瀏覽代碼

Abort early when iccid is not found on an eUICC card

The Android settings UI gets confused when we have two eUICC cards
present on one device. It will set the incorrect slot ID for one of
them.
Peter Cai 3 年之前
父節點
當前提交
6032d381d3
共有 1 個文件被更改,包括 18 次插入0 次删除
  1. 18 0
      app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt

+ 18 - 0
app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt

@@ -20,6 +20,12 @@ class OpenEuiccService : EuiccService() {
     override fun onGetEid(slotId: Int): String? =
         findChannel(slotId)?.lpa?.eid
 
+    // When two eSIM cards are present on one device, the Android settings UI
+    // gets confused and sets the incorrect slotId for profiles from one of
+    // the cards. This function helps Detect this case and abort early.
+    private fun EuiccChannel.profileExists(iccid: String?) =
+        lpa.profiles.any { it.iccid == iccid }
+
     override fun onGetOtaStatus(slotId: Int): Int {
         // Not implemented
         return 5 // EUICC_OTA_STATUS_UNAVAILABLE
@@ -84,6 +90,10 @@ class OpenEuiccService : EuiccService() {
         try {
             val channel = findChannel(slotId) ?: return RESULT_FIRST_USER
 
+            if (!channel.profileExists(iccid)) {
+                return RESULT_FIRST_USER
+            }
+
             val profile = channel.lpa.profiles.find {
                 it.iccid == iccid
             } ?: return RESULT_FIRST_USER
@@ -114,6 +124,11 @@ class OpenEuiccService : EuiccService() {
     ): Int {
         try {
             val channel = findChannel(slotId) ?: return RESULT_FIRST_USER
+
+            if (!channel.profileExists(iccid)) {
+                return RESULT_FIRST_USER
+            }
+
             if (iccid == null) {
                 // Disable active profile
                 val activeProfile = channel.lpa.profiles.find {
@@ -141,6 +156,9 @@ class OpenEuiccService : EuiccService() {
 
     override fun onUpdateSubscriptionNickname(slotId: Int, iccid: String, nickname: String?): Int {
         val channel = findChannel(slotId) ?: return RESULT_FIRST_USER
+        if (!channel.profileExists(iccid)) {
+            return RESULT_FIRST_USER
+        }
         val success = channel.lpa
             .setNickname(iccid, nickname)
         openEuiccApplication.subscriptionManager.tryRefreshCachedEuiccInfo(channel.cardId)