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

Commit 6e5bbc40 authored by septs's avatar septs Committed by Peter Cai
Browse files

fix: privileged channel manager, close all channels (#270)

parent 709a9623
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -5,10 +5,7 @@ import im.angry.openeuicc.di.AppContainer
import im.angry.openeuicc.util.*
import java.lang.Exception

class PrivilegedEuiccChannelManager(
    appContainer: AppContainer,
    context: Context
) :
class PrivilegedEuiccChannelManager(appContainer: AppContainer, context: Context) :
    DefaultEuiccChannelManager(appContainer, context) {
    override val uiccCards: Collection<UiccCardInfoCompat>
        get() = tm.uiccCardsInfoCompat
@@ -17,10 +14,15 @@ class PrivilegedEuiccChannelManager(
    // due to a (potentially) forced restart
    // This should be called every time the application is restarted
    fun closeAllStaleChannels() {
        for (card in tm.uiccCardsInfo) {
            for (channel in 0 until 10) {
        for (card in tm.uiccCardsInfoCompat) {
            // As a further option, support of logical channels is expanded up to 19 supplementary logical channels as defined by the latest version of [ISO 7816-4].
            //
            // from <https://globalplatform.org/wp-content/uploads/2018/05/GPC_CardSpecification_v2.3.1_PublicRelease_CC.pdf#page=34>
            // from <https://globalplatform.org/wp-content/uploads/2018/05/GPC_CardSpecification_v2.3.1_PublicRelease_CC.pdf#page=147>
            // from <https://github.com/seek-for-android/pool/blob/01627dfb/src/smartcard-api/src/org/simalliance/openmobileapi/service/Channel.java#L156-L183>
            for (channel in 0 until 20) {
                try {
                    tm.iccCloseLogicalChannelBySlot(card.slotIndex, channel)
                    tm.iccCloseLogicalChannelBySlot(card.physicalSlotIndex, channel)
                } catch (_: Exception) {
                    // We do not care
                }
@@ -29,10 +31,7 @@ class PrivilegedEuiccChannelManager(
    }

    override suspend fun notifyEuiccProfilesChanged(logicalSlotId: Int) {
        appContainer.subscriptionManager.apply {
            findEuiccChannelByLogicalSlot(logicalSlotId)?.let {
                tryRefreshCachedEuiccInfo(it.cardId)
            }
        }
        val channel = findEuiccChannelByLogicalSlot(logicalSlotId) ?: return
        appContainer.subscriptionManager.tryRefreshCachedEuiccInfo(channel.cardId)
    }
}
 No newline at end of file