瀏覽代碼

lpac-jni: Avoid reloading profiles from card every time

Some cards may run at a low baud rate which causes issues
Peter Cai 1 年之前
父節點
當前提交
2d312f2216
共有 1 個文件被更改,包括 22 次插入10 次删除
  1. 22 10
      libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/LocalProfileAssistantImpl.kt

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

@@ -20,6 +20,7 @@ class LocalProfileAssistantImpl(
 
     private var finalized = false
     private var contextHandle: Long = LpacJni.createContext(apduInterface, httpInterface)
+
     init {
         if (LpacJni.euiccInit(contextHandle) < 0) {
             throw IllegalArgumentException("Failed to initialize LPA")
@@ -40,8 +41,11 @@ class LocalProfileAssistantImpl(
             false
         }
 
+    private var _profiles: List<LocalProfileInfo>? = null
     override val profiles: List<LocalProfileInfo>
-        get() = LpacJni.es10cGetProfilesInfo(contextHandle)!!.asList()
+        get() = (_profiles ?: LpacJni.es10cGetProfilesInfo(contextHandle)!!.asList()).also {
+            _profiles = it
+        }
 
     override val notifications: List<LocalProfileNotification>
         get() =
@@ -55,19 +59,26 @@ class LocalProfileAssistantImpl(
         get() = LpacJni.es10cexGetEuiccInfo2(contextHandle)
 
     override fun enableProfile(iccid: String): Boolean =
-        LpacJni.es10cEnableProfile(contextHandle, iccid) == 0
+        (LpacJni.es10cEnableProfile(contextHandle, iccid) == 0).also {
+            _profiles = null
+        }
 
     override fun disableProfile(iccid: String): Boolean =
-        LpacJni.es10cDisableProfile(contextHandle, iccid) == 0
+        (LpacJni.es10cDisableProfile(contextHandle, iccid) == 0).also {
+            _profiles = null
+        }
 
-    override fun deleteProfile(iccid: String): Boolean {
-        return LpacJni.es10cDeleteProfile(contextHandle, iccid) == 0
-    }
+    override fun deleteProfile(iccid: String): Boolean =
+        (LpacJni.es10cDeleteProfile(contextHandle, iccid) == 0).also {
+            _profiles = null
+        }
 
     @Synchronized
     override fun downloadProfile(smdp: String, matchingId: String?, imei: String?,
                                  confirmationCode: String?, callback: ProfileDownloadCallback): Boolean {
-        return LpacJni.downloadProfile(contextHandle, smdp, matchingId, imei, confirmationCode, callback) == 0
+        return (LpacJni.downloadProfile(contextHandle, smdp, matchingId, imei, confirmationCode, callback) == 0).also {
+            _profiles = null
+        }
     }
 
     override fun deleteNotification(seqNumber: Long): Boolean =
@@ -79,9 +90,10 @@ class LocalProfileAssistantImpl(
             Log.d(TAG, "handleNotification $seqNumber = $it")
         } == 0
 
-    override fun setNickname(iccid: String, nickname: String): Boolean {
-        return LpacJni.es10cSetNickname(contextHandle, iccid, nickname) == 0
-    }
+    override fun setNickname(iccid: String, nickname: String): Boolean =
+        (LpacJni.es10cSetNickname(contextHandle, iccid, nickname) == 0).also {
+            _profiles = null
+        }
 
     @Synchronized
     override fun close() {