Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc6b3a48 authored by septs's avatar septs Committed by Peter Cai
Browse files

feat: support disabling refresh after switch in settings

peter: Reworked strings and i18 translations. Also removed the ad-hoc
function in favor of a lambda.
parent e08f8beb
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import androidx.core.app.NotificationManagerCompat
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.lifecycleScope
import im.angry.openeuicc.common.R
import im.angry.openeuicc.core.EuiccChannel
import im.angry.openeuicc.core.EuiccChannelManager
import im.angry.openeuicc.util.*
import kotlinx.coroutines.Dispatchers
@@ -456,30 +457,34 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
        iccid: String,
        enable: Boolean, // Enable or disable the profile indicated in iccid
        reconnectTimeoutMillis: Long = 0 // 0 = do not wait for reconnect
    ): ForegroundTaskSubscriberFlow =
    ) =
        launchForegroundTask(
            getString(R.string.task_profile_switch),
            getString(R.string.task_profile_switch_failure),
            R.drawable.ic_task_switch
        ) {
            euiccChannelManager.beginTrackedOperation(slotId, portId) {
                val (res, refreshed) = euiccChannelManager.withEuiccChannel(
                    slotId,
                    portId
                ) { channel ->
                    if (!channel.lpa.switchProfile(iccid, enable, refresh = true)) {
                val (response, refreshed) =
                    euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
                        val refresh = preferenceRepository.refreshAfterSwitchFlow.first()
                        val response = channel.lpa.switchProfile(iccid, enable, refresh)
                        if (response || !refresh) {
                            Pair(response, refresh)
                        } else {
                            // refresh failed, but refresh was requested
                            // 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.
                        Pair(channel.lpa.switchProfile(iccid, enable, refresh = false), false)
                    } else {
                        Pair(true, true)
                            Pair(
                                channel.lpa.switchProfile(iccid, enable, refresh = false),
                                false
                            )
                        }
                    }

                if (!res) {
                if (!response) {
                    throw RuntimeException("Could not switch profile")
                }

+3 −0
Original line number Diff line number Diff line
@@ -78,6 +78,9 @@ open class SettingsFragment: PreferenceFragmentCompat() {
        requirePreference<CheckBoxPreference>("pref_developer_ignore_tls_certificate")
            .bindBooleanFlow(preferenceRepository.ignoreTLSCertificateFlow)

        requirePreference<CheckBoxPreference>("pref_developer_refresh_after_switch")
            .bindBooleanFlow(preferenceRepository.refreshAfterSwitchFlow)

        requirePreference<CheckBoxPreference>("pref_developer_euicc_memory_reset")
            .bindBooleanFlow(preferenceRepository.euiccMemoryResetFlow)
    }
+6 −7
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ internal object PreferenceKeys {

    // ---- Developer Options ----
    val DEVELOPER_OPTIONS_ENABLED = booleanPreferencesKey("developer_options_enabled")
    val REFRESH_AFTER_SWITCH = booleanPreferencesKey("refresh_after_switch")
    val UNFILTERED_PROFILE_LIST = booleanPreferencesKey("unfiltered_profile_list")
    val IGNORE_TLS_CERTIFICATE = booleanPreferencesKey("ignore_tls_certificate")
    val EUICC_MEMORY_RESET = booleanPreferencesKey("euicc_memory_reset")
@@ -48,6 +49,7 @@ open class PreferenceRepository(private val context: Context) {
    val verboseLoggingFlow = bindFlow(PreferenceKeys.VERBOSE_LOGGING, false)

    // ---- Developer Options ----
    val refreshAfterSwitchFlow = bindFlow(PreferenceKeys.REFRESH_AFTER_SWITCH, true)
    val developerOptionsEnabledFlow = bindFlow(PreferenceKeys.DEVELOPER_OPTIONS_ENABLED, false)
    val unfilteredProfileListFlow = bindFlow(PreferenceKeys.UNFILTERED_PROFILE_LIST, false)
    val ignoreTLSCertificateFlow = bindFlow(PreferenceKeys.IGNORE_TLS_CERTIFICATE, false)
@@ -60,13 +62,10 @@ open class PreferenceRepository(private val context: Context) {
class PreferenceFlowWrapper<T> private constructor(
    private val context: Context,
    private val key: Preferences.Key<T>,
    inner: Flow<T>
    inner: Flow<T>,
) : Flow<T> by inner {
    internal constructor(context: Context, key: Preferences.Key<T>, defaultValue: T) : this(
        context,
        key,
        context.dataStore.data.map { it[key] ?: defaultValue }
    )
    internal constructor(context: Context, key: Preferences.Key<T>, defaultValue: T) :
            this(context, key, context.dataStore.data.map { it[key] ?: defaultValue })

    suspend fun updatePreference(value: T) {
        context.dataStore.edit { it[key] = value }
+2 −0
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@
    <string name="pref_advanced_logs">ログ</string>
    <string name="pref_advanced_logs_desc">アプリの最新デバッグログを表示します</string>
    <string name="pref_developer">開発者オプション</string>
    <string name="pref_developer_refresh_after_switch_desc">プロファイルを切り替えた後にモデムに更新コマンドを送信するかどうか。クラッシュが発生する場合は、これを無効にしてみてください。</string>
    <string name="pref_developer_unfiltered_profile_list">フィルタリングされていないプロファイル一覧を表示</string>
    <string name="pref_developer_unfiltered_profile_list_desc">非運用のプロファイルも含めます</string>
    <string name="pref_developer_ignore_tls_certificate">SM-DP+ TLS 証明書を無視する</string>
@@ -162,4 +163,5 @@
    <string name="euicc_memory_reset_invoke_button">消去する</string>
    <string name="pref_developer_euicc_memory_reset">eUICC の消去を可能にする</string>
    <string name="pref_developer_euicc_memory_reset_desc">この操作は、デフォルトでは非表示になっている危険な操作です。代わりに、すべての構成ファイルを手動で削除することもできます。</string>
    <string name="pref_developer_refresh_after_switch">モデムに更新コマンドを送信</string>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@
    <string name="pref_advanced_language">语言</string>
    <string name="pref_advanced_language_desc">选择 App 语言</string>
    <string name="pref_developer">开发者选项</string>
    <string name="pref_developer_refresh_after_switch_desc">切换配置文件后是否向基带发送刷新命令。如果发现崩溃,请尝试禁用此功能。</string>
    <string name="pref_developer_unfiltered_profile_list">显示未经过滤的配置文件列表</string>
    <string name="pref_developer_unfiltered_profile_list_desc">在配置文件列表中包括非生产环境的配置文件</string>
    <string name="pref_developer_ignore_tls_certificate">无视 SM-DP+ 的 TLS 证书</string>
@@ -162,4 +163,5 @@
    <string name="euicc_memory_reset_invoke_button">擦除</string>
    <string name="pref_developer_euicc_memory_reset">允许擦除 eUICC</string>
    <string name="pref_developer_euicc_memory_reset_desc">此操作是默认隐藏的危险操作。作为替代方案,您可以手动删除所有配置文件。</string>
    <string name="pref_developer_refresh_after_switch">向基带发送刷新命令</string>
</resources>
 No newline at end of file
Loading