app: add safe mode config to menu

This commit is contained in:
vvb2060 2024-01-07 03:52:42 +08:00 committed by John Wu
parent 02e189a029
commit dd3b9980e7
4 changed files with 25 additions and 4 deletions

View File

@ -40,6 +40,7 @@ object Config : PreferenceConfig, DBConfig {
const val SU_MNT_NS = "mnt_ns" const val SU_MNT_NS = "mnt_ns"
const val SU_BIOMETRIC = "su_biometric" const val SU_BIOMETRIC = "su_biometric"
const val ZYGISK = "zygisk" const val ZYGISK = "zygisk"
const val SAFEMODE = "safemode"
const val DENYLIST = "denylist" const val DENYLIST = "denylist"
const val SU_MANAGER = "requester" const val SU_MANAGER = "requester"
const val KEYSTORE = "keystore" const val KEYSTORE = "keystore"
@ -166,6 +167,7 @@ object Config : PreferenceConfig, DBConfig {
suBiometric = value suBiometric = value
} }
var zygisk by dbSettings(Key.ZYGISK, false) var zygisk by dbSettings(Key.ZYGISK, false)
var safemode by dbSettings(Key.SAFEMODE, 0)
var denyList by BoolDBPropertyNoWrite(Key.DENYLIST, false) var denyList by BoolDBPropertyNoWrite(Key.DENYLIST, false)
var suManager by dbStrings(Key.SU_MANAGER, "", true) var suManager by dbStrings(Key.SU_MANAGER, "", true)
var keyStoreRaw by dbStrings(Key.KEYSTORE, "", true) var keyStoreRaw by dbStrings(Key.KEYSTORE, "", true)

View File

@ -7,6 +7,8 @@ import android.view.MenuItem
import android.widget.PopupMenu import android.widget.PopupMenu
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import com.topjohnwu.magisk.R 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.base.BaseActivity
import com.topjohnwu.magisk.core.ktx.reboot as systemReboot 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_download -> systemReboot("download")
R.id.action_reboot_edl -> systemReboot("edl") R.id.action_reboot_edl -> systemReboot("edl")
R.id.action_reboot_recovery -> systemReboot("recovery") 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 else -> Unit
} }
return true return true
@ -29,10 +36,16 @@ object RebootMenu {
val themeWrapper = ContextThemeWrapper(activity, R.style.Foundation_PopupMenu) val themeWrapper = ContextThemeWrapper(activity, R.style.Foundation_PopupMenu)
val menu = PopupMenu(themeWrapper, activity.findViewById(R.id.action_reboot)) val menu = PopupMenu(themeWrapper, activity.findViewById(R.id.action_reboot))
activity.menuInflater.inflate(R.menu.menu_reboot, menu.menu) activity.menuInflater.inflate(R.menu.menu_reboot, menu.menu)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
activity.getSystemService<PowerManager>()?.isRebootingUserspaceSupported == true)
menu.menu.findItem(R.id.action_reboot_userspace).isVisible = true
menu.setOnMenuItemClickListener(RebootMenu::reboot) menu.setOnMenuItemClickListener(RebootMenu::reboot)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
activity.getSystemService<PowerManager>()?.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 return menu
} }

View File

@ -26,4 +26,9 @@
android:id="@+id/action_reboot_edl" android:id="@+id/action_reboot_edl"
android:title="@string/reboot_edl" /> android:title="@string/reboot_edl" />
</menu> <item
android:id="@+id/action_reboot_safe_mode"
android:checkable="true"
android:title="@string/reboot_safe_mode" />
</menu>

View File

@ -107,6 +107,7 @@
<string name="reboot_bootloader">Reboot to Bootloader</string> <string name="reboot_bootloader">Reboot to Bootloader</string>
<string name="reboot_download">Reboot to Download</string> <string name="reboot_download">Reboot to Download</string>
<string name="reboot_edl">Reboot to EDL</string> <string name="reboot_edl">Reboot to EDL</string>
<string name="reboot_safe_mode">Safe mode</string>
<string name="module_version_author">%1$s by %2$s</string> <string name="module_version_author">%1$s by %2$s</string>
<string name="module_state_remove">Remove</string> <string name="module_state_remove">Remove</string>
<string name="module_state_restore">Restore</string> <string name="module_state_restore">Restore</string>