Compare commits

...

1 commit

Author SHA1 Message Date
678a4e70ab
feat: integrate es10x MSS flow into channel implementations 2025-08-11 10:56:45 +08:00
4 changed files with 50 additions and 53 deletions

View file

@ -21,7 +21,7 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
override suspend fun tryOpenEuiccChannel( override suspend fun tryOpenEuiccChannel(
port: UiccPortInfoCompat, port: UiccPortInfoCompat,
isdrAid: ByteArray isdrAid: ByteArray
): EuiccChannel? { ): EuiccChannel? = try {
if (port.portIndex != 0) { if (port.portIndex != 0) {
Log.w( Log.w(
DefaultEuiccChannelManager.TAG, DefaultEuiccChannelManager.TAG,
@ -35,7 +35,6 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
DefaultEuiccChannelManager.TAG, DefaultEuiccChannelManager.TAG,
"Trying OMAPI for physical slot ${port.card.physicalSlotIndex}" "Trying OMAPI for physical slot ${port.card.physicalSlotIndex}"
) )
return try {
EuiccChannelImpl( EuiccChannelImpl(
context.getString(R.string.channel_type_omapi), context.getString(R.string.channel_type_omapi),
port, port,
@ -48,6 +47,7 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
isdrAid, isdrAid,
context.preferenceRepository.verboseLoggingFlow, context.preferenceRepository.verboseLoggingFlow,
context.preferenceRepository.ignoreTLSCertificateFlow, context.preferenceRepository.ignoreTLSCertificateFlow,
context.preferenceRepository.es10xMssFlow,
) )
} catch (_: IllegalArgumentException) { } catch (_: IllegalArgumentException) {
// Failed // Failed
@ -57,14 +57,12 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
) )
null null
} }
}
override fun tryOpenUsbEuiccChannel( override fun tryOpenUsbEuiccChannel(
ccidCtx: UsbCcidContext, ccidCtx: UsbCcidContext,
isdrAid: ByteArray isdrAid: ByteArray
): EuiccChannel? { ): EuiccChannel? = try {
try { EuiccChannelImpl(
return EuiccChannelImpl(
context.getString(R.string.channel_type_usb), context.getString(R.string.channel_type_usb),
FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)), FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
intrinsicChannelName = ccidCtx.productName, intrinsicChannelName = ccidCtx.productName,
@ -74,6 +72,7 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
isdrAid, isdrAid,
context.preferenceRepository.verboseLoggingFlow, context.preferenceRepository.verboseLoggingFlow,
context.preferenceRepository.ignoreTLSCertificateFlow, context.preferenceRepository.ignoreTLSCertificateFlow,
context.preferenceRepository.es10xMssFlow,
) )
} catch (_: IllegalArgumentException) { } catch (_: IllegalArgumentException) {
// Failed // Failed
@ -81,8 +80,7 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
DefaultEuiccChannelManager.TAG, DefaultEuiccChannelManager.TAG,
"USB APDU interface unavailable for ISD-R AID: ${isdrAid.encodeHex()}." "USB APDU interface unavailable for ISD-R AID: ${isdrAid.encodeHex()}."
) )
} null
return null
} }
override fun cleanup() { override fun cleanup() {

View file

@ -99,12 +99,6 @@ open class DefaultEuiccChannelManager(
val channel = val channel =
tryOpenChannelFirstValidAid { euiccChannelFactory.tryOpenEuiccChannel(port, it) } tryOpenChannelFirstValidAid { euiccChannelFactory.tryOpenEuiccChannel(port, it) }
if (channel != null) {
val mss = context.preferenceRepository.es10xMssFlow.first()
Log.i(TAG, "Set ${channel.type} channel, ES10x MSS to $mss")
channel.lpa.setEs10xMss(mss.toByte())
}
if (channel != null) { if (channel != null) {
channelCache.add(channel) channelCache.add(channel)
return channel return channel

View file

@ -1,8 +1,9 @@
package im.angry.openeuicc.core package im.angry.openeuicc.core
import im.angry.openeuicc.util.UiccPortInfoCompat import im.angry.openeuicc.util.UiccPortInfoCompat
import im.angry.openeuicc.util.decodeHex
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import net.typeblog.lpac_jni.ApduInterface 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.HttpInterfaceImpl
@ -15,7 +16,8 @@ class EuiccChannelImpl(
override val apduInterface: ApduInterface, override val apduInterface: ApduInterface,
override val isdrAid: ByteArray, override val isdrAid: ByteArray,
verboseLoggingFlow: Flow<Boolean>, verboseLoggingFlow: Flow<Boolean>,
ignoreTLSCertificateFlow: Flow<Boolean> ignoreTLSCertificateFlow: Flow<Boolean>,
es10xMssFlow: Flow<Int>,
) : EuiccChannel { ) : EuiccChannel {
override val slotId = port.card.physicalSlotIndex override val slotId = port.card.physicalSlotIndex
override val logicalSlotId = port.logicalSlotIndex override val logicalSlotId = port.logicalSlotIndex
@ -25,8 +27,10 @@ class EuiccChannelImpl(
LocalProfileAssistantImpl( LocalProfileAssistantImpl(
isdrAid, isdrAid,
apduInterface, apduInterface,
HttpInterfaceImpl(verboseLoggingFlow, ignoreTLSCertificateFlow) HttpInterfaceImpl(verboseLoggingFlow, ignoreTLSCertificateFlow),
) ).also {
it.setEs10xMss(runBlocking { es10xMssFlow.first().toByte() })
}
override val atr: ByteArray? override val atr: ByteArray?
get() = (apduInterface as? ApduInterfaceAtrProvider)?.atr get() = (apduInterface as? ApduInterfaceAtrProvider)?.atr

View file

@ -42,6 +42,7 @@ class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFacto
isdrAid, isdrAid,
context.preferenceRepository.verboseLoggingFlow, context.preferenceRepository.verboseLoggingFlow,
context.preferenceRepository.ignoreTLSCertificateFlow, context.preferenceRepository.ignoreTLSCertificateFlow,
context.preferenceRepository.es10xMssFlow,
) )
} catch (_: IllegalArgumentException) { } catch (_: IllegalArgumentException) {
// Failed // Failed