EuiccManagementFragment: Show alert dialog if timed out waiting for SIM
All checks were successful
/ build-debug (push) Successful in 4m17s

This commit is contained in:
Peter Cai 2024-03-21 21:16:14 -04:00
parent d9d0cf2e75
commit 92d8f9079f
3 changed files with 19 additions and 10 deletions

View file

@ -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))

View file

@ -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>

View file

@ -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
}