Skip to content

Commit fbe5c0a

Browse files
committed
Fix: Root/su detection - remove FLAG_MOUNT_MASTER, increase timeout, better shell check
1 parent d7b3c3e commit fbe5c0a

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

app/src/main/java/com/appcontrolx/App.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ class App : Application() {
1515
private const val TAG = "AppControlX"
1616

1717
init {
18+
// Configure libsu
1819
Shell.enableVerboseLogging = BuildConfig.DEBUG
1920
Shell.setDefaultBuilder(
2021
Shell.Builder.create()
21-
.setFlags(Shell.FLAG_MOUNT_MASTER)
22-
.setTimeout(10)
22+
.setFlags(Shell.FLAG_REDIRECT_STDERR)
23+
.setTimeout(30) // Increase timeout for slow devices
2324
)
2425
}
2526
}

app/src/main/java/com/appcontrolx/executor/RootExecutor.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,18 @@ class RootExecutor : CommandExecutor {
5858
}
5959

6060
return try {
61+
// Ensure shell is ready
62+
val shell = Shell.getShell()
63+
if (!shell.isRoot) {
64+
return Result.failure(Exception("Root access not available"))
65+
}
66+
6167
val result = Shell.cmd(command).exec()
6268
if (result.isSuccess) {
6369
Result.success(result.out.joinToString("\n"))
6470
} else {
65-
Result.failure(Exception(result.err.joinToString("\n")))
71+
val error = result.err.joinToString("\n").ifEmpty { "Command failed" }
72+
Result.failure(Exception(error))
6673
}
6774
} catch (e: Exception) {
6875
Result.failure(e)

app/src/main/java/com/appcontrolx/service/PermissionBridge.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,17 @@ class PermissionBridge(private val context: Context? = null) {
6565
fun checkRootNow(): Boolean {
6666
return try {
6767
// Get shell instance - this will trigger root request if needed
68-
Shell.getShell()
68+
val shell = Shell.getShell()
6969

70-
// Check if root was granted
70+
// Check if shell is root
71+
if (shell.isRoot) {
72+
return true
73+
}
74+
75+
// Fallback check
7176
Shell.isAppGrantedRoot() == true
7277
} catch (e: Exception) {
78+
android.util.Log.e("PermissionBridge", "Root check failed", e)
7379
false
7480
}
7581
}

0 commit comments

Comments
 (0)