diff --git a/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt b/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt index 96c0949..cff6e89 100644 --- a/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt +++ b/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) @@ -247,6 +254,9 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener, } private fun showOptionsMenu() { + // Prevent users from doing multiple things at once + if (invalid || swipeRefresh.isRefreshing) return + PopupMenu(root.context, profileMenu).apply { setOnMenuItemClickListener(::onMenuItemClicked) populatePopupWithProfileActions(this, profile) diff --git a/app-common/src/main/res/values/strings.xml b/app-common/src/main/res/values/strings.xml index a2424e5..2920bfa 100644 --- a/app-common/src/main/res/values/strings.xml +++ b/app-common/src/main/res/values/strings.xml @@ -16,7 +16,7 @@ Delete Rename - Timed out waiting for the eSIM chip to switch profiles. You might want to restart the application or even the phone. + 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. Cannot switch to new eSIM profile. Nickname cannot be longer than 64 characters