Merge branch 'master' into refresh-after-switch

This commit is contained in:
septs 2025-03-10 09:29:16 +08:00
commit 137caab8ae
Signed by: septs
SSH key fingerprint: SHA256:ElK0p6DNkbsqYUdJ3I9QHDVf21SQD0c2r+hd7s/r5Co
8 changed files with 25 additions and 14 deletions

View file

@ -26,12 +26,12 @@ 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")
// ---- 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")

View file

@ -172,8 +172,6 @@
<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_refresh_after_switch">Refresh status after switching</string>
<string name="pref_advanced_refresh_after_switch_desc">If crash after switch, Please trying disable the function</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>
@ -183,6 +181,8 @@
<string name="pref_advanced_logs">Logs</string>
<string name="pref_advanced_logs_desc">View recent debug logs of the application</string>
<string name="pref_developer">Developer Options</string>
<string name="pref_developer_refresh_after_switch">Refresh status after switching</string>
<string name="pref_developer_refresh_after_switch_desc">If crash after switch, Please trying disable the function</string>
<string name="pref_developer_unfiltered_profile_list">Show unfiltered profile list</string>
<string name="pref_developer_unfiltered_profile_list_desc">Include non-production profiles in the list</string>
<string name="pref_developer_ignore_tls_certificate">Ignore SM-DP+ TLS certificate</string>

View file

@ -60,8 +60,8 @@
<CheckBoxPreference
app:iconSpaceReserved="false"
app:key="pref_developer_refresh_after_switch"
app:summary="@string/pref_advanced_refresh_after_switch_desc"
app:title="@string/pref_advanced_refresh_after_switch" />
app:summary="@string/pref_developer_refresh_after_switch_desc"
app:title="@string/pref_developer_refresh_after_switch" />
<CheckBoxPreference
app:iconSpaceReserved="false"
@ -77,7 +77,6 @@
<CheckBoxPreference
app:iconSpaceReserved="false"
app:isPreferenceVisible="false"
app:key="pref_developer_euicc_memory_reset"
app:summary="@string/pref_developer_euicc_memory_reset_desc"
app:title="@string/pref_developer_euicc_memory_reset" />

View file

@ -6,11 +6,9 @@ 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.preferenceRepository
import java.security.MessageDigest
class UnprivilegedSettingsFragment : SettingsFragment() {

View file

@ -8,7 +8,8 @@ import im.angry.openeuicc.util.*
import kotlinx.coroutines.flow.first
import java.lang.IllegalArgumentException
class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFactory(context) {
class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFactory(context),
PrivilegedEuiccContextMarker {
private val tm by lazy {
(context.applicationContext as OpenEuiccApplication).appContainer.telephonyManager
}
@ -22,7 +23,7 @@ class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFacto
super.tryOpenEuiccChannel(port)?.let { return it }
}
if (port.card.isEuicc || (context.preferenceRepository as PrivilegedPreferenceRepository).removableTelephonyManagerFlow.first()) {
if (port.card.isEuicc || preferenceRepository.removableTelephonyManagerFlow.first()) {
Log.i(
DefaultEuiccChannelManager.TAG,
"Trying TelephonyManager for slot ${port.card.physicalSlotIndex} port ${port.portIndex}"

View file

@ -6,7 +6,7 @@ import androidx.preference.Preference
import im.angry.openeuicc.R
import im.angry.openeuicc.util.*
class PrivilegedSettingsFragment : SettingsFragment() {
class PrivilegedSettingsFragment : SettingsFragment(), PrivilegedEuiccContextMarker {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
super.onCreatePreferences(savedInstanceState, rootKey)
addPreferencesFromResource(R.xml.pref_privileged_settings)
@ -21,7 +21,7 @@ class PrivilegedSettingsFragment : SettingsFragment() {
requirePreference<Preference>("pref_advanced_language").isVisible = false
// Force use TelephonyManager API
requirePreference<CheckBoxPreference>("pref_developer_tmapi_removable")
.bindBooleanFlow((preferenceRepository as PrivilegedPreferenceRepository).removableTelephonyManagerFlow)
requirePreference<CheckBoxPreference>("pref_developer_removable_telephony_manager")
.bindBooleanFlow(preferenceRepository.removableTelephonyManagerFlow)
}
}

View file

@ -5,10 +5,23 @@ import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
import androidx.fragment.app.Fragment
import java.util.concurrent.Executors
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
interface PrivilegedEuiccContextMarker {
val privilegedEuiccMarkerContext: Context
get() = when (this) {
is Context -> this
is Fragment -> requireContext()
else -> throw RuntimeException("PrivilegedEuiccContextMarker shall only be used on Fragments or UI types that derive from Context")
}
val preferenceRepository: PrivilegedPreferenceRepository
get() = privilegedEuiccMarkerContext.preferenceRepository as PrivilegedPreferenceRepository
}
suspend fun Context.bindServiceSuspended(intent: Intent, flags: Int): Pair<IBinder?, () -> Unit> =
suspendCoroutine { cont ->
var binder: IBinder?

View file

@ -5,7 +5,7 @@
app:key="pref_developer_overlay">
<CheckBoxPreference
app:iconSpaceReserved="false"
app:key="pref_developer_tmapi_removable"
app:key="pref_developer_removable_telephony_manager"
app:summary="@string/pref_developer_telephony_manager_removable_desc"
app:title="@string/pref_developer_telephony_manager_removable" />
</PreferenceCategory>