From 2760f37e6bc3e708f046d40e83f43a76d6e1de0e Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Thu, 15 Oct 2020 02:00:10 +0800 Subject: [PATCH] Add userspace reboot --- .../java/com/topjohnwu/magisk/events/RebootEvent.kt | 7 +++++++ app/src/main/res/menu/menu_reboot.xml | 13 +++++++++---- app/src/main/res/values/strings.xml | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt b/app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt index 5f64e9015..ec239c032 100644 --- a/app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/RebootEvent.kt @@ -1,8 +1,11 @@ package com.topjohnwu.magisk.events +import android.os.Build +import android.os.PowerManager import android.view.ContextThemeWrapper import android.view.MenuItem import android.widget.PopupMenu +import androidx.core.content.getSystemService import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.base.BaseActivity import com.topjohnwu.superuser.Shell @@ -13,6 +16,7 @@ object RebootEvent { private fun reboot(item: MenuItem): Boolean { when (item.itemId) { R.id.action_reboot_normal -> systemReboot() + R.id.action_reboot_userspace -> systemReboot("userspace") R.id.action_reboot_bootloader -> systemReboot("bootloader") R.id.action_reboot_download -> systemReboot("download") R.id.action_reboot_edl -> systemReboot("edl") @@ -25,6 +29,9 @@ object RebootEvent { fun inflateMenu(activity: BaseActivity): PopupMenu { val themeWrapper = ContextThemeWrapper(activity, R.style.Foundation_PopupMenu) val menu = PopupMenu(themeWrapper, activity.findViewById(R.id.action_reboot)) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && + activity.getSystemService()?.isRebootingUserspaceSupported == true) + menu.menu.getItem(R.id.action_reboot_userspace).isVisible = true activity.menuInflater.inflate(R.menu.menu_reboot, menu.menu) menu.setOnMenuItemClickListener(::reboot) return menu diff --git a/app/src/main/res/menu/menu_reboot.xml b/app/src/main/res/menu/menu_reboot.xml index 5f607ce4f..5a20c955b 100644 --- a/app/src/main/res/menu/menu_reboot.xml +++ b/app/src/main/res/menu/menu_reboot.xml @@ -5,6 +5,15 @@ android:id="@+id/action_reboot_normal" android:title="@string/reboot" /> + + + + @@ -17,8 +26,4 @@ android:id="@+id/action_reboot_edl" android:title="@string/reboot_edl" /> - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4024fc57d..76c41f42e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -109,6 +109,7 @@ (No info provided) + Soft reboot Reboot to Recovery Reboot to Bootloader Reboot to Download