Compare commits
2 commits
65c9a7dc39
...
d54fcf2589
Author | SHA1 | Date | |
---|---|---|---|
d54fcf2589 | |||
7cb872a664 |
6 changed files with 58 additions and 20 deletions
|
@ -33,7 +33,7 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
|
||||||
|
|
||||||
Log.i(DefaultEuiccChannelManager.TAG, "Trying OMAPI for physical slot ${port.card.physicalSlotIndex}")
|
Log.i(DefaultEuiccChannelManager.TAG, "Trying OMAPI for physical slot ${port.card.physicalSlotIndex}")
|
||||||
try {
|
try {
|
||||||
return EuiccChannel(
|
return EuiccChannelImpl(
|
||||||
port,
|
port,
|
||||||
OmapiApduInterface(
|
OmapiApduInterface(
|
||||||
seService!!,
|
seService!!,
|
||||||
|
@ -61,7 +61,7 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
|
||||||
if (bulkIn == null || bulkOut == null) return null
|
if (bulkIn == null || bulkOut == null) return null
|
||||||
val conn = usbManager.openDevice(usbDevice) ?: return null
|
val conn = usbManager.openDevice(usbDevice) ?: return null
|
||||||
if (!conn.claimInterface(usbInterface, true)) return null
|
if (!conn.claimInterface(usbInterface, true)) return null
|
||||||
return EuiccChannel(
|
return EuiccChannelImpl(
|
||||||
FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
|
FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
|
||||||
UsbApduInterface(
|
UsbApduInterface(
|
||||||
conn,
|
conn,
|
||||||
|
|
|
@ -159,6 +159,16 @@ open class DefaultEuiccChannelManager(
|
||||||
findEuiccChannelByPort(physicalSlotId, portId)
|
findEuiccChannelByPort(physicalSlotId, portId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun <R> withEuiccChannel(
|
||||||
|
physicalSlotId: Int,
|
||||||
|
portId: Int,
|
||||||
|
fn: (EuiccChannel) -> R
|
||||||
|
): R {
|
||||||
|
val channel = findEuiccChannelByPortBlocking(physicalSlotId, portId)
|
||||||
|
?: throw EuiccChannelManager.EuiccChannelNotFoundException()
|
||||||
|
return fn(channel)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun waitForReconnect(physicalSlotId: Int, portId: Int, timeoutMillis: Long) {
|
override suspend fun waitForReconnect(physicalSlotId: Int, portId: Int, timeoutMillis: Long) {
|
||||||
if (physicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) return
|
if (physicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) return
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,18 @@
|
||||||
package im.angry.openeuicc.core
|
package im.angry.openeuicc.core
|
||||||
|
|
||||||
import im.angry.openeuicc.util.*
|
import im.angry.openeuicc.util.*
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import net.typeblog.lpac_jni.ApduInterface
|
|
||||||
import net.typeblog.lpac_jni.LocalProfileAssistant
|
import net.typeblog.lpac_jni.LocalProfileAssistant
|
||||||
import net.typeblog.lpac_jni.impl.HttpInterfaceImpl
|
|
||||||
import net.typeblog.lpac_jni.impl.LocalProfileAssistantImpl
|
|
||||||
|
|
||||||
class EuiccChannel(
|
interface EuiccChannel {
|
||||||
val port: UiccPortInfoCompat,
|
val port: UiccPortInfoCompat
|
||||||
apduInterface: ApduInterface,
|
|
||||||
verboseLoggingFlow: Flow<Boolean>
|
|
||||||
) {
|
|
||||||
val slotId = port.card.physicalSlotIndex // PHYSICAL slot
|
|
||||||
val logicalSlotId = port.logicalSlotIndex
|
|
||||||
val portId = port.portIndex
|
|
||||||
|
|
||||||
val lpa: LocalProfileAssistant =
|
val slotId: Int // PHYSICAL slot
|
||||||
LocalProfileAssistantImpl(apduInterface, HttpInterfaceImpl(verboseLoggingFlow))
|
val logicalSlotId: Int
|
||||||
|
val portId: Int
|
||||||
|
|
||||||
|
val lpa: LocalProfileAssistant
|
||||||
|
|
||||||
val valid: Boolean
|
val valid: Boolean
|
||||||
get() = lpa.valid
|
|
||||||
|
|
||||||
fun close() = lpa.close()
|
fun close()
|
||||||
}
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package im.angry.openeuicc.core
|
||||||
|
|
||||||
|
import im.angry.openeuicc.util.*
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import net.typeblog.lpac_jni.ApduInterface
|
||||||
|
import net.typeblog.lpac_jni.LocalProfileAssistant
|
||||||
|
import net.typeblog.lpac_jni.impl.HttpInterfaceImpl
|
||||||
|
import net.typeblog.lpac_jni.impl.LocalProfileAssistantImpl
|
||||||
|
|
||||||
|
class EuiccChannelImpl(
|
||||||
|
override val port: UiccPortInfoCompat,
|
||||||
|
apduInterface: ApduInterface,
|
||||||
|
verboseLoggingFlow: Flow<Boolean>
|
||||||
|
) : EuiccChannel {
|
||||||
|
override val slotId = port.card.physicalSlotIndex
|
||||||
|
override val logicalSlotId = port.logicalSlotIndex
|
||||||
|
override val portId = port.portIndex
|
||||||
|
|
||||||
|
override val lpa: LocalProfileAssistant =
|
||||||
|
LocalProfileAssistantImpl(apduInterface, HttpInterfaceImpl(verboseLoggingFlow))
|
||||||
|
|
||||||
|
override val valid: Boolean
|
||||||
|
get() = lpa.valid
|
||||||
|
|
||||||
|
override fun close() = lpa.close()
|
||||||
|
}
|
|
@ -64,6 +64,16 @@ interface EuiccChannelManager {
|
||||||
suspend fun findEuiccChannelByPort(physicalSlotId: Int, portId: Int): EuiccChannel?
|
suspend fun findEuiccChannelByPort(physicalSlotId: Int, portId: Int): EuiccChannel?
|
||||||
fun findEuiccChannelByPortBlocking(physicalSlotId: Int, portId: Int): EuiccChannel?
|
fun findEuiccChannelByPortBlocking(physicalSlotId: Int, portId: Int): EuiccChannel?
|
||||||
|
|
||||||
|
class EuiccChannelNotFoundException: Exception("EuiccChannel not found")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a EuiccChannel by its slot and port, then run a callback with a reference to it.
|
||||||
|
* The reference is not supposed to be held outside of the callback.
|
||||||
|
*
|
||||||
|
* If a channel for that slot / port is not found, EuiccChannelNotFoundException is thrown
|
||||||
|
*/
|
||||||
|
suspend fun <R> withEuiccChannel(physicalSlotId: Int, portId: Int, fn: (EuiccChannel) -> R): R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidate all EuiccChannels previously cached by this Manager
|
* Invalidate all EuiccChannels previously cached by this Manager
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -26,7 +26,7 @@ class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFacto
|
||||||
"Trying TelephonyManager for slot ${port.card.physicalSlotIndex} port ${port.portIndex}"
|
"Trying TelephonyManager for slot ${port.card.physicalSlotIndex} port ${port.portIndex}"
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
return EuiccChannel(
|
return EuiccChannelImpl(
|
||||||
port,
|
port,
|
||||||
TelephonyManagerApduInterface(
|
TelephonyManagerApduInterface(
|
||||||
port,
|
port,
|
||||||
|
|
Loading…
Add table
Reference in a new issue