瀏覽代碼

Implement subscription removal for OpenEuiccService

Peter Cai 3 年之前
父節點
當前提交
54f02ff638
共有 1 個文件被更改,包括 24 次插入4 次删除
  1. 24 4
      app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt

+ 24 - 4
app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt

@@ -82,8 +82,28 @@ class OpenEuiccService : EuiccService() {
         return EuiccInfo("Unknown") // TODO: Can we actually implement this?
     }
 
-    override fun onDeleteSubscription(slotId: Int, iccid: String?): Int {
-        TODO("Not yet implemented")
+    override fun onDeleteSubscription(slotId: Int, iccid: String): Int {
+        try {
+            val channel = findChannel(slotId) ?: return RESULT_FIRST_USER
+            val iccidBig = TextUtil.iccidLittleToBig(iccid)
+
+            val profile = channel.lpa.profiles.find {
+                it.iccid == iccidBig
+            } ?: return RESULT_FIRST_USER
+
+            if (profile.state == LocalProfileInfo.State.Enabled) {
+                // Must disable the profile first
+                return RESULT_FIRST_USER
+            }
+
+            return if (channel.lpa.deleteProfile(iccidBig, Progress()) == "0") {
+                RESULT_OK
+            } else {
+                RESULT_FIRST_USER
+            }
+        } catch (e: Exception) {
+            return RESULT_FIRST_USER
+        }
     }
 
     @Deprecated("Deprecated in Java")
@@ -96,9 +116,9 @@ class OpenEuiccService : EuiccService() {
             val channel = findChannel(slotId) ?: return RESULT_FIRST_USER
             if (iccid == null) {
                 // Disable active profile
-                val activeProfile = channel.lpa.profiles.filter {
+                val activeProfile = channel.lpa.profiles.find {
                     it.state == LocalProfileInfo.State.Enabled
-                }[0] ?: return RESULT_OK
+                } ?: return RESULT_OK
 
                 return if (channel.lpa.disableProfile(activeProfile.iccid, Progress()) == "0") {
                     RESULT_OK