Compare commits

...

1 commit

Author SHA1 Message Date
e31200d142
fix: usb isd-r aid fallback 2025-04-01 21:18:20 +08:00
4 changed files with 31 additions and 29 deletions

View file

@ -60,7 +60,7 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
Log.i(DefaultEuiccChannelManager.TAG, "Is OMAPI channel, setting MSS to 60") Log.i(DefaultEuiccChannelManager.TAG, "Is OMAPI channel, setting MSS to 60")
it.lpa.setEs10xMss(60) it.lpa.setEs10xMss(60)
} }
} catch (e: IllegalArgumentException) { } catch (_: IllegalArgumentException) {
// Failed // Failed
Log.w( Log.w(
DefaultEuiccChannelManager.TAG, DefaultEuiccChannelManager.TAG,
@ -80,6 +80,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
try {
return EuiccChannelImpl( return EuiccChannelImpl(
context.getString(R.string.usb), context.getString(R.string.usb),
FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)), FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
@ -94,6 +95,14 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
context.preferenceRepository.verboseLoggingFlow, context.preferenceRepository.verboseLoggingFlow,
context.preferenceRepository.ignoreTLSCertificateFlow, context.preferenceRepository.ignoreTLSCertificateFlow,
) )
} catch (_: IllegalArgumentException) {
// Failed
Log.w(
DefaultEuiccChannelManager.TAG,
"USB APDU interface unavailable for ${usbDevice.vendorId}:${usbDevice.productId}."
)
}
return null
} }
override fun cleanup() { override fun cleanup() {

View file

@ -277,11 +277,7 @@ open class DefaultEuiccChannelManager(
) )
try { try {
val channel = tryOpenChannelFirstValidAid { val channel = tryOpenChannelFirstValidAid {
euiccChannelFactory.tryOpenUsbEuiccChannel( euiccChannelFactory.tryOpenUsbEuiccChannel(device, iface, it)
device,
iface,
it
)
} }
if (channel != null && channel.lpa.valid) { if (channel != null && channel.lpa.valid) {
usbChannel = channel usbChannel = channel

View file

@ -53,7 +53,7 @@ class UsbApduInterface(
"A9088100820101830107".decodeHex(), "A9088100820101830107".decodeHex(),
le = null, le = null,
) )
transmitApduByChannel(terminalCapabilities, 0,) transmitApduByChannel(terminalCapabilities, 0)
} }
override fun disconnect() { override fun disconnect() {

View file

@ -34,15 +34,12 @@ fun formatFreeSpace(size: Int): String =
* If none is found, at least EUICC_DEFAULT_ISDR_AID is returned * If none is found, at least EUICC_DEFAULT_ISDR_AID is returned
*/ */
fun parseIsdrAidList(s: String): List<ByteArray> = fun parseIsdrAidList(s: String): List<ByteArray> =
s.split('\n').map(String::trim).filter { !it.startsWith('#') } s.split('\n')
.map(String::trim) .map(String::trim)
.mapNotNull { .filter { !it.startsWith('#') }
try { .map(String::trim)
it.decodeHex() .filter(String::isNotEmpty)
} catch (_: IllegalArgumentException) { .mapNotNull { runCatching(it::decodeHex).getOrNull() }
null
}
}
.ifEmpty { listOf(EUICC_DEFAULT_ISDR_AID.decodeHex()) } .ifEmpty { listOf(EUICC_DEFAULT_ISDR_AID.decodeHex()) }
fun String.prettyPrintJson(): String { fun String.prettyPrintJson(): String {