Compare commits

...

2 commits

Author SHA1 Message Date
0e86a922d1 fix: do not refresh eUICC when switching port mapping
All checks were successful
/ build-debug (push) Successful in 4m25s
This is entirely unnecessary and only causes problems
2024-06-16 17:45:30 -04:00
2b3f042e39 Move some functions to LPAUtils 2024-06-16 17:42:21 -04:00
3 changed files with 19 additions and 13 deletions

View file

@ -1,18 +1,32 @@
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<LocalProfileInfo>.operational: List<LocalProfileInfo>
get() = filter {
it.profileClass == LocalProfileInfo.Clazz.Operational
}
fun LocalProfileAssistant.disableActiveProfileWithUndo(): () -> Unit =
profiles.find { it.state == LocalProfileInfo.State.Enabled }?.let {
disableProfile(it.iccid)
val List<EuiccChannel>.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)
return { enableProfile(it.iccid) }
} ?: { }

View file

@ -11,14 +11,12 @@ 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
@ -60,12 +58,6 @@ interface OpenEuiccContextMarker {
get() = appContainer.telephonyManager
}
val LocalProfileInfo.isEnabled: Boolean
get() = state == LocalProfileInfo.State.Enabled
val List<EuiccChannel>.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

View file

@ -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()
it.lpa.disableActiveProfileWithUndo(false)
}
}
@ -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()
return@mapNotNull channel.lpa.disableActiveProfileWithUndo(false)
} else {
// Do not do anything for external eUICCs -- we can't really trust them to work properly
// with no profile enabled.