feat: force use tmapi #139

Closed
septs wants to merge 2 commits from septs:force-use-tmapi into master
7 changed files with 33 additions and 4 deletions

View file

@ -122,7 +122,7 @@ open class SettingsFragment: PreferenceFragmentCompat() {
return true return true
} }
private fun CheckBoxPreference.bindBooleanFlow(flow: PreferenceFlowWrapper<Boolean>) { protected fun CheckBoxPreference.bindBooleanFlow(flow: PreferenceFlowWrapper<Boolean>) {
lifecycleScope.launch { lifecycleScope.launch {
flow.collect { isChecked = it } flow.collect { isChecked = it }
} }

View file

@ -31,6 +31,7 @@ internal object PreferenceKeys {
// ---- Developer Options ---- // ---- Developer Options ----
val DEVELOPER_OPTIONS_ENABLED = booleanPreferencesKey("developer_options_enabled") val DEVELOPER_OPTIONS_ENABLED = booleanPreferencesKey("developer_options_enabled")
val REMOVABLE_TMAPI = booleanPreferencesKey("removable_tmapi")
val UNFILTERED_PROFILE_LIST = booleanPreferencesKey("unfiltered_profile_list") val UNFILTERED_PROFILE_LIST = booleanPreferencesKey("unfiltered_profile_list")
val IGNORE_TLS_CERTIFICATE = booleanPreferencesKey("ignore_tls_certificate") val IGNORE_TLS_CERTIFICATE = booleanPreferencesKey("ignore_tls_certificate")
} }
@ -48,6 +49,7 @@ class PreferenceRepository(private val context: Context) {
// ---- Developer Options ---- // ---- Developer Options ----
val developerOptionsEnabledFlow = bindFlow(PreferenceKeys.DEVELOPER_OPTIONS_ENABLED, false) val developerOptionsEnabledFlow = bindFlow(PreferenceKeys.DEVELOPER_OPTIONS_ENABLED, false)
val removableTMAPIFlow = bindFlow(PreferenceKeys.REMOVABLE_TMAPI, false)
val unfilteredProfileListFlow = bindFlow(PreferenceKeys.UNFILTERED_PROFILE_LIST, false) val unfilteredProfileListFlow = bindFlow(PreferenceKeys.UNFILTERED_PROFILE_LIST, false)
val ignoreTLSCertificateFlow = bindFlow(PreferenceKeys.IGNORE_TLS_CERTIFICATE, false) val ignoreTLSCertificateFlow = bindFlow(PreferenceKeys.IGNORE_TLS_CERTIFICATE, false)

View file

@ -52,7 +52,7 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <im.angry.openeuicc.ui.preference.LongSummaryPreferenceCategory
app:key="pref_developer" app:key="pref_developer"
app:title="@string/pref_developer" app:title="@string/pref_developer"
app:iconSpaceReserved="false"> app:iconSpaceReserved="false">
@ -69,7 +69,7 @@
app:summary="@string/pref_developer_ignore_tls_certificate_desc" app:summary="@string/pref_developer_ignore_tls_certificate_desc"
app:title="@string/pref_developer_ignore_tls_certificate" /> app:title="@string/pref_developer_ignore_tls_certificate" />
</PreferenceCategory> </im.angry.openeuicc.ui.preference.LongSummaryPreferenceCategory>
<PreferenceCategory <PreferenceCategory
app:key="pref_info" app:key="pref_info"

View file

@ -5,6 +5,7 @@ import android.util.Log
import im.angry.openeuicc.OpenEuiccApplication import im.angry.openeuicc.OpenEuiccApplication
import im.angry.openeuicc.R import im.angry.openeuicc.R
import im.angry.openeuicc.util.* import im.angry.openeuicc.util.*
import kotlinx.coroutines.flow.first
import java.lang.IllegalArgumentException import java.lang.IllegalArgumentException
class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFactory(context) { class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFactory(context) {
@ -21,7 +22,7 @@ class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFacto
super.tryOpenEuiccChannel(port)?.let { return it } super.tryOpenEuiccChannel(port)?.let { return it }
} }
if (port.card.isEuicc) { if (port.card.isEuicc || context.preferenceRepository.removableTMAPIFlow.first()) {
Log.i( Log.i(
DefaultEuiccChannelManager.TAG, DefaultEuiccChannelManager.TAG,
"Trying TelephonyManager for slot ${port.card.physicalSlotIndex} port ${port.portIndex}" "Trying TelephonyManager for slot ${port.card.physicalSlotIndex} port ${port.portIndex}"

View file

@ -1,11 +1,17 @@
package im.angry.openeuicc.ui package im.angry.openeuicc.ui
import android.os.Bundle import android.os.Bundle
import androidx.preference.CheckBoxPreference
import androidx.preference.Preference import androidx.preference.Preference
import im.angry.openeuicc.R
import im.angry.openeuicc.util.preferenceRepository
class PrivilegedSettingsFragment : SettingsFragment() { class PrivilegedSettingsFragment : SettingsFragment() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
super.onCreatePreferences(savedInstanceState, rootKey) super.onCreatePreferences(savedInstanceState, rootKey)
addPreferencesFromResource(R.xml.pref_privileged_settings)
mergePreferenceOverlay("pref_developer_overlay", "pref_developer")
// It's stupid to _disable_ things for privileged, but for now, the per-app locale picker // It's stupid to _disable_ things for privileged, but for now, the per-app locale picker
// is not usable for apps signed with the platform key. // is not usable for apps signed with the platform key.
// ref: <https://android.googlesource.com/platform/packages/apps/Settings/+/refs/tags/android-15.0.0_r6/src/com/android/settings/applications/AppLocaleUtil.java#60> // ref: <https://android.googlesource.com/platform/packages/apps/Settings/+/refs/tags/android-15.0.0_r6/src/com/android/settings/applications/AppLocaleUtil.java#60>
@ -13,5 +19,9 @@ class PrivilegedSettingsFragment : SettingsFragment() {
// eventually work for platform-signed apps. Or, at some point we might introduce our own // eventually work for platform-signed apps. Or, at some point we might introduce our own
// locale picker, which hopefully works whether privileged or not. // locale picker, which hopefully works whether privileged or not.
requirePreference<Preference>("pref_advanced_language").isVisible = false requirePreference<Preference>("pref_advanced_language").isVisible = false
// Force use TelephonyManager API
requirePreference<CheckBoxPreference>("pref_developer_tmapi_removable")
.bindBooleanFlow(preferenceRepository.removableTMAPIFlow)
} }
} }

View file

@ -22,4 +22,8 @@
<string name="lui_desc">Your device supports eSIMs. To connect to mobile network, download your eSIM issued by a carrier, or insert a physical SIM.</string> <string name="lui_desc">Your device supports eSIMs. To connect to mobile network, download your eSIM issued by a carrier, or insert a physical SIM.</string>
<string name="lui_skip">Skip</string> <string name="lui_skip">Skip</string>
<string name="lui_download">Download eSIM</string> <string name="lui_download">Download eSIM</string>
<!-- Preference -->
<string name="pref_developer_tmapi_removable">Using TMAPI for removable</string>
<string name="pref_developer_tmapi_removable_desc">TMAPI (TelephonyManager API) will not be enabled in non-euicc mode and some removable eSIM cards may not work.\nEnable this option to skip detection and force TMAPI to be enabled.</string>
</resources> </resources>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
app:isPreferenceVisible="false"
app:key="pref_developer_overlay">
<CheckBoxPreference
app:iconSpaceReserved="false"
app:key="pref_developer_tmapi_removable"
app:summary="@string/pref_developer_tmapi_removable_desc"
app:title="@string/pref_developer_tmapi_removable" />
</PreferenceCategory>
</PreferenceScreen>