Compare commits
2 commits
7215a2351b
...
5dacb75717
Author | SHA1 | Date | |
---|---|---|---|
5dacb75717 | |||
f28867ef2e |
4 changed files with 6 additions and 87 deletions
|
@ -113,25 +113,7 @@ open class DefaultEuiccChannelManager(
|
|||
findEuiccChannelBySlot(logicalSlotId)
|
||||
}
|
||||
|
||||
override fun findEuiccChannelByPhysicalSlotBlocking(physicalSlotId: Int): EuiccChannel? =
|
||||
runBlocking {
|
||||
withContext(Dispatchers.IO) {
|
||||
if (physicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) {
|
||||
return@withContext usbChannel
|
||||
}
|
||||
|
||||
for (card in uiccCards) {
|
||||
if (card.physicalSlotIndex != physicalSlotId) continue
|
||||
for (port in card.ports) {
|
||||
tryOpenEuiccChannel(port)?.let { return@withContext it }
|
||||
}
|
||||
}
|
||||
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun findAllEuiccChannelsByPhysicalSlot(physicalSlotId: Int): List<EuiccChannel>? {
|
||||
private suspend fun findAllEuiccChannelsByPhysicalSlot(physicalSlotId: Int): List<EuiccChannel>? {
|
||||
if (physicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) {
|
||||
return usbChannel?.let { listOf(it) }
|
||||
}
|
||||
|
@ -144,11 +126,6 @@ open class DefaultEuiccChannelManager(
|
|||
return null
|
||||
}
|
||||
|
||||
override fun findAllEuiccChannelsByPhysicalSlotBlocking(physicalSlotId: Int): List<EuiccChannel>? =
|
||||
runBlocking {
|
||||
findAllEuiccChannelsByPhysicalSlot(physicalSlotId)
|
||||
}
|
||||
|
||||
override suspend fun findEuiccChannelByPort(physicalSlotId: Int, portId: Int): EuiccChannel? =
|
||||
withContext(Dispatchers.IO) {
|
||||
if (physicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) {
|
||||
|
|
|
@ -52,20 +52,6 @@ interface EuiccChannelManager {
|
|||
*/
|
||||
fun findEuiccChannelBySlotBlocking(logicalSlotId: Int): EuiccChannel?
|
||||
|
||||
/**
|
||||
* Returns the first EuiccChannel corresponding to a **physical** slot
|
||||
* If the physical slot supports MEP and has multiple ports, it is undefined
|
||||
* which of the two channels will be returned.
|
||||
*/
|
||||
fun findEuiccChannelByPhysicalSlotBlocking(physicalSlotId: Int): EuiccChannel?
|
||||
|
||||
/**
|
||||
* Returns all EuiccChannels corresponding to a **physical** slot
|
||||
* Multiple channels are possible in the case of MEP
|
||||
*/
|
||||
suspend fun findAllEuiccChannelsByPhysicalSlot(physicalSlotId: Int): List<EuiccChannel>?
|
||||
fun findAllEuiccChannelsByPhysicalSlotBlocking(physicalSlotId: Int): List<EuiccChannel>?
|
||||
|
||||
/**
|
||||
* Returns the EuiccChannel corresponding to a **physical** slot and a port ID
|
||||
*/
|
||||
|
|
|
@ -3,9 +3,6 @@ package im.angry.openeuicc.util
|
|||
import android.util.Log
|
||||
import im.angry.openeuicc.core.EuiccChannel
|
||||
import im.angry.openeuicc.core.EuiccChannelManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import net.typeblog.lpac_jni.LocalProfileAssistant
|
||||
import net.typeblog.lpac_jni.LocalProfileInfo
|
||||
|
||||
|
@ -109,39 +106,3 @@ suspend inline fun EuiccChannelManager.beginTrackedOperation(
|
|||
}
|
||||
Log.d(TAG, "Operation complete")
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as beginTrackedOperation but uses blocking primitives.
|
||||
* TODO: This function needs to be phased out of use.
|
||||
*/
|
||||
inline fun EuiccChannelManager.beginTrackedOperationBlocking(
|
||||
slotId: Int,
|
||||
portId: Int,
|
||||
op: () -> Boolean
|
||||
) {
|
||||
val latestSeq =
|
||||
findEuiccChannelByPortBlocking(slotId, portId)!!.lpa.notifications.firstOrNull()?.seqNumber
|
||||
?: 0
|
||||
Log.d(TAG, "Latest notification is $latestSeq before operation")
|
||||
if (op()) {
|
||||
Log.d(TAG, "Operation has requested notification handling")
|
||||
try {
|
||||
// Note that the exact instance of "channel" might have changed here if reconnected;
|
||||
// so we MUST use the automatic getter for "channel"
|
||||
findEuiccChannelByPortBlocking(
|
||||
slotId,
|
||||
portId
|
||||
)?.lpa?.notifications?.filter { it.seqNumber > latestSeq }?.forEach {
|
||||
Log.d(TAG, "Handling notification $it")
|
||||
findEuiccChannelByPortBlocking(
|
||||
slotId,
|
||||
portId
|
||||
)?.lpa?.handleNotification(it.seqNumber)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// Ignore any error during notification handling
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "Operation complete")
|
||||
}
|
|
@ -42,15 +42,6 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
|
|||
) {
|
||||
val euiccChannelManager
|
||||
get() = euiccChannelManagerService.euiccChannelManager
|
||||
|
||||
fun findChannel(physicalSlotId: Int): EuiccChannel? =
|
||||
euiccChannelManager.findEuiccChannelByPhysicalSlotBlocking(physicalSlotId)
|
||||
|
||||
fun findChannel(slotId: Int, portId: Int): EuiccChannel? =
|
||||
euiccChannelManager.findEuiccChannelByPortBlocking(slotId, portId)
|
||||
|
||||
fun findAllChannels(physicalSlotId: Int): List<EuiccChannel>? =
|
||||
euiccChannelManager.findAllEuiccChannelsByPhysicalSlotBlocking(physicalSlotId)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,7 +79,11 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
|
|||
}
|
||||
|
||||
override fun onGetEid(slotId: Int): String? = withEuiccChannelManager {
|
||||
findChannel(slotId)?.lpa?.eID
|
||||
val portId = euiccChannelManager.findFirstAvailablePort(slotId)
|
||||
if (portId < 0) return@withEuiccChannelManager null
|
||||
euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
|
||||
channel.lpa.eID
|
||||
}
|
||||
}
|
||||
|
||||
// When two eSIM cards are present on one device, the Android settings UI
|
||||
|
|
Loading…
Add table
Reference in a new issue