|
@@ -7,18 +7,19 @@ import android.se.omapi.SEService
|
|
|
import android.telephony.UiccCardInfo
|
|
import android.telephony.UiccCardInfo
|
|
|
import android.util.Log
|
|
import android.util.Log
|
|
|
import im.angry.openeuicc.OpenEuiccApplication
|
|
import im.angry.openeuicc.OpenEuiccApplication
|
|
|
|
|
+import im.angry.openeuicc.util.*
|
|
|
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
|
|
|
import kotlinx.coroutines.sync.withLock
|
|
import kotlinx.coroutines.sync.withLock
|
|
|
import kotlinx.coroutines.withContext
|
|
import kotlinx.coroutines.withContext
|
|
|
|
|
+import java.lang.Exception
|
|
|
import kotlin.coroutines.resume
|
|
import kotlin.coroutines.resume
|
|
|
import kotlin.coroutines.suspendCoroutine
|
|
import kotlin.coroutines.suspendCoroutine
|
|
|
|
|
|
|
|
class EuiccChannelManager(private val context: Context) {
|
|
class EuiccChannelManager(private val context: Context) {
|
|
|
companion object {
|
|
companion object {
|
|
|
const val TAG = "EuiccChannelManager"
|
|
const val TAG = "EuiccChannelManager"
|
|
|
- const val MAX_SIMS = 3
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private val channels = mutableListOf<EuiccChannel>()
|
|
private val channels = mutableListOf<EuiccChannel>()
|
|
@@ -124,4 +125,19 @@ class EuiccChannelManager(private val context: Context) {
|
|
|
seService?.shutdown()
|
|
seService?.shutdown()
|
|
|
seService = null
|
|
seService = null
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // Clean up channels left open in TelephonyManager
|
|
|
|
|
+ // due to a (potentially) forced restart
|
|
|
|
|
+ // This should be called every time the application is restarted
|
|
|
|
|
+ fun closeAllStaleChannels() {
|
|
|
|
|
+ for (card in tm.uiccCardsInfo) {
|
|
|
|
|
+ for (channel in 0 until 10) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ tm.iccCloseLogicalChannelBySlot(card.slotIndex, channel)
|
|
|
|
|
+ } catch (_: Exception) {
|
|
|
|
|
+ // We do not care
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|