Use svc for reboot if feasible

Close #1488
This commit is contained in:
topjohnwu
2019-06-12 00:55:21 -07:00
parent 0ce1720516
commit 00bff4912e
9 changed files with 56 additions and 91 deletions
@@ -155,10 +155,5 @@ class RootUtils : Shell.Initializer() {
fun rmAndLaunch(rm: String, component: ComponentName) {
Shell.su("(rm_launch $rm ${component.flattenToString()})").exec()
}
@JvmStatic
fun reboot() {
Shell.su("/system/bin/reboot ${if (Info.recovery) "recovery" else ""}").submit()
}
}
}
@@ -1,18 +1,13 @@
package com.topjohnwu.magisk.utils
import com.topjohnwu.magisk.Info
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.io.SuFileInputStream
import com.topjohnwu.superuser.io.SuFileOutputStream
import java.io.File
fun reboot(recovery: Boolean = false): Shell.Result {
val command = StringBuilder("/system/bin/reboot")
.appendIf(recovery) {
append(" recovery")
}
.toString()
return Shell.su(command).exec()
fun reboot(reason: String = if (Info.recovery) "recovery" else "") {
Shell.su("/system/bin/svc power reboot $reason || /system/bin/reboot $reason").submit()
}
fun File.suOutputStream() = SuFileOutputStream(this)