mirror of
https://github.com/Hamza417/Inure.git
synced 2026-03-13 10:19:43 +08:00
feat: add root mode check in ShizukuServiceHelper
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user