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

Commit 22a7a514 authored by septs's avatar septs Committed by Peter Cai
Browse files

fix: notification handling in multiple se (#269)

parent 6e5bbc40
Loading
Loading
Loading
Loading
+3 −12
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ import kotlinx.coroutines.flow.Flow
 * or when this instance is destroyed.
 *
 * To precisely control the lifecycle of this object itself (and thus its cached channels),
 * all other compoents must access EuiccChannelManager objects through EuiccChannelManagerService.
 * all other components must access EuiccChannelManager objects through EuiccChannelManagerService.
 * Holding references independent of EuiccChannelManagerService is unsupported.
 */
interface EuiccChannelManager {
@@ -86,21 +86,12 @@ interface EuiccChannelManager {
     *
     * If a channel for that slot / port is not found, EuiccChannelNotFoundException is thrown
     */
    suspend fun <R> withEuiccChannel(
        physicalSlotId: Int,
        portId: Int,
        seId: EuiccChannel.SecureElementId = EuiccChannel.SecureElementId.DEFAULT,
        fn: suspend (EuiccChannel) -> R
    ): R
    suspend fun <R> withEuiccChannel(physicalSlotId: Int, portId: Int, seId: EuiccChannel.SecureElementId, fn: suspend (EuiccChannel) -> R): R

    /**
     * Same as withEuiccChannel(Int, Int, SecureElementId, (EuiccChannel) -> R) but instead uses logical slot ID
     */
    suspend fun <R> withEuiccChannel(
        logicalSlotId: Int,
        seId: EuiccChannel.SecureElementId = EuiccChannel.SecureElementId.DEFAULT,
        fn: suspend (EuiccChannel) -> R
    ): R
    suspend fun <R> withEuiccChannel(logicalSlotId: Int, seId: EuiccChannel.SecureElementId, fn: suspend (EuiccChannel) -> R): R

    /**
     * Invalidate all EuiccChannels previously cached by this Manager
+19 −23
Original line number Diff line number Diff line
@@ -52,16 +52,13 @@ class NotificationsActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker
    }

    override fun onInit() {
        notificationList.layoutManager =
            LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        notificationList.addItemDecoration(
            DividerItemDecoration(
                this,
                LinearLayoutManager.VERTICAL
            )
        )
        notificationList.adapter = notificationAdapter
        registerForContextMenu(notificationList)
        notificationList.apply {
            val context = this@NotificationsActivity
            adapter = notificationAdapter
            layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
            addItemDecoration(DividerItemDecoration(context, LinearLayoutManager.VERTICAL))
            registerForContextMenu(this)
        }

        logicalSlotId = intent.getIntExtra("logicalSlotId", 0)
        seId = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
@@ -131,13 +128,9 @@ class NotificationsActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker

    private fun refresh() {
        launchTask {
            notificationAdapter.notifications =
                euiccChannelManager.withEuiccChannel(logicalSlotId, seId) { channel ->
                    val nameMap = buildMap {
                        for (profile in channel.lpa.profiles) {
                            put(profile.iccid, profile.displayName)
                        }
                    }
            notificationAdapter.notifications = withEuiccChannel { channel ->
                val nameMap = channel.lpa.profiles
                    .associate { Pair(it.iccid, it.displayName) }

                channel.lpa.notifications.map {
                    LocalProfileNotificationWrapper(it, nameMap[it.iccid] ?: "???")
@@ -146,6 +139,9 @@ class NotificationsActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker
        }
    }

    private suspend fun <R> withEuiccChannel(fn: suspend (EuiccChannel) -> R) =
        euiccChannelManager.withEuiccChannel(logicalSlotId, seId, fn)

    data class LocalProfileNotificationWrapper(
        val inner: LocalProfileNotification,
        val profileName: String
@@ -224,7 +220,7 @@ class NotificationsActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker
                R.id.notification_process -> {
                    launchTask {
                        withContext(Dispatchers.IO) {
                            euiccChannelManager.withEuiccChannel(logicalSlotId) { channel ->
                            withEuiccChannel { channel ->
                                channel.lpa.handleNotification(notification.inner.seqNumber)
                            }
                        }
@@ -237,7 +233,7 @@ class NotificationsActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker
                R.id.notification_delete -> {
                    launchTask {
                        withContext(Dispatchers.IO) {
                            euiccChannelManager.withEuiccChannel(logicalSlotId) { channel ->
                            withEuiccChannel { channel ->
                                channel.lpa.deleteNotification(notification.inner.seqNumber)
                            }
                        }