ソースを参照

EuiccManagementFragment: Show alert dialog if timed out waiting for SIM

Peter Cai 1 年間 前
コミット
92d8f9079f

+ 15 - 0
app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt

@@ -16,6 +16,7 @@ import android.widget.ImageButton
 import android.widget.PopupMenu
 import android.widget.TextView
 import android.widget.Toast
+import androidx.appcompat.app.AlertDialog
 import androidx.fragment.app.Fragment
 import androidx.lifecycle.lifecycleScope
 import androidx.recyclerview.widget.LinearLayoutManager
@@ -26,6 +27,7 @@ import net.typeblog.lpac_jni.LocalProfileInfo
 import im.angry.openeuicc.common.R
 import im.angry.openeuicc.util.*
 import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.TimeoutCancellationException
 import kotlinx.coroutines.flow.first
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
@@ -138,6 +140,19 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
                 }
                 refresh()
                 fab.isEnabled = true
+            } catch (e: TimeoutCancellationException) {
+                // Timed out waiting for SIM to come back online, we can no longer assume that the LPA is still valid
+                AlertDialog.Builder(requireContext()).apply {
+                    setMessage(R.string.enable_disable_timeout)
+                    setPositiveButton(android.R.string.ok) { dialog, _ ->
+                        dialog.dismiss()
+                        requireActivity().finish()
+                    }
+                    setOnDismissListener { _ ->
+                        requireActivity().finish()
+                    }
+                    show()
+                }
             } catch (e: Exception) {
                 Log.d(TAG, "Failed to enable / disable profile $iccid")
                 Log.d(TAG, Log.getStackTraceString(e))

+ 2 - 0
app-common/src/main/res/values/strings.xml

@@ -16,6 +16,8 @@
     <string name="delete">Delete</string>
     <string name="rename">Rename</string>
 
+    <string name="enable_disable_timeout">Timed out waiting for the eSIM chip to switch profiles. You might want to restart the application or even the phone.</string>
+
     <string name="toast_profile_enable_failed">Cannot switch to new eSIM profile.</string>
     <string name="toast_profile_name_too_long">Nickname cannot be longer than 64 characters</string>
 

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

@@ -90,11 +90,7 @@ class LocalProfileAssistantImpl(
     override fun enableProfile(iccid: String, reconnectTimeout: Long): Boolean {
         val res = LpacJni.es10cEnableProfile(contextHandle, iccid) == 0
         if (reconnectTimeout > 0) {
-            try {
-                tryReconnect(reconnectTimeout)
-            } catch (e: Exception) {
-                return false
-            }
+            tryReconnect(reconnectTimeout)
         }
         return res
     }
@@ -102,11 +98,7 @@ class LocalProfileAssistantImpl(
     override fun disableProfile(iccid: String, reconnectTimeout: Long): Boolean {
         val res = LpacJni.es10cDisableProfile(contextHandle, iccid) == 0
         if (reconnectTimeout > 0) {
-            try {
-                tryReconnect(reconnectTimeout)
-            } catch (e: Exception) {
-                return false
-            }
+            tryReconnect(reconnectTimeout)
         }
         return res
     }