diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt index dd1d25180..bccd3cc90 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt @@ -40,6 +40,7 @@ object Config : PreferenceConfig, DBConfig { const val SU_MNT_NS = "mnt_ns" const val SU_BIOMETRIC = "su_biometric" const val ZYGISK = "zygisk" + const val SAFEMODE = "safemode" const val DENYLIST = "denylist" const val SU_MANAGER = "requester" const val KEYSTORE = "keystore" @@ -166,6 +167,7 @@ object Config : PreferenceConfig, DBConfig { suBiometric = value } var zygisk by dbSettings(Key.ZYGISK, false) + var safemode by dbSettings(Key.SAFEMODE, 0) var denyList by BoolDBPropertyNoWrite(Key.DENYLIST, false) var suManager by dbStrings(Key.SU_MANAGER, "", true) var keyStoreRaw by dbStrings(Key.KEYSTORE, "", true) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/RebootMenu.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/RebootMenu.kt index 6ecc8f74f..4b28e59de 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/RebootMenu.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/RebootMenu.kt @@ -7,6 +7,8 @@ import android.view.MenuItem import android.widget.PopupMenu import androidx.core.content.getSystemService import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.core.Config +import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.base.BaseActivity import com.topjohnwu.magisk.core.ktx.reboot as systemReboot @@ -20,6 +22,11 @@ object RebootMenu { R.id.action_reboot_download -> systemReboot("download") R.id.action_reboot_edl -> systemReboot("edl") R.id.action_reboot_recovery -> systemReboot("recovery") + R.id.action_reboot_safe_mode -> { + val status = !item.isChecked + item.isChecked = status + Config.safemode = if (status) 2 else 0 + } else -> Unit } return true @@ -29,10 +36,16 @@ object RebootMenu { val themeWrapper = ContextThemeWrapper(activity, R.style.Foundation_PopupMenu) val menu = PopupMenu(themeWrapper, activity.findViewById(R.id.action_reboot)) activity.menuInflater.inflate(R.menu.menu_reboot, menu.menu) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && - activity.getSystemService()?.isRebootingUserspaceSupported == true) - menu.menu.findItem(R.id.action_reboot_userspace).isVisible = true menu.setOnMenuItemClickListener(RebootMenu::reboot) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && + activity.getSystemService()?.isRebootingUserspaceSupported == true) { + menu.menu.findItem(R.id.action_reboot_userspace).isVisible = true + } + if (Const.APP_IS_CANARY) { + menu.menu.findItem(R.id.action_reboot_safe_mode).isChecked = Config.safemode >= 2 + } else { + menu.menu.findItem(R.id.action_reboot_safe_mode).isVisible = false + } return menu } diff --git a/app/src/main/res/menu/menu_reboot.xml b/app/src/main/res/menu/menu_reboot.xml index 5a20c955b..626502393 100644 --- a/app/src/main/res/menu/menu_reboot.xml +++ b/app/src/main/res/menu/menu_reboot.xml @@ -26,4 +26,9 @@ 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 b465da90a..86af664ad 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -107,6 +107,7 @@ Reboot to Bootloader Reboot to Download Reboot to EDL + Safe mode %1$s by %2$s Remove Restore