Refresh system cached Euicc profile info every time LUI is started

This commit is contained in:
Peter Cai 2022-05-03 18:59:30 -04:00
parent eb862301cc
commit 67d03a0696
5 changed files with 37 additions and 8 deletions

View file

@ -1,6 +1,7 @@
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 android.telephony.TelephonyManager
import im.angry.openeuicc.core.EuiccChannelManager import im.angry.openeuicc.core.EuiccChannelManager
import im.angry.openeuicc.util.* import im.angry.openeuicc.util.*
@ -15,6 +16,10 @@ class OpenEuiccApplication : Application() {
EuiccChannelManager(this) EuiccChannelManager(this)
} }
val subscriptionManager by lazy {
getSystemService(SubscriptionManager::class.java)!!
}
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
// Clean up channels left open in TelephonyManager // Clean up channels left open in TelephonyManager

View file

@ -9,6 +9,7 @@ interface EuiccChannelStateManager {
data class EuiccChannel( data class EuiccChannel(
val slotId: Int, val slotId: Int,
val cardId: Int,
val name: String, val name: String,
val lpa: LocalProfileAssistant, val lpa: LocalProfileAssistant,
val stateManager: EuiccChannelStateManager val stateManager: EuiccChannelStateManager

View file

@ -56,10 +56,10 @@ class EuiccChannelManager(private val context: Context) {
} }
} }
val shouldTryTelephonyManager = val (shouldTryTelephonyManager, cardId) =
tm.uiccCardsInfo.find { it.slotIndex == slotId }?.let { tm.uiccCardsInfo.find { it.slotIndex == slotId }?.let {
it.isEuicc && !it.isRemovable Pair(it.isEuicc && !it.isRemovable, it.cardId)
} ?: false } ?: Pair(false, 0)
var apduChannel: ApduChannel? = null var apduChannel: ApduChannel? = null
var stateManager: EuiccChannelStateManager? = null var stateManager: EuiccChannelStateManager? = null
@ -81,7 +81,11 @@ class EuiccChannelManager(private val context: Context) {
} ?: return null } ?: return null
} }
val channel = EuiccChannel(slotId, "SIM $slotId", LocalProfileAssistantImpl(apduChannel), stateManager!!) val channel = EuiccChannel(
slotId, cardId,
"SIM $slotId",
LocalProfileAssistantImpl(apduChannel),
stateManager!!)
channels.add(channel) channels.add(channel)
return channel return channel
} }

View file

@ -15,9 +15,7 @@ import androidx.lifecycle.lifecycleScope
import im.angry.openeuicc.R import im.angry.openeuicc.R
import im.angry.openeuicc.core.EuiccChannelManager import im.angry.openeuicc.core.EuiccChannelManager
import im.angry.openeuicc.databinding.ActivityMainBinding import im.angry.openeuicc.databinding.ActivityMainBinding
import im.angry.openeuicc.util.dsdsEnabled import im.angry.openeuicc.util.*
import im.angry.openeuicc.util.openEuiccApplication
import im.angry.openeuicc.util.supportsDSDS
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -99,6 +97,7 @@ class MainActivity : AppCompatActivity() {
manager.knownChannels.forEach { manager.knownChannels.forEach {
Log.d(TAG, it.name) Log.d(TAG, it.name)
Log.d(TAG, it.lpa.eid) Log.d(TAG, it.lpa.eid)
openEuiccApplication.subscriptionManager.tryRefreshCachedEuiccInfo(it.cardId)
} }
} }

View file

@ -1,7 +1,9 @@
package im.angry.openeuicc.util package im.angry.openeuicc.util
import android.telephony.IccOpenLogicalChannelResponse import android.telephony.IccOpenLogicalChannelResponse
import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager import android.telephony.TelephonyManager
import java.lang.Exception
import java.lang.reflect.Method import java.lang.reflect.Method
val TelephonyManager.supportsDSDS: Boolean val TelephonyManager.supportsDSDS: Boolean
@ -13,6 +15,16 @@ var TelephonyManager.dsdsEnabled: Boolean
switchMultiSimConfig(if (value) { 2 } else {1}) switchMultiSimConfig(if (value) { 2 } else {1})
} }
fun SubscriptionManager.tryRefreshCachedEuiccInfo(cardId: Int) {
if (cardId != 0) {
try {
requestEmbeddedSubscriptionInfoListRefresh(cardId)
} catch (e: Exception) {
// Ignore
}
}
}
// Hidden APIs via reflection to enable building without AOSP source tree // Hidden APIs via reflection to enable building without AOSP source tree
private val iccOpenLogicalChannelBySlot: Method by lazy { private val iccOpenLogicalChannelBySlot: Method by lazy {
TelephonyManager::class.java.getMethod( TelephonyManager::class.java.getMethod(
@ -48,4 +60,12 @@ fun TelephonyManager.iccTransmitApduLogicalChannelBySlot(
): String? = ): String? =
iccTransmitApduLogicalChannelBySlot.invoke( iccTransmitApduLogicalChannelBySlot.invoke(
this, slotId, channel, cla, instruction, p1, p2, p3, data this, slotId, channel, cla, instruction, p1, p2, p3, data
) as String? ) as String?
private val requestEmbeddedSubscriptionInfoListRefresh: Method by lazy {
SubscriptionManager::class.java.getMethod("requestEmbeddedSubscriptionInfoListRefresh", Int::class.java)
}
fun SubscriptionManager.requestEmbeddedSubscriptionInfoListRefresh(cardId: Int): Unit {
requestEmbeddedSubscriptionInfoListRefresh.invoke(this, cardId)
}