Skip to content

Commit 033b9fa

Browse files
committed
feat: consider unsecure devcies that have unlocked bootloader
1 parent 975745b commit 033b9fa

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

app/src/main/java/com/klee/sapio/data/DeviceConfiguration.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ class DeviceConfiguration @Inject constructor(
4242
}
4343

4444
fun isRisky(): Int {
45-
return if (RootBeer(mContext).isRooted) {
45+
return if (RootBeer(mContext).isRooted && !isBootloaderLocked()) {
4646
Label.RISKY
4747
} else {
4848
Label.SECURE
4949
}
5050
}
51+
52+
private fun isBootloaderLocked(): Boolean {
53+
val verifiedBootState = SystemPropertyReader().read("ro.boot.verifiedbootstate")
54+
return verifiedBootState == "yellow" || verifiedBootState == "green"
55+
}
5156
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.klee.sapio.data
2+
3+
import android.annotation.SuppressLint
4+
import android.util.Log
5+
6+
@SuppressLint("PrivateApi")
7+
class SystemPropertyReader {
8+
9+
private val getMethod by lazy {
10+
val clazz = Class.forName("android.os.SystemProperties")
11+
clazz.getMethod("get", String::class.java, String::class.java)
12+
}
13+
14+
fun read(propertyName: String): String {
15+
return try {
16+
val value = getMethod.invoke(null, propertyName, "") as String
17+
value.trim()
18+
} catch (exception: ReflectiveOperationException) {
19+
Log.w(TAG, "Unable to read property $propertyName", exception)
20+
""
21+
} catch (exception: IllegalArgumentException) {
22+
Log.w(TAG, "Invalid arguments supplied for $propertyName", exception)
23+
""
24+
}
25+
}
26+
27+
private companion object {
28+
private const val TAG = "SystemPropertyReader"
29+
}
30+
}

0 commit comments

Comments
 (0)