refactor: Condense dependency management to a rudimentary dependency injection subpackage
All checks were successful
/ build-debug (push) Successful in 4m16s
All checks were successful
/ build-debug (push) Successful in 4m16s
This commit is contained in:
parent
770083523d
commit
2d1c96023a
|
@ -1,34 +1,19 @@
|
||||||
package im.angry.openeuicc
|
package im.angry.openeuicc
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.telephony.SubscriptionManager
|
|
||||||
import android.telephony.TelephonyManager
|
|
||||||
import com.google.android.material.color.DynamicColors
|
import com.google.android.material.color.DynamicColors
|
||||||
import im.angry.openeuicc.core.EuiccChannelManager
|
import im.angry.openeuicc.di.AppContainer
|
||||||
import im.angry.openeuicc.core.IEuiccChannelManager
|
import im.angry.openeuicc.di.DefaultAppContainer
|
||||||
import im.angry.openeuicc.util.PreferenceRepository
|
|
||||||
|
|
||||||
open class OpenEuiccApplication : Application() {
|
open class OpenEuiccApplication : Application() {
|
||||||
|
open val appContainer: AppContainer by lazy {
|
||||||
|
DefaultAppContainer(this)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
// Observe dynamic colors changes
|
// Observe dynamic colors changes
|
||||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
val telephonyManager by lazy {
|
|
||||||
getSystemService(TelephonyManager::class.java)!!
|
|
||||||
}
|
|
||||||
|
|
||||||
open val euiccChannelManager: IEuiccChannelManager by lazy {
|
|
||||||
EuiccChannelManager(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
val subscriptionManager by lazy {
|
|
||||||
getSystemService(SubscriptionManager::class.java)!!
|
|
||||||
}
|
|
||||||
|
|
||||||
val preferenceRepository by lazy {
|
|
||||||
PreferenceRepository(this)
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -25,7 +25,7 @@ open class EuiccChannelManager(protected val context: Context) : IEuiccChannelMa
|
||||||
private val lock = Mutex()
|
private val lock = Mutex()
|
||||||
|
|
||||||
protected val tm by lazy {
|
protected val tm by lazy {
|
||||||
(context.applicationContext as OpenEuiccApplication).telephonyManager
|
(context.applicationContext as OpenEuiccApplication).appContainer.telephonyManager
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open val uiccCards: Collection<UiccCardInfoCompat>
|
protected open val uiccCards: Collection<UiccCardInfoCompat>
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package im.angry.openeuicc.di
|
||||||
|
|
||||||
|
import android.telephony.SubscriptionManager
|
||||||
|
import android.telephony.TelephonyManager
|
||||||
|
import im.angry.openeuicc.core.IEuiccChannelManager
|
||||||
|
import im.angry.openeuicc.util.*
|
||||||
|
|
||||||
|
interface AppContainer {
|
||||||
|
val telephonyManager: TelephonyManager
|
||||||
|
val euiccChannelManager: IEuiccChannelManager
|
||||||
|
val subscriptionManager: SubscriptionManager
|
||||||
|
val preferenceRepository: PreferenceRepository
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package im.angry.openeuicc.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.telephony.SubscriptionManager
|
||||||
|
import android.telephony.TelephonyManager
|
||||||
|
import im.angry.openeuicc.core.EuiccChannelManager
|
||||||
|
import im.angry.openeuicc.core.IEuiccChannelManager
|
||||||
|
import im.angry.openeuicc.util.*
|
||||||
|
|
||||||
|
open class DefaultAppContainer(context: Context) : AppContainer {
|
||||||
|
override val telephonyManager by lazy {
|
||||||
|
context.getSystemService(TelephonyManager::class.java)!!
|
||||||
|
}
|
||||||
|
|
||||||
|
override val euiccChannelManager: IEuiccChannelManager by lazy {
|
||||||
|
EuiccChannelManager(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val subscriptionManager by lazy {
|
||||||
|
context.getSystemService(SubscriptionManager::class.java)!!
|
||||||
|
}
|
||||||
|
|
||||||
|
override val preferenceRepository by lazy {
|
||||||
|
PreferenceRepository(context)
|
||||||
|
}
|
||||||
|
}
|
|
@ -121,7 +121,7 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
|
||||||
super.onStart()
|
super.onStart()
|
||||||
profileDownloadIMEI.editText!!.text = Editable.Factory.getInstance().newEditable(
|
profileDownloadIMEI.editText!!.text = Editable.Factory.getInstance().newEditable(
|
||||||
try {
|
try {
|
||||||
openEuiccApplication.telephonyManager.getImei(channel.logicalSlotId)
|
telephonyManager.getImei(channel.logicalSlotId)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import androidx.fragment.app.Fragment
|
||||||
import im.angry.openeuicc.OpenEuiccApplication
|
import im.angry.openeuicc.OpenEuiccApplication
|
||||||
import im.angry.openeuicc.core.EuiccChannel
|
import im.angry.openeuicc.core.EuiccChannel
|
||||||
import im.angry.openeuicc.core.IEuiccChannelManager
|
import im.angry.openeuicc.core.IEuiccChannelManager
|
||||||
|
import im.angry.openeuicc.di.AppContainer
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
@ -48,11 +49,14 @@ interface OpenEuiccContextMarker {
|
||||||
val openEuiccApplication: OpenEuiccApplication
|
val openEuiccApplication: OpenEuiccApplication
|
||||||
get() = openEuiccMarkerContext.applicationContext as OpenEuiccApplication
|
get() = openEuiccMarkerContext.applicationContext as OpenEuiccApplication
|
||||||
|
|
||||||
|
val appContainer: AppContainer
|
||||||
|
get() = openEuiccApplication.appContainer
|
||||||
|
|
||||||
val euiccChannelManager: IEuiccChannelManager
|
val euiccChannelManager: IEuiccChannelManager
|
||||||
get() = openEuiccApplication.euiccChannelManager
|
get() = appContainer.euiccChannelManager
|
||||||
|
|
||||||
val telephonyManager: TelephonyManager
|
val telephonyManager: TelephonyManager
|
||||||
get() = openEuiccApplication.telephonyManager
|
get() = appContainer.telephonyManager
|
||||||
}
|
}
|
||||||
|
|
||||||
val LocalProfileInfo.isEnabled: Boolean
|
val LocalProfileInfo.isEnabled: Boolean
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
package im.angry.openeuicc
|
package im.angry.openeuicc
|
||||||
|
|
||||||
import im.angry.openeuicc.core.IEuiccChannelManager
|
|
||||||
import im.angry.openeuicc.core.PrivilegedEuiccChannelManager
|
import im.angry.openeuicc.core.PrivilegedEuiccChannelManager
|
||||||
|
import im.angry.openeuicc.di.AppContainer
|
||||||
|
import im.angry.openeuicc.di.PrivilegedAppContainer
|
||||||
|
|
||||||
class PrivilegedOpenEuiccApplication: OpenEuiccApplication() {
|
class PrivilegedOpenEuiccApplication: OpenEuiccApplication() {
|
||||||
override val euiccChannelManager: IEuiccChannelManager by lazy {
|
override val appContainer: AppContainer by lazy {
|
||||||
PrivilegedEuiccChannelManager(this)
|
PrivilegedAppContainer(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
(euiccChannelManager as PrivilegedEuiccChannelManager).closeAllStaleChannels()
|
(appContainer.euiccChannelManager as PrivilegedEuiccChannelManager).closeAllStaleChannels()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -48,7 +48,7 @@ class PrivilegedEuiccChannelManager(context: Context): EuiccChannelManager(conte
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun notifyEuiccProfilesChanged(logicalSlotId: Int) {
|
override fun notifyEuiccProfilesChanged(logicalSlotId: Int) {
|
||||||
(context.applicationContext as OpenEuiccApplication).subscriptionManager.apply {
|
(context.applicationContext as OpenEuiccApplication).appContainer.subscriptionManager.apply {
|
||||||
findEuiccChannelBySlotBlocking(logicalSlotId)?.let {
|
findEuiccChannelBySlotBlocking(logicalSlotId)?.let {
|
||||||
tryRefreshCachedEuiccInfo(it.cardId)
|
tryRefreshCachedEuiccInfo(it.cardId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package im.angry.openeuicc.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import im.angry.openeuicc.core.IEuiccChannelManager
|
||||||
|
import im.angry.openeuicc.core.PrivilegedEuiccChannelManager
|
||||||
|
|
||||||
|
class PrivilegedAppContainer(context: Context) : DefaultAppContainer(context) {
|
||||||
|
override val euiccChannelManager: IEuiccChannelManager by lazy {
|
||||||
|
PrivilegedEuiccChannelManager(context)
|
||||||
|
}
|
||||||
|
}
|
|
@ -238,7 +238,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
|
||||||
}
|
}
|
||||||
val success = channel.lpa
|
val success = channel.lpa
|
||||||
.setNickname(iccid, nickname!!)
|
.setNickname(iccid, nickname!!)
|
||||||
openEuiccApplication.subscriptionManager.tryRefreshCachedEuiccInfo(channel.cardId)
|
appContainer.subscriptionManager.tryRefreshCachedEuiccInfo(channel.cardId)
|
||||||
return if (success) {
|
return if (success) {
|
||||||
RESULT_OK
|
RESULT_OK
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -26,7 +26,7 @@ class PrivilegedMainActivity : MainActivity() {
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||||
R.id.dsds -> {
|
R.id.dsds -> {
|
||||||
tm.setDsdsEnabled(openEuiccApplication.euiccChannelManager, !item.isChecked)
|
tm.setDsdsEnabled(euiccChannelManager, !item.isChecked)
|
||||||
Toast.makeText(this, R.string.toast_dsds_switched, Toast.LENGTH_LONG).show()
|
Toast.makeText(this, R.string.toast_dsds_switched, Toast.LENGTH_LONG).show()
|
||||||
finish()
|
finish()
|
||||||
true
|
true
|
||||||
|
|
|
@ -32,12 +32,8 @@ class SlotMappingFragment: BaseMaterialDialogFragment(),
|
||||||
const val TAG = "SlotMappingFragment"
|
const val TAG = "SlotMappingFragment"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val tm: TelephonyManager by lazy {
|
|
||||||
(requireContext().applicationContext as OpenEuiccApplication).telephonyManager
|
|
||||||
}
|
|
||||||
|
|
||||||
private val ports: List<UiccPortInfoCompat> by lazy {
|
private val ports: List<UiccPortInfoCompat> by lazy {
|
||||||
tm.uiccCardsInfoCompat.flatMap { it.ports }
|
telephonyManager.uiccCardsInfoCompat.flatMap { it.ports }
|
||||||
}
|
}
|
||||||
|
|
||||||
private val portsDesc: List<String> by lazy {
|
private val portsDesc: List<String> by lazy {
|
||||||
|
@ -81,7 +77,7 @@ class SlotMappingFragment: BaseMaterialDialogFragment(),
|
||||||
private fun init() {
|
private fun init() {
|
||||||
lifecycleScope.launch(Dispatchers.Main) {
|
lifecycleScope.launch(Dispatchers.Main) {
|
||||||
val mapping = withContext(Dispatchers.IO) {
|
val mapping = withContext(Dispatchers.IO) {
|
||||||
tm.simSlotMapping
|
telephonyManager.simSlotMapping
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter = SlotMappingAdapter(mapping.toMutableList().apply {
|
adapter = SlotMappingAdapter(mapping.toMutableList().apply {
|
||||||
|
@ -100,14 +96,14 @@ class SlotMappingFragment: BaseMaterialDialogFragment(),
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
// Use the utility method from PrivilegedTelephonyUtils to ensure
|
// Use the utility method from PrivilegedTelephonyUtils to ensure
|
||||||
// unmapped ports have all profiles disabled
|
// unmapped ports have all profiles disabled
|
||||||
tm.updateSimSlotMapping(openEuiccApplication.euiccChannelManager, adapter.mappings)
|
telephonyManager.updateSimSlotMapping(euiccChannelManager, adapter.mappings)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Toast.makeText(requireContext(), R.string.slot_mapping_failure, Toast.LENGTH_LONG).show()
|
Toast.makeText(requireContext(), R.string.slot_mapping_failure, Toast.LENGTH_LONG).show()
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
Toast.makeText(requireContext(), R.string.slot_mapping_completed, Toast.LENGTH_LONG).show()
|
Toast.makeText(requireContext(), R.string.slot_mapping_completed, Toast.LENGTH_LONG).show()
|
||||||
openEuiccApplication.euiccChannelManager.invalidate()
|
euiccChannelManager.invalidate()
|
||||||
requireActivity().finish()
|
requireActivity().finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +111,7 @@ class SlotMappingFragment: BaseMaterialDialogFragment(),
|
||||||
private suspend fun buildHelpText() = withContext(Dispatchers.IO) {
|
private suspend fun buildHelpText() = withContext(Dispatchers.IO) {
|
||||||
val nLogicalSlots = adapter.mappings.size
|
val nLogicalSlots = adapter.mappings.size
|
||||||
|
|
||||||
val cards = openEuiccApplication.telephonyManager.uiccCardsInfoCompat
|
val cards = telephonyManager.uiccCardsInfoCompat
|
||||||
|
|
||||||
val nPhysicalSlots = cards.size
|
val nPhysicalSlots = cards.size
|
||||||
var idxMepCard = -1
|
var idxMepCard = -1
|
||||||
|
@ -129,7 +125,7 @@ class SlotMappingFragment: BaseMaterialDialogFragment(),
|
||||||
}
|
}
|
||||||
|
|
||||||
val mayEnableDSDS =
|
val mayEnableDSDS =
|
||||||
openEuiccApplication.telephonyManager.supportsDSDS && !openEuiccApplication.telephonyManager.dsdsEnabled
|
telephonyManager.supportsDSDS && !telephonyManager.dsdsEnabled
|
||||||
val extraText =
|
val extraText =
|
||||||
if (nLogicalSlots == 1 && mayEnableDSDS) {
|
if (nLogicalSlots == 1 && mayEnableDSDS) {
|
||||||
getString(R.string.slot_mapping_help_dsds)
|
getString(R.string.slot_mapping_help_dsds)
|
||||||
|
|
Loading…
Reference in a new issue