feat: disable refresh after switch
This commit is contained in:
parent
c8ecdee095
commit
10709bc2b5
7 changed files with 42 additions and 4 deletions
|
@ -452,24 +452,28 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
|
|||
getString(R.string.task_profile_switch_failure),
|
||||
R.drawable.ic_task_switch
|
||||
) {
|
||||
val flow = preferenceRepository.refreshAfterSwitchFlow
|
||||
euiccChannelManager.beginTrackedOperation(slotId, portId) {
|
||||
val (res, refreshed) = euiccChannelManager.withEuiccChannel(
|
||||
slotId,
|
||||
portId
|
||||
) { channel ->
|
||||
if (!channel.lpa.switchProfile(iccid, enable, refresh = true)) {
|
||||
val refresh = preferenceRepository.refreshAfterSwitchFlow.first()
|
||||
if (!channel.lpa.switchProfile(iccid, enable, refresh = refresh)) {
|
||||
// Sometimes, we *can* enable or disable the profile, but we cannot
|
||||
// send the refresh command to the modem because the profile somehow
|
||||
// makes the modem "busy". In this case, we can still switch by setting
|
||||
// refresh to false, but then the switch cannot take effect until the
|
||||
// user resets the modem manually by toggling airplane mode or rebooting.
|
||||
flow.updatePreference(false)
|
||||
Pair(channel.lpa.switchProfile(iccid, enable, refresh = false), false)
|
||||
} else {
|
||||
Pair(true, true)
|
||||
Pair(true, refresh)
|
||||
}
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
preferenceRepository.refreshAfterSwitchFlow.updatePreference(false)
|
||||
throw RuntimeException("Could not switch profile")
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ open class SettingsFragment: PreferenceFragmentCompat() {
|
|||
return true
|
||||
}
|
||||
|
||||
private fun CheckBoxPreference.bindBooleanFlow(flow: PreferenceFlowWrapper<Boolean>) {
|
||||
protected fun CheckBoxPreference.bindBooleanFlow(flow: PreferenceFlowWrapper<Boolean>) {
|
||||
lifecycleScope.launch {
|
||||
flow.collect { isChecked = it }
|
||||
}
|
||||
|
|
|
@ -5,11 +5,15 @@ import androidx.datastore.core.DataStore
|
|||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import androidx.datastore.preferences.core.intPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import androidx.fragment.app.Fragment
|
||||
import im.angry.openeuicc.OpenEuiccApplication
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "prefs")
|
||||
|
||||
|
@ -26,6 +30,7 @@ internal object PreferenceKeys {
|
|||
val NOTIFICATION_SWITCH = booleanPreferencesKey("notification_switch")
|
||||
|
||||
// ---- Advanced ----
|
||||
val REFRESH_AFTER_SWITCH = booleanPreferencesKey("refresh_after_switch")
|
||||
val DISABLE_SAFEGUARD_REMOVABLE_ESIM = booleanPreferencesKey("disable_safeguard_removable_esim")
|
||||
val VERBOSE_LOGGING = booleanPreferencesKey("verbose_logging")
|
||||
|
||||
|
@ -43,6 +48,7 @@ class PreferenceRepository(private val context: Context) {
|
|||
val notificationSwitchFlow = bindFlow(PreferenceKeys.NOTIFICATION_SWITCH, false)
|
||||
|
||||
// ---- Advanced ----
|
||||
val refreshAfterSwitchFlow = bindFlow(PreferenceKeys.REFRESH_AFTER_SWITCH, true)
|
||||
val disableSafeguardFlow = bindFlow(PreferenceKeys.DISABLE_SAFEGUARD_REMOVABLE_ESIM, false)
|
||||
val verboseLoggingFlow = bindFlow(PreferenceKeys.VERBOSE_LOGGING, false)
|
||||
|
||||
|
@ -69,4 +75,8 @@ class PreferenceFlowWrapper<T> private constructor(
|
|||
suspend fun updatePreference(value: T) {
|
||||
context.dataStore.edit { it[key] = value }
|
||||
}
|
||||
}
|
||||
|
||||
internal fun with(flow: Flow<T>) = PreferenceFlowWrapper(context, key, flow)
|
||||
}
|
||||
|
||||
fun PreferenceFlowWrapper<Boolean>.negative() = with(map { !it })
|
||||
|
|
|
@ -157,6 +157,8 @@
|
|||
<string name="pref_notifications_switch">Switching</string>
|
||||
<string name="pref_notifications_switch_desc">Send notifications for <i>switching</i> profiles\nNote that this type of notification is unreliable.</string>
|
||||
<string name="pref_advanced">Advanced</string>
|
||||
<string name="pref_advanced_disable_refresh_after_switch">Disable refresh status after switching</string>
|
||||
<string name="pref_advanced_disable_refresh_after_switch_desc">Avoid OMAPI crash after switch</string>
|
||||
<string name="pref_advanced_disable_safeguard_removable_esim">Allow Disabling / Deleting Active Profile</string>
|
||||
<string name="pref_advanced_disable_safeguard_removable_esim_desc">By default, this app prevents you from disabling the active profile on a removable eSIM inserted in the device, because doing so may <i>sometimes</i> render it inaccessible.\nCheck this box to <i>remove</i> this safeguard.</string>
|
||||
<string name="pref_advanced_verbose_logging">Verbose Logging</string>
|
||||
|
|
|
@ -23,17 +23,20 @@
|
|||
</im.angry.openeuicc.ui.preference.LongSummaryPreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
app:key="pref_advanced"
|
||||
app:title="@string/pref_advanced"
|
||||
app:iconSpaceReserved="false">
|
||||
<CheckBoxPreference
|
||||
app:key="pref_advanced_disable_safeguard_removable_esim"
|
||||
app:iconSpaceReserved="false"
|
||||
app:title="@string/pref_advanced_disable_safeguard_removable_esim"
|
||||
app:order="10"
|
||||
app:summary="@string/pref_advanced_disable_safeguard_removable_esim_desc" />
|
||||
|
||||
<CheckBoxPreference
|
||||
app:key="pref_advanced_verbose_logging"
|
||||
app:iconSpaceReserved="false"
|
||||
app:order="11"
|
||||
app:title="@string/pref_advanced_verbose_logging"
|
||||
app:summary="@string/pref_advanced_verbose_logging_desc" />
|
||||
|
||||
|
@ -41,12 +44,14 @@
|
|||
app:iconSpaceReserved="false"
|
||||
app:isPreferenceVisible="false"
|
||||
app:key="pref_advanced_language"
|
||||
app:order="12"
|
||||
app:summary="@string/pref_advanced_language_desc"
|
||||
app:title="@string/pref_advanced_language" />
|
||||
|
||||
<Preference
|
||||
app:key="pref_advanced_logs"
|
||||
app:iconSpaceReserved="false"
|
||||
app:order="13"
|
||||
app:title="@string/pref_advanced_logs"
|
||||
app:summary="@string/pref_advanced_logs_desc" />
|
||||
|
||||
|
|
|
@ -6,9 +6,12 @@ import android.content.pm.PackageManager
|
|||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.preference.CheckBoxPreference
|
||||
import androidx.preference.Preference
|
||||
import im.angry.easyeuicc.R
|
||||
import im.angry.openeuicc.util.encodeHex
|
||||
import im.angry.openeuicc.util.negative
|
||||
import im.angry.openeuicc.util.preferenceRepository
|
||||
import java.security.MessageDigest
|
||||
|
||||
class UnprivilegedSettingsFragment : SettingsFragment() {
|
||||
|
@ -29,8 +32,12 @@ class UnprivilegedSettingsFragment : SettingsFragment() {
|
|||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
super.onCreatePreferences(savedInstanceState, rootKey)
|
||||
addPreferencesFromResource(R.xml.pref_unprivileged_settings)
|
||||
mergePreferenceOverlay("pref_advanced_overlay", "pref_advanced")
|
||||
mergePreferenceOverlay("pref_info_overlay", "pref_info")
|
||||
|
||||
requirePreference<CheckBoxPreference>("pref_advanced_disable_refreshed_after_switch")
|
||||
.bindBooleanFlow(preferenceRepository.refreshAfterSwitchFlow.negative())
|
||||
|
||||
requirePreference<Preference>("pref_info_ara_m").apply {
|
||||
summary = firstSigner.encodeHex()
|
||||
setOnPreferenceClickListener {
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<PreferenceCategory
|
||||
app:isPreferenceVisible="false"
|
||||
app:key="pref_advanced_overlay">
|
||||
<CheckBoxPreference
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="pref_advanced_disable_refreshed_after_switch"
|
||||
app:order="1"
|
||||
app:summary="@string/pref_advanced_disable_refresh_after_switch_desc"
|
||||
app:title="@string/pref_advanced_disable_refresh_after_switch" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
app:isPreferenceVisible="false"
|
||||
app:key="pref_info_overlay">
|
||||
|
|
Loading…
Add table
Reference in a new issue