feat: update TelephonyManager preference key and implement context marker interface (#167)
All checks were successful
/ build-debug (push) Successful in 4m38s
All checks were successful
/ build-debug (push) Successful in 4m38s
Reviewed-on: #167 Co-authored-by: septs <github@septs.pw> Co-committed-by: septs <github@septs.pw>
This commit is contained in:
parent
74cc08ce8e
commit
88eb1ce0e2
4 changed files with 20 additions and 6 deletions
|
@ -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}"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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?
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Reference in a new issue