feat: add root mode check in ShizukuServiceHelper

This commit is contained in:
Hamza Rizwan
2026-02-19 01:55:28 +05:30
parent 35c60124d5
commit 745c8a8adf
2 changed files with 24 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package app.simple.inure.helpers
import android.content.ComponentName
import android.content.ServiceConnection
import android.content.pm.PackageManager
import android.os.IBinder
import android.util.Log
import app.simple.inure.BuildConfig
@@ -91,6 +92,24 @@ class ShizukuServiceHelper private constructor() {
}
}
fun isRootMode(): Boolean {
if (Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED) {
val uid = Shizuku.getUid()
if (uid == 0) {
// Running as Root
return true
} else if (uid == 2000) {
// Running as ADB (Shell)
return false
} else {
// Running as an app with Shizuku permission
return false
}
} else {
return false
}
}
companion object {
private const val TAG = "ShizukuHelper"
private var INSTANCE: ShizukuServiceHelper? = null

View File

@@ -75,6 +75,11 @@ class ClearCacheViewModel(application: Application, val packageInfo: PackageInfo
private fun runShizuku(shizukuServiceHelper: ShizukuServiceHelper) {
viewModelScope.launch(Dispatchers.IO) {
kotlin.runCatching {
if (shizukuServiceHelper.isRootMode().not()) {
postWarning("Shizuku is not running in root mode and root is required to clear app cache.")
return@launch
}
shizukuServiceHelper.service?.simpleExecute(getCommand()).let { shellResult ->
kotlin.runCatching {
for (i in shellResult?.output!!.lines()) {