Take a Mutex before modifying the EuiccChannel list
This commit is contained in:
parent
cc7f9a2957
commit
146b7fdc8d
|
@ -9,6 +9,8 @@ import android.util.Log
|
|||
import im.angry.openeuicc.OpenEuiccApplication
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
@ -23,6 +25,8 @@ class EuiccChannelManager(private val context: Context) {
|
|||
|
||||
private var seService: SEService? = null
|
||||
|
||||
private val lock = Mutex()
|
||||
|
||||
private val tm by lazy {
|
||||
(context.applicationContext as OpenEuiccApplication).telephonyManager
|
||||
}
|
||||
|
@ -43,6 +47,7 @@ class EuiccChannelManager(private val context: Context) {
|
|||
}
|
||||
|
||||
private suspend fun tryOpenEuiccChannel(uiccInfo: UiccCardInfo): EuiccChannel? {
|
||||
lock.withLock {
|
||||
ensureSEService()
|
||||
val existing = channels.find { it.slotId == uiccInfo.slotIndex }
|
||||
if (existing != null) {
|
||||
|
@ -55,7 +60,10 @@ class EuiccChannelManager(private val context: Context) {
|
|||
}
|
||||
|
||||
val channelInfo = EuiccChannelInfo(
|
||||
uiccInfo.slotIndex, uiccInfo.cardId, "SIM ${uiccInfo.slotIndex}", uiccInfo.isRemovable
|
||||
uiccInfo.slotIndex,
|
||||
uiccInfo.cardId,
|
||||
"SIM ${uiccInfo.slotIndex}",
|
||||
uiccInfo.isRemovable
|
||||
)
|
||||
|
||||
var euiccChannel: EuiccChannel? = null
|
||||
|
@ -76,6 +84,7 @@ class EuiccChannelManager(private val context: Context) {
|
|||
|
||||
return euiccChannel
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun findEuiccChannelBySlot(slotId: Int): EuiccChannel? {
|
||||
return tm.uiccCardsInfo.find { it.slotIndex == slotId }?.let {
|
||||
|
|
Loading…
Reference in a new issue