瀏覽代碼

Add findAvailablePorts() to EuiccChannelManager

For use with OpenEuiccService
Peter Cai 1 年之前
父節點
當前提交
13085ec202

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

@@ -174,6 +174,15 @@ open class DefaultEuiccChannelManager(
             findAllEuiccChannelsByPhysicalSlot(physicalSlotId)?.getOrNull(0)?.portId ?: -1
         }
 
+    override suspend fun findAvailablePorts(physicalSlotId: Int): List<Int> =
+        withContext(Dispatchers.IO) {
+            if (physicalSlotId == EuiccChannelManager.USB_CHANNEL_ID) {
+                return@withContext listOf(0)
+            }
+
+            findAllEuiccChannelsByPhysicalSlot(physicalSlotId)?.map { it.portId } ?: listOf()
+        }
+
     override suspend fun <R> withEuiccChannel(
         physicalSlotId: Int,
         portId: Int,

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

@@ -78,6 +78,11 @@ interface EuiccChannelManager {
      */
     suspend fun findFirstAvailablePort(physicalSlotId: Int): Int
 
+    /**
+     * Returns all mapped & available port IDs for a physical slot.
+     */
+    suspend fun findAvailablePorts(physicalSlotId: Int): List<Int>
+
     class EuiccChannelNotFoundException: Exception("EuiccChannel not found")
 
     /**