浏览代码

Remove last trace of findEuiccChannelBySlotBlocking() public usage

Peter Cai 1 年之前
父节点
当前提交
42c870192c

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

@@ -108,7 +108,7 @@ open class DefaultEuiccChannelManager(
             null
             null
         }
         }
 
 
-    override fun findEuiccChannelBySlotBlocking(logicalSlotId: Int): EuiccChannel? =
+    protected fun findEuiccChannelBySlotBlocking(logicalSlotId: Int): EuiccChannel? =
         runBlocking {
         runBlocking {
             findEuiccChannelBySlot(logicalSlotId)
             findEuiccChannelBySlot(logicalSlotId)
         }
         }

+ 0 - 5
app-common/src/main/java/im/angry/openeuicc/core/EuiccChannelManager.kt

@@ -47,11 +47,6 @@ interface EuiccChannelManager {
      */
      */
     suspend fun waitForReconnect(physicalSlotId: Int, portId: Int, timeoutMillis: Long = 1000)
     suspend fun waitForReconnect(physicalSlotId: Int, portId: Int, timeoutMillis: Long = 1000)
 
 
-    /**
-     * Returns the EuiccChannel corresponding to a **logical** slot
-     */
-    fun findEuiccChannelBySlotBlocking(logicalSlotId: Int): EuiccChannel?
-
     /**
     /**
      * Returns the first mapped & available port ID for a physical slot, or -1 if
      * Returns the first mapped & available port ID for a physical slot, or -1 if
      * not found.
      * not found.

+ 14 - 21
app-common/src/main/java/im/angry/openeuicc/ui/NotificationsActivity.kt

@@ -20,7 +20,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import androidx.recyclerview.widget.RecyclerView
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
 import im.angry.openeuicc.common.R
 import im.angry.openeuicc.common.R
-import im.angry.openeuicc.core.EuiccChannel
 import im.angry.openeuicc.core.EuiccChannelManager
 import im.angry.openeuicc.core.EuiccChannelManager
 import im.angry.openeuicc.util.*
 import im.angry.openeuicc.util.*
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.Dispatchers
@@ -33,7 +32,7 @@ class NotificationsActivity: BaseEuiccAccessActivity(), OpenEuiccContextMarker {
     private lateinit var notificationList: RecyclerView
     private lateinit var notificationList: RecyclerView
     private val notificationAdapter = NotificationAdapter()
     private val notificationAdapter = NotificationAdapter()
 
 
-    private lateinit var euiccChannel: EuiccChannel
+    private var logicalSlotId = -1
 
 
     override fun onCreate(savedInstanceState: Bundle?) {
     override fun onCreate(savedInstanceState: Bundle?) {
         enableEdgeToEdge()
         enableEdgeToEdge()
@@ -56,7 +55,7 @@ class NotificationsActivity: BaseEuiccAccessActivity(), OpenEuiccContextMarker {
         notificationList.adapter = notificationAdapter
         notificationList.adapter = notificationAdapter
         registerForContextMenu(notificationList)
         registerForContextMenu(notificationList)
 
 
-        val logicalSlotId = intent.getIntExtra("logicalSlotId", 0)
+        logicalSlotId = intent.getIntExtra("logicalSlotId", 0)
 
 
         // This is slightly different from the MainActivity logic
         // This is slightly different from the MainActivity logic
         // due to the length (we don't want to display the full USB product name)
         // due to the length (we don't want to display the full USB product name)
@@ -104,16 +103,8 @@ class NotificationsActivity: BaseEuiccAccessActivity(), OpenEuiccContextMarker {
         swipeRefresh.isRefreshing = true
         swipeRefresh.isRefreshing = true
 
 
         lifecycleScope.launch {
         lifecycleScope.launch {
-            if (!this@NotificationsActivity::euiccChannel.isInitialized) {
-                withContext(Dispatchers.IO) {
-                    euiccChannelManagerLoaded.await()
-                    euiccChannel = euiccChannelManager.findEuiccChannelBySlotBlocking(
-                        intent.getIntExtra(
-                            "logicalSlotId",
-                            0
-                        )
-                    )!!
-                }
+            withContext(Dispatchers.IO) {
+                euiccChannelManagerLoaded.await()
             }
             }
 
 
             task()
             task()
@@ -124,13 +115,11 @@ class NotificationsActivity: BaseEuiccAccessActivity(), OpenEuiccContextMarker {
 
 
     private fun refresh() {
     private fun refresh() {
        launchTask {
        launchTask {
-           val profiles = withContext(Dispatchers.IO) {
-               euiccChannel.lpa.profiles
-           }
-
            notificationAdapter.notifications =
            notificationAdapter.notifications =
-               withContext(Dispatchers.IO) {
-                   euiccChannel.lpa.notifications.map {
+               euiccChannelManager.withEuiccChannel(logicalSlotId) { channel ->
+                   val profiles = channel.lpa.profiles
+
+                   channel.lpa.notifications.map {
                        val profile = profiles.find { p -> p.iccid == it.iccid }
                        val profile = profiles.find { p -> p.iccid == it.iccid }
                        LocalProfileNotificationWrapper(it, profile?.displayName ?: "???")
                        LocalProfileNotificationWrapper(it, profile?.displayName ?: "???")
                    }
                    }
@@ -205,7 +194,9 @@ class NotificationsActivity: BaseEuiccAccessActivity(), OpenEuiccContextMarker {
                 R.id.notification_process -> {
                 R.id.notification_process -> {
                     launchTask {
                     launchTask {
                         withContext(Dispatchers.IO) {
                         withContext(Dispatchers.IO) {
-                            euiccChannel.lpa.handleNotification(notification.inner.seqNumber)
+                            euiccChannelManager.withEuiccChannel(logicalSlotId) { channel ->
+                                channel.lpa.handleNotification(notification.inner.seqNumber)
+                            }
                         }
                         }
 
 
                         refresh()
                         refresh()
@@ -215,7 +206,9 @@ class NotificationsActivity: BaseEuiccAccessActivity(), OpenEuiccContextMarker {
                 R.id.notification_delete -> {
                 R.id.notification_delete -> {
                     launchTask {
                     launchTask {
                         withContext(Dispatchers.IO) {
                         withContext(Dispatchers.IO) {
-                            euiccChannel.lpa.deleteNotification(notification.inner.seqNumber)
+                            euiccChannelManager.withEuiccChannel(logicalSlotId) { channel ->
+                                channel.lpa.deleteNotification(notification.inner.seqNumber)
+                            }
                         }
                         }
 
 
                         refresh()
                         refresh()