diff --git a/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt b/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt index f799f03..e5c2f52 100644 --- a/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt +++ b/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt @@ -1,32 +1,18 @@ package im.angry.openeuicc.util -import im.angry.openeuicc.core.EuiccChannel import net.typeblog.lpac_jni.LocalProfileAssistant import net.typeblog.lpac_jni.LocalProfileInfo val LocalProfileInfo.displayName: String get() = nickName.ifEmpty { name } - -val LocalProfileInfo.isEnabled: Boolean - get() = state == LocalProfileInfo.State.Enabled - val List.operational: List get() = filter { it.profileClass == LocalProfileInfo.Clazz.Operational } -val List.hasMultipleChips: Boolean - get() = distinctBy { it.slotId }.size > 1 - -/** - * Disable the active profile, return a lambda that reverts this action when called. - * If refreshOnDisable is true, also cause a eUICC refresh command. Note that refreshing - * will disconnect the eUICC and might need some time before being operational again. - * See EuiccManager.waitForReconnect() - */ -fun LocalProfileAssistant.disableActiveProfileWithUndo(refreshOnDisable: Boolean): () -> Unit = - profiles.find { it.isEnabled }?.let { - disableProfile(it.iccid, refreshOnDisable) +fun LocalProfileAssistant.disableActiveProfileWithUndo(): () -> Unit = + profiles.find { it.state == LocalProfileInfo.State.Enabled }?.let { + disableProfile(it.iccid) return { enableProfile(it.iccid) } } ?: { } \ No newline at end of file diff --git a/app-common/src/main/java/im/angry/openeuicc/util/Utils.kt b/app-common/src/main/java/im/angry/openeuicc/util/Utils.kt index 444c176..a93e7d2 100644 --- a/app-common/src/main/java/im/angry/openeuicc/util/Utils.kt +++ b/app-common/src/main/java/im/angry/openeuicc/util/Utils.kt @@ -11,12 +11,14 @@ import com.google.zxing.RGBLuminanceSource import com.google.zxing.common.HybridBinarizer import com.google.zxing.qrcode.QRCodeReader import im.angry.openeuicc.OpenEuiccApplication +import im.angry.openeuicc.core.EuiccChannel import im.angry.openeuicc.di.AppContainer import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withContext +import net.typeblog.lpac_jni.LocalProfileInfo import kotlin.RuntimeException import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException @@ -58,6 +60,12 @@ interface OpenEuiccContextMarker { get() = appContainer.telephonyManager } +val LocalProfileInfo.isEnabled: Boolean + get() = state == LocalProfileInfo.State.Enabled + +val List.hasMultipleChips: Boolean + get() = distinctBy { it.slotId }.size > 1 + // Create an instance of OMAPI SEService in a manner that "makes sense" without unpredictable callbacks suspend fun connectSEService(context: Context): SEService = suspendCoroutine { cont -> // Use a Mutex to make sure the continuation is run *after* the "service" variable is assigned diff --git a/app/src/main/java/im/angry/openeuicc/util/PrivilegedTelephonyUtils.kt b/app/src/main/java/im/angry/openeuicc/util/PrivilegedTelephonyUtils.kt index 3c30bce..6a13c50 100644 --- a/app/src/main/java/im/angry/openeuicc/util/PrivilegedTelephonyUtils.kt +++ b/app/src/main/java/im/angry/openeuicc/util/PrivilegedTelephonyUtils.kt @@ -22,7 +22,7 @@ fun TelephonyManager.setDsdsEnabled(euiccManager: EuiccChannelManager, enabled: // Disable all eSIM profiles before performing a DSDS switch (only for internal eSIMs) knownChannels.forEach { if (!it.removable) { - it.lpa.disableActiveProfileWithUndo(false) + it.lpa.disableActiveProfileWithUndo() } } @@ -45,7 +45,7 @@ fun TelephonyManager.updateSimSlotMapping( val undo = unmapped.mapNotNull { mapping -> euiccManager.findEuiccChannelByPortBlocking(mapping.physicalSlotIndex, mapping.portIndex)?.let { channel -> if (!channel.removable) { - return@mapNotNull channel.lpa.disableActiveProfileWithUndo(false) + return@mapNotNull channel.lpa.disableActiveProfileWithUndo() } else { // Do not do anything for external eUICCs -- we can't really trust them to work properly // with no profile enabled.