浏览代码

refactor: Make EuiccChannel abstract

This allows wrapping to control reference lifetime outside of
EuiccChannelManager.
Peter Cai 1 年之前
父节点
当前提交
d54fcf2589

+ 2 - 2
app-common/src/main/java/im/angry/openeuicc/core/DefaultEuiccChannelFactory.kt

@@ -33,7 +33,7 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
 
         Log.i(DefaultEuiccChannelManager.TAG, "Trying OMAPI for physical slot ${port.card.physicalSlotIndex}")
         try {
-            return EuiccChannel(
+            return EuiccChannelImpl(
                 port,
                 OmapiApduInterface(
                     seService!!,
@@ -61,7 +61,7 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
         if (bulkIn == null || bulkOut == null) return null
         val conn = usbManager.openDevice(usbDevice) ?: return null
         if (!conn.claimInterface(usbInterface, true)) return null
-        return EuiccChannel(
+        return EuiccChannelImpl(
             FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
             UsbApduInterface(
                 conn,

+ 9 - 17
app-common/src/main/java/im/angry/openeuicc/core/EuiccChannel.kt

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

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

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

+ 1 - 1
app/src/main/java/im/angry/openeuicc/core/PrivilegedEuiccChannelFactory.kt

@@ -26,7 +26,7 @@ class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFacto
                 "Trying TelephonyManager for slot ${port.card.physicalSlotIndex} port ${port.portIndex}"
             )
             try {
-                return EuiccChannel(
+                return EuiccChannelImpl(
                     port,
                     TelephonyManagerApduInterface(
                         port,