Browse Source

fix: do not refresh eUICC when switching port mapping

This is entirely unnecessary and only causes problems
Peter Cai 1 year ago
parent
commit
0e86a922d1

+ 9 - 3
app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt

@@ -19,8 +19,14 @@ val List<LocalProfileInfo>.operational: List<LocalProfileInfo>
 val List<EuiccChannel>.hasMultipleChips: Boolean
 val List<EuiccChannel>.hasMultipleChips: Boolean
     get() = distinctBy { it.slotId }.size > 1
     get() = distinctBy { it.slotId }.size > 1
 
 
-fun LocalProfileAssistant.disableActiveProfileWithUndo(): () -> Unit =
-    profiles.find { it.state == LocalProfileInfo.State.Enabled }?.let {
-        disableProfile(it.iccid)
+/**
+ * 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) }
         return { enableProfile(it.iccid) }
     } ?: { }
     } ?: { }

+ 2 - 2
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)
     // Disable all eSIM profiles before performing a DSDS switch (only for internal eSIMs)
     knownChannels.forEach {
     knownChannels.forEach {
         if (!it.removable) {
         if (!it.removable) {
-            it.lpa.disableActiveProfileWithUndo()
+            it.lpa.disableActiveProfileWithUndo(false)
         }
         }
     }
     }
 
 
@@ -45,7 +45,7 @@ fun TelephonyManager.updateSimSlotMapping(
     val undo = unmapped.mapNotNull { mapping ->
     val undo = unmapped.mapNotNull { mapping ->
         euiccManager.findEuiccChannelByPortBlocking(mapping.physicalSlotIndex, mapping.portIndex)?.let { channel ->
         euiccManager.findEuiccChannelByPortBlocking(mapping.physicalSlotIndex, mapping.portIndex)?.let { channel ->
             if (!channel.removable) {
             if (!channel.removable) {
-                return@mapNotNull channel.lpa.disableActiveProfileWithUndo()
+                return@mapNotNull channel.lpa.disableActiveProfileWithUndo(false)
             } else {
             } else {
                 // Do not do anything for external eUICCs -- we can't really trust them to work properly
                 // Do not do anything for external eUICCs -- we can't really trust them to work properly
                 // with no profile enabled.
                 // with no profile enabled.