Browse Source

refactor: Pass multi-SE metadata inside EuiccChannel so it can be shown in MainActivity

Peter Cai 1 month ago
parent
commit
f498c22ad8

+ 4 - 0
app-common/src/main/java/im/angry/openeuicc/core/DefaultEuiccChannelManager.kt

@@ -109,6 +109,10 @@ open class DefaultEuiccChannelManager(
             break
             break
         }
         }
 
 
+        // Set the hasMultipleSE field now since we only get to know that after we have iterated all AIDs
+        // This also flips a flag in EuiccChannelImpl and prevents the field from being set again
+        ret.forEach { it.hasMultipleSE = (seId > 1) }
+
         return ret
         return ret
     }
     }
 
 

+ 8 - 0
app-common/src/main/java/im/angry/openeuicc/core/EuiccChannel.kt

@@ -68,6 +68,14 @@ interface EuiccChannel {
      */
      */
     val seId: SecureElementId
     val seId: SecureElementId
 
 
+    /**
+     * Does this channel belong to a chip that supports multiple SEs?
+     * Note that this is only made `var` to make initialization a bit less annoying --
+     * this should never be set again after the channel is originally opened.
+     * Attempting to do so will yield an exception.
+     */
+    var hasMultipleSE: Boolean
+
     val lpa: LocalProfileAssistant
     val lpa: LocalProfileAssistant
 
 
     val valid: Boolean
     val valid: Boolean

+ 11 - 0
app-common/src/main/java/im/angry/openeuicc/core/EuiccChannelImpl.kt

@@ -39,5 +39,16 @@ class EuiccChannelImpl(
     override val valid: Boolean
     override val valid: Boolean
         get() = lpa.valid
         get() = lpa.valid
 
 
+    private var hasMultipleSEInitialized = false
+
+    override var hasMultipleSE: Boolean = false
+        set(value) {
+            if (hasMultipleSEInitialized) {
+                throw IllegalStateException("already initialized")
+            }
+
+            field = value
+        }
+
     override fun close() = lpa.close()
     override fun close() = lpa.close()
 }
 }

+ 5 - 0
app-common/src/main/java/im/angry/openeuicc/core/EuiccChannelWrapper.kt

@@ -42,6 +42,11 @@ class EuiccChannelWrapper(orig: EuiccChannel) : EuiccChannel {
         get() = channel.atr
         get() = channel.atr
     override val isdrAid: ByteArray
     override val isdrAid: ByteArray
         get() = channel.isdrAid
         get() = channel.isdrAid
+    override var hasMultipleSE: Boolean
+        get() = channel.hasMultipleSE
+        set(value) {
+            channel.hasMultipleSE = value
+        }
 
 
     override fun close() = channel.close()
     override fun close() = channel.close()
 
 

+ 7 - 1
app-common/src/main/java/im/angry/openeuicc/ui/MainActivity.kt

@@ -166,8 +166,14 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
                     // but it could change in the future
                     // but it could change in the future
                     euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
                     euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
 
 
-                    val channelName =
+                    val channelName = if (channel.hasMultipleSE) {
+                        appContainer.customizableTextProvider.formatNonUsbChannelNameWithSeId(
+                            channel.logicalSlotId,
+                            channel.seId
+                        )
+                    } else {
                         appContainer.customizableTextProvider.formatNonUsbChannelName(channel.logicalSlotId)
                         appContainer.customizableTextProvider.formatNonUsbChannelName(channel.logicalSlotId)
+                    }
                     newPages.add(Page(channel.logicalSlotId, channelName) {
                     newPages.add(Page(channel.logicalSlotId, channelName) {
                         appContainer.uiComponentFactory.createEuiccManagementFragment(
                         appContainer.uiComponentFactory.createEuiccManagementFragment(
                             slotId,
                             slotId,

+ 2 - 4
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardSlotSelectFragment.kt

@@ -20,7 +20,6 @@ import im.angry.openeuicc.util.enabled
 import im.angry.openeuicc.util.ensureEuiccChannelManager
 import im.angry.openeuicc.util.ensureEuiccChannelManager
 import im.angry.openeuicc.util.euiccChannelManager
 import im.angry.openeuicc.util.euiccChannelManager
 import im.angry.openeuicc.util.formatFreeSpace
 import im.angry.openeuicc.util.formatFreeSpace
-import kotlinx.coroutines.flow.asFlow
 import kotlinx.coroutines.flow.flatMapConcat
 import kotlinx.coroutines.flow.flatMapConcat
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.toList
 import kotlinx.coroutines.flow.toList
@@ -100,14 +99,13 @@ class DownloadWizardSlotSelectFragment : DownloadWizardActivity.DownloadWizardSt
         ensureEuiccChannelManager()
         ensureEuiccChannelManager()
         showProgressBar(-1)
         showProgressBar(-1)
         val slots = euiccChannelManager.flowAllOpenEuiccPorts().flatMapConcat { (slotId, portId) ->
         val slots = euiccChannelManager.flowAllOpenEuiccPorts().flatMapConcat { (slotId, portId) ->
-            val ses = euiccChannelManager.flowEuiccSecureElements(slotId, portId).toList()
-            ses.asFlow().map { seId ->
+            euiccChannelManager.flowEuiccSecureElements(slotId, portId).map { seId ->
                 euiccChannelManager.withEuiccChannel(slotId, portId, seId) { channel ->
                 euiccChannelManager.withEuiccChannel(slotId, portId, seId) { channel ->
                     SlotInfo(
                     SlotInfo(
                         channel.logicalSlotId,
                         channel.logicalSlotId,
                         channel.port.card.isRemovable,
                         channel.port.card.isRemovable,
                         channel.port.card.ports.size > 1,
                         channel.port.card.ports.size > 1,
-                        ses.size > 1,
+                        channel.hasMultipleSE,
                         channel.portId,
                         channel.portId,
                         channel.seId,
                         channel.seId,
                         channel.lpa.eID,
                         channel.lpa.eID,