瀏覽代碼

lpac-jni: Fixup channel validity detection

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

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

@@ -12,15 +12,7 @@ abstract class EuiccChannel(
 
     abstract val lpa: LocalProfileAssistant
     val valid: Boolean
-        get() {
-            try {
-                // Try to ping the eUICC card by reading the EID
-                lpa.eID
-            } catch (e: Exception) {
-                return false
-            }
-            return true
-        }
+        get() = lpa.valid
 
     fun close() = lpa.close()
 }

+ 10 - 0
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LocalProfileAssistant.kt

@@ -9,6 +9,16 @@ interface LocalProfileAssistant {
         private const val TAG = "LocalProfileAssistant"
     }
 
+    val valid: Boolean
+        get() = try {
+            // If we can read both eID and profiles properly, we are likely looking at
+            // a valid LocalProfileAssistant
+            eID
+            profiles
+            true
+        } catch (e: Exception) {
+            false
+        }
     val profiles: List<LocalProfileInfo>
     val notifications: List<LocalProfileNotification>
     val eID: String

+ 2 - 2
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/LocalProfileAssistantImpl.kt

@@ -49,8 +49,8 @@ class LocalProfileAssistantImpl(
                     apduInterface.connect()
                     contextHandle = LpacJni.createContext(apduInterface, httpInterface)
                     check(LpacJni.es10xInit(contextHandle) >= 0) { "Reconnect attempt failed" }
-                    // Validate that we can actually use the APDU channel by trying to read eID
-                    eID
+                    // Validate that we can actually use the APDU channel by trying to read eID and profiles
+                    check(valid) { "Reconnected channel is invalid" }
                     break
                 } catch (e: Exception) {
                     e.printStackTrace()