From fe3553f2a67946b6ccc517e23779f0b164053c7a Mon Sep 17 00:00:00 2001 From: septs Date: Thu, 7 Mar 2024 02:41:14 +0800 Subject: [PATCH] refactor se bypass detect --- .../java/app/septs/euiccprobe/MainActivity.kt | 9 +++---- .../app/septs/euiccprobe/OpenMobileAPI.kt | 25 +++++++++++++++++++ .../app/septs/euiccprobe/SystemService.kt | 24 ------------------ 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/app/septs/euiccprobe/MainActivity.kt b/app/src/main/java/app/septs/euiccprobe/MainActivity.kt index 40a828e..fb2530f 100644 --- a/app/src/main/java/app/septs/euiccprobe/MainActivity.kt +++ b/app/src/main/java/app/septs/euiccprobe/MainActivity.kt @@ -56,11 +56,6 @@ class MainActivity : AppCompatActivity() { appendLine() appendLine("eUICC System Service: $state") } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - val state = SystemService.getSEBypassState(applicationContext) - appendLine() - appendLine("Secure Elements: $state") - } SystemService.getSystemFeatures(applicationContext).let { appendLine() appendLine("System Features:") @@ -103,6 +98,10 @@ class MainActivity : AppCompatActivity() { appendLine("Open Mobile API:") appendLine("- Backend: ${result.backend}") appendLine("- State: ${result.state}") + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + val state = OpenMobileAPI.getBypassState(applicationContext) + appendLine("- Bypass: $state") + } if (result.state == OpenMobileAPI.State.Available) { for (slot in result.slots) { val state = if (slot.value) "Available" else "Unavailable" diff --git a/app/src/main/java/app/septs/euiccprobe/OpenMobileAPI.kt b/app/src/main/java/app/septs/euiccprobe/OpenMobileAPI.kt index b6f31f1..c30874f 100644 --- a/app/src/main/java/app/septs/euiccprobe/OpenMobileAPI.kt +++ b/app/src/main/java/app/septs/euiccprobe/OpenMobileAPI.kt @@ -33,6 +33,31 @@ object OpenMobileAPI { Available, } + + enum class SEBypass { + Unavailable, + CannotBeBypassed, + CanBeBypassed, + FullAccess, + } + + @RequiresApi(Build.VERSION_CODES.P) + fun getBypassState(context: Context): SEBypass { + val pkgName = "com.android.se" + if (!SystemService.hasService(context, pkgName)) { + return SEBypass.Unavailable + } + if (SystemProperties.get("ro.debuggable")?.toInt() != 1) { + return SEBypass.CannotBeBypassed + } + val rule = SystemProperties.get("service.seek") + ?: SystemProperties.get("persist.service.seek") + if (rule.orEmpty().contains("fullaccess")) { + return SEBypass.FullAccess + } + return SEBypass.CanBeBypassed + } + suspend fun getSlots(context: Context): Result { val result = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { fromBuiltin(context) diff --git a/app/src/main/java/app/septs/euiccprobe/SystemService.kt b/app/src/main/java/app/septs/euiccprobe/SystemService.kt index b8a7b0a..815bb6f 100644 --- a/app/src/main/java/app/septs/euiccprobe/SystemService.kt +++ b/app/src/main/java/app/septs/euiccprobe/SystemService.kt @@ -15,30 +15,6 @@ object SystemService { Disabled, } - enum class SEBypass { - Unsupported, - CannotBeBypassed, - CanBeBypassed, - FullAccess, - } - - @RequiresApi(Build.VERSION_CODES.P) - fun getSEBypassState(context: Context): SEBypass { - val pkgName = "com.android.se" - if (!hasService(context, pkgName)) { - return SEBypass.Unsupported - } - if (SystemProperties.get("ro.debuggable")?.toInt() != 1) { - return SEBypass.CannotBeBypassed - } - val rule = SystemProperties.get("service.seek") - ?: SystemProperties.get("persist.service.seek") - if (rule.orEmpty().contains("fullaccess")) { - return SEBypass.FullAccess - } - return SEBypass.CanBeBypassed - } - fun getSystemFeatures(context: Context): Map { val features = arrayOf( "android.hardware.telephony",