diff --git a/app/src/main/java/app/septs/euiccprobe/MainActivity.kt b/app/src/main/java/app/septs/euiccprobe/MainActivity.kt index cba719b..98685ac 100644 --- a/app/src/main/java/app/septs/euiccprobe/MainActivity.kt +++ b/app/src/main/java/app/septs/euiccprobe/MainActivity.kt @@ -108,8 +108,7 @@ class MainActivity : AppCompatActivity() { } if (result.state == OpenMobileAPI.State.Available) { for (slot in result.slots) { - val state = if (slot.value) "Available" else "Unavailable" - appendLine("- ${slot.key} Slot: $state") + appendLine("- ${slot.key} Slot: ${slot.value}") } } } diff --git a/app/src/main/java/app/septs/euiccprobe/OpenMobileAPI.kt b/app/src/main/java/app/septs/euiccprobe/OpenMobileAPI.kt index e794563..443c4ea 100644 --- a/app/src/main/java/app/septs/euiccprobe/OpenMobileAPI.kt +++ b/app/src/main/java/app/septs/euiccprobe/OpenMobileAPI.kt @@ -17,7 +17,7 @@ object OpenMobileAPI { data class Result( val backend: Backend, val state: State, - val slots: Map + val slots: Map ) enum class Backend { @@ -32,6 +32,13 @@ object OpenMobileAPI { Available, } + enum class SlotState { + NotConnectable, + Connectable, + Available, + Unavailable, + } + enum class SEBypass { Unavailable, CannotBeBypassed, @@ -92,19 +99,22 @@ object OpenMobileAPI { return Result(Backend.Builtin, State.UnableToConnect, emptyMap()) } val slots = buildMap { + var state: SlotState for (reader in service.readers) { if (!reader.name.startsWith("SIM")) continue + state = SlotState.Connectable try { val session = reader.openSession() val channel = session.openLogicalChannel(ISD_R_APPLET_ID) ?: continue - put(normalizeName(reader.name), channel.isOpen) + state = if (channel.isOpen) SlotState.Available else SlotState.Unavailable if (channel.isOpen) channel.close() if (!session.isClosed) session.closeChannels() } catch (_: SecurityException) { - put(normalizeName(reader.name), true) + state = SlotState.Available } catch (e: Throwable) { Log.e(javaClass.name, "${reader.name} = ${e.message}") } + put(normalizeName(reader.name), state) } service.shutdown() } @@ -124,19 +134,22 @@ object OpenMobileAPI { return Result(Backend.SIMAlliance, State.UnableToConnect, emptyMap()) } val slots = buildMap { + var state: SlotState for (reader in service.readers) { if (!reader.name.startsWith("SIM")) continue + state = SlotState.Connectable try { val session = reader.openSession() val channel = session.openLogicalChannel(ISD_R_APPLET_ID) - put(normalizeName(reader.name), !channel.isClosed) + state = if (channel.isClosed) SlotState.Unavailable else SlotState.Available if (!channel.isClosed) channel.close() if (!session.isClosed) session.closeChannels() } catch (_: SecurityException) { - put(normalizeName(reader.name), true) + state = SlotState.Available } catch (e: Throwable) { Log.e(javaClass.name, "${reader.name} = ${e.message}") } + put(normalizeName(reader.name), state) } service.shutdown() } @@ -144,16 +157,16 @@ object OpenMobileAPI { return Result(Backend.SIMAlliance, state, slots) } - private fun getCardSlots(context: Context): Map { + private fun getCardSlots(context: Context): Map { val service = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager val count = when { Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> service.activeModemCount Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> @Suppress("DEPRECATION") service.phoneCount - else -> return mapOf(Pair("SIM1", false)) + else -> return mapOf(Pair("SIM1", SlotState.NotConnectable)) } return buildMap { for (index in 1..count) { - put("SIM$index", false) + put("SIM$index", SlotState.NotConnectable) } } }