ソースを参照

EuiccChannelManager: Check for channel validity before returning

Related to #26. Sometimes we could open a channel but it somehow ends up
being invalid, for example for a slot that's not actually an eUICC
(???). This should be a bug somewhere else, but we should nevertheless
prevent OpenEUICC from crashing.
Peter Cai 1 年間 前
コミット
5785fe2e7c

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

@@ -54,8 +54,18 @@ open class DefaultEuiccChannelManager(
                 return null
             }
 
-            return euiccChannelFactory.tryOpenEuiccChannel(port)?.also {
-                channels.add(it)
+            val channel = euiccChannelFactory.tryOpenEuiccChannel(port) ?: return null
+
+            if (channel.valid) {
+                channels.add(channel)
+                return channel
+            } else {
+                Log.i(
+                    TAG,
+                    "Was able to open channel for logical slot ${port.logicalSlotIndex}, but the channel is invalid (cannot get eID or profiles without errors). This slot might be broken, aborting."
+                )
+                channel.close()
+                return null
             }
         }
     }