Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 713ffec2 authored by Peter Cai's avatar Peter Cai
Browse files

feat: multi-SE support for USB channels (#309)

All channels now support multi-SE. UsbCcidReaderFragment now no longer wraps inner EuiccManagementFragment's but instead calls MainActivity to instantiate tabs for USB channels. Also, we now no longer use the USB product name as channel titles but instead use "USB Reader" and "USB Reader, SE x" for all of them.

Reviewed-on: https://gitea.angry.im/PeterCxy/OpenEUICC/pulls/309


Reviewed-by: default avatarsepts <github@septs.pw>
parent c676c273
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
<component name="ProjectCodeStyleConfiguration">
  <code_scheme name="Project" version="173">
    <JavaCodeStyleSettings>
      <option name="IMPORT_LAYOUT_TABLE">
        <value>
          <package name="android" withSubpackages="true" static="true" />
          <package name="androidx" withSubpackages="true" static="true" />
          <package name="com" withSubpackages="true" static="true" />
          <package name="junit" withSubpackages="true" static="true" />
          <package name="net" withSubpackages="true" static="true" />
          <package name="org" withSubpackages="true" static="true" />
          <package name="java" withSubpackages="true" static="true" />
          <package name="javax" withSubpackages="true" static="true" />
          <package name="" withSubpackages="true" static="true" />
          <emptyLine />
          <package name="android" withSubpackages="true" static="false" />
          <emptyLine />
          <package name="androidx" withSubpackages="true" static="false" />
          <emptyLine />
          <package name="com" withSubpackages="true" static="false" />
          <emptyLine />
          <package name="junit" withSubpackages="true" static="false" />
          <emptyLine />
          <package name="net" withSubpackages="true" static="false" />
          <emptyLine />
          <package name="org" withSubpackages="true" static="false" />
          <emptyLine />
          <package name="java" withSubpackages="true" static="false" />
          <emptyLine />
          <package name="javax" withSubpackages="true" static="false" />
          <emptyLine />
          <package name="" withSubpackages="true" static="false" />
          <emptyLine />
        </value>
      </option>
    </JavaCodeStyleSettings>
    <JetCodeStyleSettings>
      <option name="PACKAGES_TO_USE_STAR_IMPORTS">
        <value>
+0 −2
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
        EuiccChannelImpl(
            context.getString(R.string.channel_type_omapi),
            port,
            intrinsicChannelName = null,
            OmapiApduInterface(
                seService!!,
                port,
@@ -67,7 +66,6 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
        EuiccChannelImpl(
            context.getString(R.string.channel_type_usb),
            FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
            intrinsicChannelName = ccidCtx.productName,
            UsbApduInterface(
                ccidCtx
            ),
+6 −9
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ open class DefaultEuiccChannelManager(
        get() = (0..<tm.activeModemCountCompat).map { FakeUiccCardInfoCompat(it) }

    private suspend inline fun tryOpenChannelWithKnownAids(
        supportsMultiSE: Boolean,
        openFn: (ByteArray, EuiccChannel.SecureElementId) -> EuiccChannel?
    ): List<EuiccChannel> {
        var isdrAidList =
@@ -100,10 +99,9 @@ open class DefaultEuiccChannelManager(
                    ret.add(channel)
                    openedAids.add(aid)

                    // Don't try opening more than 1 channel unless we support multi SE or
                    // there is a vendor implementation for deciding when we should stop
                    // opening more channels
                    if (!supportsMultiSE || vendorDecider == null) {
                    // Don't try opening more than 1 channel unless there is a vendor
                    // implementation for deciding when we should stop opening more channels
                    if (vendorDecider == null) {
                        break@outer
                    }
                }
@@ -149,9 +147,9 @@ open class DefaultEuiccChannelManager(
                return null
            }

            // This function is not responsible for managing USB channels (see the initial check), so supportsMultiSE is true.
            // This function is not responsible for managing USB channels (see the initial check)
            val channels =
                tryOpenChannelWithKnownAids(supportsMultiSE = true) { isdrAid, seId ->
                tryOpenChannelWithKnownAids { isdrAid, seId ->
                    euiccChannelFactory.tryOpenEuiccChannel(
                        port,
                        isdrAid,
@@ -379,8 +377,7 @@ open class DefaultEuiccChannelManager(
                    UsbCcidContext.createFromUsbDevice(context, device, iface) ?: return@forEach

                try {
                    // TODO: We should also support multiple SEs over USB readers (the code here already does, UI doesn't yet)
                    val channels = tryOpenChannelWithKnownAids(supportsMultiSE = false) { isdrAid, seId ->
                    val channels = tryOpenChannelWithKnownAids { isdrAid, seId ->
                        euiccChannelFactory.tryOpenUsbEuiccChannel(ccidCtx, isdrAid, seId)
                    }
                    if (channels.isNotEmpty() && channels[0].valid) {
+0 −7
Original line number Diff line number Diff line
@@ -85,13 +85,6 @@ interface EuiccChannel {
     */
    val atr: ByteArray?

    /**
     * Intrinsic name of this channel. For device-internal SIM slots,
     * this should be null; for USB readers, this should be the name of
     * the reader device.
     */
    val intrinsicChannelName: String?

    /**
     * The underlying APDU interface for this channel
     */
+0 −1
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ import net.typeblog.lpac_jni.impl.LocalProfileAssistantImpl
class EuiccChannelImpl(
    override val type: String,
    override val port: UiccPortInfoCompat,
    override val intrinsicChannelName: String?,
    override val apduInterface: ApduInterface,
    override val isdrAid: ByteArray,
    override val seId: EuiccChannel.SecureElementId,
Loading