@@ -4,6 +4,7 @@ import android.content.Context
44import androidx.compose.runtime.getValue
55import androidx.compose.runtime.mutableStateOf
66import androidx.compose.runtime.setValue
7+ import androidx.compose.ui.graphics.Paint
78import androidx.compose.ui.util.fastJoinToString
89import com.rk.DaemonServer.received_messages
910import com.rk.taskmanager.TaskManager
@@ -187,7 +188,7 @@ enum class DaemonResult(var message: String?) {
187188 OK (null ),
188189 SHIZUKU_PERMISSION_DENIED (strings.shizuku_permission_denied.getString()),
189190 SHIZUKU_NOT_RUNNING (if (ShizukuShell .isShizukuInstalled()) strings.shizuku_not_running.getString() else strings.shizuku_not_installed.getString()),
190- SU_NOT_IN_PATH (strings.su_not_in_path.getString()),
191+ SU_FAILED (strings.su_not_in_path.getString()),
191192 UNKNOWN_ERROR (null ),
192193 DAEMON_REFUSED (strings.daemon_not_started.getString()),
193194 DAEMON_ALREADY_BEING_STARTED (null )
@@ -255,8 +256,10 @@ suspend fun startDaemon(
255256 }
256257
257258 WorkingMode .ROOT .id -> {
258- if (! isSuInPath()) {
259- return @withContext DaemonResult .SU_NOT_IN_PATH
259+ val suCheck = isSuWorking()
260+
261+ if (! suCheck.first){
262+ return @withContext DaemonResult .SU_FAILED .also { it.message = suCheck.second?.message ? : " unknown error" }
260263 }
261264
262265 // val cmd = arrayOf("su", "-c", daemonFile.absolutePath, "-p", port.toString(), "-D")
@@ -287,16 +290,19 @@ suspend fun startDaemon(
287290 return result
288291}
289292
290- suspend fun isSuInPath (): Boolean = withContext(Dispatchers .IO ) {
291- return @withContext try {
292- val process = Runtime .getRuntime().exec(arrayOf(" which" , " su" ))
293- val result = process.inputStream.bufferedReader().readLine()
294- result != null
293+ suspend fun isSuWorking (): Pair <Boolean , Exception ?> = withContext(Dispatchers .IO ) {
294+ try {
295+ val process = Runtime .getRuntime().exec(arrayOf(" su" , " -c" , " id -u" ))
296+ val output = process.inputStream.bufferedReader().readLine()
297+ process.waitFor()
298+ Pair (output == " 0" ,null )
295299 } catch (e: Exception ) {
296- false
300+ e.printStackTrace()
301+ Pair (false ,e)
297302 }
298303}
299304
305+
300306private suspend fun newProcess (
301307 cmd : Array <String >,
302308 env : Array <String >,
0 commit comments