Clean up TelephonyManager channels in case of a forced restart
This commit is contained in:
parent
103be89d17
commit
7140840129
|
@ -3,6 +3,8 @@ package im.angry.openeuicc
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
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 java.lang.Exception
|
||||||
|
|
||||||
class OpenEuiccApplication : Application() {
|
class OpenEuiccApplication : Application() {
|
||||||
val telephonyManager by lazy {
|
val telephonyManager by lazy {
|
||||||
|
@ -12,4 +14,19 @@ class OpenEuiccApplication : Application() {
|
||||||
val euiccChannelManager by lazy {
|
val euiccChannelManager by lazy {
|
||||||
EuiccChannelManager(this)
|
EuiccChannelManager(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
// Clean up channels left open in TelephonyManager
|
||||||
|
// due to a (potentially) forced restart
|
||||||
|
for (slotId in 0 until EuiccChannelManager.MAX_SIMS) {
|
||||||
|
for (channel in 0 until 10) {
|
||||||
|
try {
|
||||||
|
telephonyManager.iccCloseLogicalChannelBySlot(slotId, channel)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
// We do not care
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,8 +21,6 @@ class TelephonyManagerApduChannel(
|
||||||
// TODO: On Tiramisu, we need to specify the portId also if we want MEP support
|
// TODO: On Tiramisu, we need to specify the portId also if we want MEP support
|
||||||
fun tryConnectUiccSlot(tm: TelephonyManager, slotId: Int): Pair<ApduChannel, EuiccChannelStateManager>? {
|
fun tryConnectUiccSlot(tm: TelephonyManager, slotId: Int): Pair<ApduChannel, EuiccChannelStateManager>? {
|
||||||
try {
|
try {
|
||||||
// FIXME: Clean up previously opened channels across restarts
|
|
||||||
tm.iccCloseLogicalChannelBySlot(slotId, 1)
|
|
||||||
val channel = tm.iccOpenLogicalChannelBySlot(slotId, EUICC_APP_ID, 0)
|
val channel = tm.iccOpenLogicalChannelBySlot(slotId, EUICC_APP_ID, 0)
|
||||||
if (channel.status != STATUS_NO_ERROR || channel.channel == INVALID_CHANNEL) {
|
if (channel.status != STATUS_NO_ERROR || channel.channel == INVALID_CHANNEL) {
|
||||||
Log.e(TAG, "Unable to open eUICC channel for slot ${slotId} via TelephonyManager: ${channel.status}")
|
Log.e(TAG, "Unable to open eUICC channel for slot ${slotId} via TelephonyManager: ${channel.status}")
|
||||||
|
|
Loading…
Reference in a new issue