Browse Source

fix: build failed (#271)

Reviewed-on: https://gitea.angry.im/PeterCxy/OpenEUICC/pulls/271
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
septs 2 months ago
parent
commit
7ca832f68e

+ 14 - 14
app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt

@@ -33,6 +33,8 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
         const val TAG = "OpenEuiccService"
         const val TAG = "OpenEuiccService"
     }
     }
 
 
+    private val seId = EuiccChannel.SecureElementId.DEFAULT
+
     private val hasInternalEuicc by lazy {
     private val hasInternalEuicc by lazy {
         telephonyManager.uiccCardsInfoCompat.any { it.isEuicc && !it.isRemovable }
         telephonyManager.uiccCardsInfoCompat.any { it.isEuicc && !it.isRemovable }
     }
     }
@@ -63,15 +65,13 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
      * This ensures that we only spawn and connect to APDU channels when we absolutely need to,
      * This ensures that we only spawn and connect to APDU channels when we absolutely need to,
      * instead of keeping them open unnecessarily in the background at all times.
      * instead of keeping them open unnecessarily in the background at all times.
      *
      *
-     * This function cannot be inline because non-local returns may bypass the unbind
+     * This function cannot be inline because non-local returns may bypass to unbind
      */
      */
     private fun <T> withEuiccChannelManager(fn: suspend EuiccChannelManagerContext.() -> T): T {
     private fun <T> withEuiccChannelManager(fn: suspend EuiccChannelManagerContext.() -> T): T {
         val (binder, unbind) = runBlocking {
         val (binder, unbind) = runBlocking {
             bindServiceSuspended(
             bindServiceSuspended(
-                Intent(
-                    this@OpenEuiccService,
-                    EuiccChannelManagerService::class.java
-                ), BIND_AUTO_CREATE
+                Intent(this@OpenEuiccService, EuiccChannelManagerService::class.java),
+                BIND_AUTO_CREATE
             )
             )
         }
         }
 
 
@@ -92,7 +92,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
     override fun onGetEid(slotId: Int): String? = withEuiccChannelManager {
     override fun onGetEid(slotId: Int): String? = withEuiccChannelManager {
         val portId = euiccChannelManager.findFirstAvailablePort(slotId)
         val portId = euiccChannelManager.findFirstAvailablePort(slotId)
         if (portId < 0) return@withEuiccChannelManager null
         if (portId < 0) return@withEuiccChannelManager null
-        euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
+        euiccChannelManager.withEuiccChannel(slotId, portId, seId) { channel ->
             channel.lpa.eID
             channel.lpa.eID
         }
         }
     }
     }
@@ -199,7 +199,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
             }
             }
 
 
             return@withEuiccChannelManager try {
             return@withEuiccChannelManager try {
-                euiccChannelManager.withEuiccChannel(slotId, port) { channel ->
+                euiccChannelManager.withEuiccChannel(slotId, port, seId) { channel ->
                     val filteredProfiles =
                     val filteredProfiles =
                         if (preferenceRepository.unfilteredProfileListFlow.first())
                         if (preferenceRepository.unfilteredProfileListFlow.first())
                             channel.lpa.profiles
                             channel.lpa.profiles
@@ -232,7 +232,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
                         channel.port.card.isRemovable
                         channel.port.card.isRemovable
                     )
                     )
                 }
                 }
