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

Commit 7ca832f6 authored by septs's avatar septs Committed by Peter Cai
Browse files

fix: build failed (#271)

parent 7e1c4907
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
        const val TAG = "OpenEuiccService"
    }

    private val seId = EuiccChannel.SecureElementId.DEFAULT

    private val hasInternalEuicc by lazy {
        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,
     * 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 {
        val (binder, unbind) = runBlocking {
            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 {
        val portId = euiccChannelManager.findFirstAvailablePort(slotId)
        if (portId < 0) return@withEuiccChannelManager null
        euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
        euiccChannelManager.withEuiccChannel(slotId, portId, seId) { channel ->
            channel.lpa.eID
        }
    }
@@ -199,7 +199,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
            }

            return@withEuiccChannelManager try {
                euiccChannelManager.withEuiccChannel(slotId, port) { channel ->
                euiccChannelManager.withEuiccChannel(slotId, port, seId) { channel ->
                    val filteredProfiles =
                        if (preferenceRepository.unfilteredProfileListFlow.first())
                            channel.lpa.profiles
@@ -232,7 +232,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
                        channel.port.card.isRemovable
                    )
                }
            } catch (e: EuiccChannelManager.EuiccChannelNotFoundException) {
            } catch (_: EuiccChannelManager.EuiccChannelNotFoundException) {
                GetEuiccProfileInfoListResult(
                    RESULT_FIRST_USER,
                    arrayOf(),
@@ -254,7 +254,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {

        // Check that the profile has been disabled on all slots
        val enabledAnywhere = ports.any { port ->
            euiccChannelManager.withEuiccChannel(slotId, port) { channel ->
            euiccChannelManager.withEuiccChannel(slotId, port, seId) { channel ->
                channel.lpa.profiles.enabled?.iccid == iccid
            }
        }
@@ -316,7 +316,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
                    Pair(slotId, port)
                } else {
                    // Else, check until the indicated port is available
                    euiccChannelManager.withEuiccChannel(slotId, portIndex) { channel ->
                    euiccChannelManager.withEuiccChannel(slotId, portIndex, seId) { channel ->
                        if (!channel.valid) {
                            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
                retryWithTimeout(5000) {
                    euiccChannelManager.withEuiccChannel(slotId, foundPortId) { channel ->
                    euiccChannelManager.withEuiccChannel(slotId, foundPortId, seId) { channel ->
                        if (!channel.valid) {
                            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) {
                // iccid == null means disabling
                val foundIccid =
                    euiccChannelManager.withEuiccChannel(foundSlotId, foundPortId) { channel ->
                    euiccChannelManager.withEuiccChannel(foundSlotId, foundPortId, seId) { channel ->
                        channel.lpa.profiles.enabled?.iccid
                    } ?: return@withEuiccChannelManager RESULT_FIRST_USER
                Pair(foundIccid, false)
@@ -386,7 +386,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
            if (res != null) return@withEuiccChannelManager RESULT_FIRST_USER

            return@withEuiccChannelManager RESULT_OK
        } catch (e: Exception) {
        } catch (_: Exception) {
            return@withEuiccChannelManager RESULT_FIRST_USER
        } finally {
            euiccChannelManager.invalidate()
@@ -416,7 +416,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
                )
                    .waitDone()) == null

            euiccChannelManager.withEuiccChannel(slotId, port) { channel ->
            euiccChannelManager.withEuiccChannel(slotId, port, seId) { channel ->
                appContainer.subscriptionManager.tryRefreshCachedEuiccInfo(channel.cardId)
            }
            return@withEuiccChannelManager if (success) {
+7 −7
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ import im.angry.openeuicc.core.EuiccChannelManager
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.runBlocking

private val seId = EuiccChannel.SecureElementId.DEFAULT

val TelephonyManager.supportsDSDS: Boolean
    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)
    runBlocking {
        euiccManager.flowInternalEuiccPorts().onEach { (slotId, portId) ->
            euiccManager.withEuiccChannel(slotId, portId) {
            euiccManager.withEuiccChannel(slotId, portId, seId) {
                if (!it.port.card.isRemovable) {
                    it.lpa.disableActiveProfile(false)
                }
@@ -32,7 +34,8 @@ fun TelephonyManager.setDsdsEnabled(euiccManager: EuiccChannelManager, enabled:
// Disable eSIM profiles before switching the slot mapping
// This ensures that unmapped eSIM ports never have "ghost" profiles enabled
suspend fun TelephonyManager.updateSimSlotMapping(
    euiccManager: EuiccChannelManager, newMapping: Collection<UiccSlotMapping>,
    euiccManager: EuiccChannelManager,
    newMapping: Collection<UiccSlotMapping>,
    currentMapping: Collection<UiccSlotMapping> = simSlotMapping
) {
    val unmapped = currentMapping.filterNot { mapping ->
@@ -43,7 +46,7 @@ suspend fun TelephonyManager.updateSimSlotMapping(
    }

    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) {
                channel.lpa.disableActiveProfileKeepIccId(false)
            } else {
@@ -54,10 +57,7 @@ suspend fun TelephonyManager.updateSimSlotMapping(
        }?.let { iccid ->
            // 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)
                }
            }