ソースを参照

ui: Prevent crash after a profile switch that timed out

...and improve the prompt when this happens.
Peter Cai 1 年間 前
コミット
a29b068035

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

@@ -47,6 +47,10 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
 
     private val adapter = EuiccProfileAdapter()
 
+    // Marker for when this fragment might enter an invalid state
+    // e.g. after a failed enable / disable operation
+    private var invalid = false
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setHasOptionsMenu(true)
@@ -106,6 +110,7 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
 
     @SuppressLint("NotifyDataSetChanged")
     private fun refresh() {
+        if (invalid) return
         swipeRefresh.isRefreshing = true
 
         lifecycleScope.launch {
@@ -151,6 +156,8 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
                     euiccChannelManager.waitForReconnect(slotId, portId, timeoutMillis = 30 * 1000)
                 } catch (e: TimeoutCancellationException) {
                     withContext(Dispatchers.Main) {
+                        // Prevent this Fragment from being used again
+                        invalid = true
                         // 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)

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

@@ -16,7 +16,7 @@
     <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="enable_disable_timeout">Timed out waiting for the eSIM chip to switch profiles. This may be a bug in your phone\'s modem firmware. Try toggling airplane mode, restarting the application, or rebooting 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>