-            } catch (e: EuiccChannelManager.EuiccChannelNotFoundException) {
+            } catch (_: EuiccChannelManager.EuiccChannelNotFoundException) {
                 GetEuiccProfileInfoListResult(
                 GetEuiccProfileInfoListResult(
                     RESULT_FIRST_USER,
                     RESULT_FIRST_USER,
                     arrayOf(),
                     arrayOf(),
@@ -254,7 +254,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
 
 
         // Check that the profile has been disabled on all slots
         // Check that the profile has been disabled on all slots
         val enabledAnywhere = ports.any { port ->
         val enabledAnywhere = ports.any { port ->
-            euiccChannelManager.withEuiccChannel(slotId, port) { channel ->
+            euiccChannelManager.withEuiccChannel(slotId, port, seId) { channel ->
                 channel.lpa.profiles.enabled?.iccid == iccid
                 channel.lpa.profiles.enabled?.iccid == iccid
             }
             }
         }
         }
@@ -316,7 +316,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
                     Pair(slotId, port)
                     Pair(slotId, port)
                 } else {
                 } else {
                     // Else, check until the indicated port is available
                     // Else, check until the indicated port is available
-                    euiccChannelManager.withEuiccChannel(slotId, portIndex) { channel ->
+                    euiccChannelManager.withEuiccChannel(slotId, portIndex, seId) { channel ->
                         if (!channel.valid) {
                         if (!channel.valid) {
                             throw IllegalStateException("Indicated slot / port combination is unavailable; may need to try again")
                             throw IllegalStateException("Indicated slot / port combination is unavailable; may need to try again")
                         }
                         }
@@ -350,7 +350,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
 
 
                 // Wait for availability again
                 // Wait for availability again
                 retryWithTimeout(5000) {
                 retryWithTimeout(5000) {
-                    euiccChannelManager.withEuiccChannel(slotId, foundPortId) { channel ->
+                    euiccChannelManager.withEuiccChannel(slotId, foundPortId, seId) { channel ->
                         if (!channel.valid) {
                         if (!channel.valid) {
                             throw IllegalStateException("Indicated slot / port combination is unavailable; may need to try again")
                             throw IllegalStateException("Indicated slot / port combination is unavailable; may need to try again")
                         }
                         }
@@ -366,7 +366,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
             val (foundIccid, enable) = if (iccid == null) {
             val (foundIccid, enable) = if (iccid == null) {
                 // iccid == null means disabling
                 // iccid == null means disabling
                 val foundIccid =
                 val foundIccid =
-                    euiccChannelManager.withEuiccChannel(foundSlotId, foundPortId) { channel ->
+                    euiccChannelManager.withEuiccChannel(foundSlotId, foundPortId, seId) { channel ->
                         channel.lpa.profiles.enabled?.iccid
                         channel.lpa.profiles.enabled?.iccid
                     } ?: return@withEuiccChannelManager RESULT_FIRST_USER
                     } ?: return@withEuiccChannelManager RESULT_FIRST_USER
                 Pair(foundIccid, false)
                 Pair(foundIccid, false)
@@ -386,7 +386,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
             if (res != null) return@withEuiccChannelManager RESULT_FIRST_USER
             if (res != null) return@withEuiccChannelManager RESULT_FIRST_USER
 
 
             return@withEuiccChannelManager RESULT_OK
             return@withEuiccChannelManager RESULT_OK
-        } catch (e: Exception) {
+        } catch (_: Exception) {
             return@withEuiccChannelManager RESULT_FIRST_USER
             return@withEuiccChannelManager RESULT_FIRST_USER
         } finally {
         } finally {
             euiccChannelManager.invalidate()
             euiccChannelManager.invalidate()
@@ -416,7 +416,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
                 )
                 )
                     .waitDone()) == null
                     .waitDone()) == null
 
 
-            euiccChannelManager.withEuiccChannel(slotId, port) { channel ->
+            euiccChannelManager.withEuiccChannel(slotId, port, seId) { channel ->
                 appContainer.subscriptionManager.tryRefreshCachedEuiccInfo(channel.cardId)
                 appContainer.subscriptionManager.tryRefreshCachedEuiccInfo(channel.cardId)
             }
             }
             return@withEuiccChannelManager if (success) {
             return@withEuiccChannelManager if (success) {

+ 7 - 7
app/src/main/java/im/angry/openeuicc/util/PrivilegedTelephonyUtils.kt

@@ -8,6 +8,8 @@ import im.angry.openeuicc.core.EuiccChannelManager
 import kotlinx.coroutines.flow.onEach
 import kotlinx.coroutines.flow.onEach
 import kotlinx.coroutines.runBlocking
 import kotlinx.coroutines.runBlocking
 
 
+private val seId = EuiccChannel.SecureElementId.DEFAULT
+
 val TelephonyManager.supportsDSDS: Boolean
 val TelephonyManager.supportsDSDS: Boolean
     get() = supportedModemCount == 2
     get() = supportedModemCount == 2
 
 
@@ -18,7 +20,7 @@ fun TelephonyManager.setDsdsEnabled(euiccManager: EuiccChannelManager, enabled:
     // Disable all eSIM profiles before performing a DSDS switch (only for internal eSIMs)
     // Disable all eSIM profiles before performing a DSDS switch (only for internal eSIMs)
     runBlocking {
     runBlocking {
         euiccManager.flowInternalEuiccPorts().onEach { (slotId, portId) ->
         euiccManager.flowInternalEuiccPorts().onEach { (slotId, portId) ->
-            euiccManager.withEuiccChannel(slotId, portId) {
+            euiccManager.withEuiccChannel(slotId, portId, seId) {
                 if (!it.port.card.isRemovable) {
                 if (!it.port.card.isRemovable) {
                     it.lpa.disableActiveProfile(false)
                     it.lpa.disableActiveProfile(false)
                 }
                 }
@@ -32,7 +34,8 @@ fun TelephonyManager.setDsdsEnabled(euiccManager: EuiccChannelManager, enabled:
 // Disable eSIM profiles before switching the slot mapping
 // Disable eSIM profiles before switching the slot mapping
 // This ensures that unmapped eSIM ports never have "ghost" profiles enabled
 // This ensures that unmapped eSIM ports never have "ghost" profiles enabled
 suspend fun TelephonyManager.updateSimSlotMapping(
 suspend fun TelephonyManager.updateSimSlotMapping(
-    euiccManager: EuiccChannelManager, newMapping: Collection<UiccSlotMapping>,
+    euiccManager: EuiccChannelManager,
+    newMapping: Collection<UiccSlotMapping>,
     currentMapping: Collection<UiccSlotMapping> = simSlotMapping
     currentMapping: Collection<UiccSlotMapping> = simSlotMapping
 ) {
 ) {
     val unmapped = currentMapping.filterNot { mapping ->
     val unmapped = currentMapping.filterNot { mapping ->
@@ -43,7 +46,7 @@ suspend fun TelephonyManager.updateSimSlotMapping(
     }
     }
 
 
     val undo: List<suspend () -> Unit> = unmapped.mapNotNull { mapping ->
     val undo: List<suspend () -> Unit> = unmapped.mapNotNull { mapping ->
-        euiccManager.withEuiccChannel(mapping.physicalSlotIndex, mapping.portIndex) { channel ->
+        euiccManager.withEuiccChannel(mapping.physicalSlotIndex, mapping.portIndex, seId) { channel ->
             if (!channel.port.card.isRemovable) {
             if (!channel.port.card.isRemovable) {
                 channel.lpa.disableActiveProfileKeepIccId(false)
                 channel.lpa.disableActiveProfileKeepIccId(false)
             } else {
             } else {
@@ -54,10 +57,7 @@ suspend fun TelephonyManager.updateSimSlotMapping(
         }?.let { iccid ->
         }?.let { iccid ->
             // Generate undo closure because we can't keep reference to `channel` in the closure above
             // Generate undo closure because we can't keep reference to `channel` in the closure above
             {
             {
-                euiccManager.withEuiccChannel(
-                    mapping.physicalSlotIndex,
-                    mapping.portIndex
-                ) { channel ->
+                euiccManager.withEuiccChannel(mapping.physicalSlotIndex, mapping.portIndex, seId) { channel ->
                     channel.lpa.enableProfile(iccid)
                     channel.lpa.enableProfile(iccid)
                 }
                 }
             }
             }