working poc

This commit is contained in:
2026-03-10 00:36:59 +05:00
parent 881dbfb648
commit a319a07440
34 changed files with 2067 additions and 37 deletions

View File

@@ -0,0 +1,54 @@
package sh.sar.isodroid.root
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
object RootManager {
init {
Shell.enableVerboseLogging = true
Shell.setDefaultBuilder(
Shell.Builder.create()
.setFlags(Shell.FLAG_MOUNT_MASTER or Shell.FLAG_REDIRECT_STDERR)
.setTimeout(10)
)
}
suspend fun hasRoot(): Boolean = withContext(Dispatchers.IO) {
Shell.isAppGrantedRoot() == true
}
suspend fun requestRoot(): Boolean = withContext(Dispatchers.IO) {
Shell.getShell().isRoot
}
suspend fun executeCommand(command: String): CommandResult = withContext(Dispatchers.IO) {
val result = Shell.cmd(command).exec()
CommandResult(
success = result.isSuccess,
output = result.out.joinToString("\n"),
error = result.err.joinToString("\n"),
exitCode = result.code
)
}
suspend fun executeCommands(vararg commands: String): CommandResult = withContext(Dispatchers.IO) {
val result = Shell.cmd(*commands).exec()
CommandResult(
success = result.isSuccess,
output = result.out.joinToString("\n"),
error = result.err.joinToString("\n"),
exitCode = result.code
)
}
fun getShell(): Shell = Shell.getShell()
}
data class CommandResult(
val success: Boolean,
val output: String,
val error: String,
val exitCode: Int
)