瀏覽代碼

[4/n] Only try to open ports with a mapped slot index

Peter Cai 2 年之前
父節點
當前提交
53be772591

+ 1 - 1
app-common/src/main/java/im/angry/openeuicc/core/EuiccChannel.kt

@@ -10,7 +10,7 @@ abstract class EuiccChannel(
     val logicalSlotId = port.logicalSlotIndex
     val portId = port.portIndex
     val cardId = port.card.cardId
-    val name = "SLOT ${port.card.physicalSlotIndex}:${port.portIndex}"
+    val name = "SLOT $logicalSlotId"
     val removable = port.card.isRemovable
 
     abstract val lpa: LocalProfileAssistant

+ 7 - 1
app-common/src/main/java/im/angry/openeuicc/core/EuiccChannelManager.kt

@@ -4,6 +4,7 @@ import android.content.Context
 import android.os.Handler
 import android.os.HandlerThread
 import android.se.omapi.SEService
+import android.telephony.SubscriptionManager
 import android.util.Log
 import im.angry.openeuicc.OpenEuiccApplication
 import im.angry.openeuicc.util.*
@@ -77,7 +78,7 @@ open class EuiccChannelManager(protected val context: Context) {
             ensureSEService()
             val existing = channels.find { it.slotId == port.card.physicalSlotIndex && it.portId == port.portIndex }
             if (existing != null) {
-                if (existing.valid) {
+                if (existing.valid && port.logicalSlotIndex == existing.logicalSlotId) {
                     return existing
                 } else {
                     existing.close()
@@ -85,6 +86,11 @@ open class EuiccChannelManager(protected val context: Context) {
                 }
             }
 
+            if (port.logicalSlotIndex == SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
+                // We can only open channels on ports that are actually enabled
+                return null
+            }
+
             var euiccChannel: EuiccChannel? = tryOpenEuiccChannelPrivileged(port)
 
             if (euiccChannel == null) {