Compare commits

..

No commits in common. "d54fcf2589c4e94dc041b4d5d857a56a8e7dbd80" and "65c9a7dc39bc88e23c9a6b8b4c7bd6091f30f5ac" have entirely different histories.

6 changed files with 20 additions and 58 deletions

View file

@ -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 EuiccChannelImpl( return EuiccChannel(
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 EuiccChannelImpl( return EuiccChannel(
FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)), FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
UsbApduInterface( UsbApduInterface(
conn, conn,

View file

@ -159,16 +159,6 @@ 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

View file

@ -1,18 +1,26 @@
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
interface EuiccChannel { class 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 slotId: Int // PHYSICAL slot val lpa: LocalProfileAssistant =
val logicalSlotId: Int LocalProfileAssistantImpl(apduInterface, HttpInterfaceImpl(verboseLoggingFlow))
val portId: Int
val lpa: LocalProfileAssistant
val valid: Boolean val valid: Boolean
get() = lpa.valid
fun close() fun close() = lpa.close()
} }

View file

@ -1,26 +0,0 @@
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()
}

View file

@ -64,16 +64,6 @@ 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
*/ */

View file

@ -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 EuiccChannelImpl( return EuiccChannel(
port, port,
TelephonyManagerApduInterface( TelephonyManagerApduInterface(
port, port,