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 bccd3cc90..c8957cda4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt @@ -40,7 +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 BOOTLOOP = "bootloop" const val DENYLIST = "denylist" const val SU_MANAGER = "requester" const val KEYSTORE = "keystore" @@ -167,7 +167,7 @@ object Config : PreferenceConfig, DBConfig { suBiometric = value } var zygisk by dbSettings(Key.ZYGISK, false) - var safemode by dbSettings(Key.SAFEMODE, 0) + var bootloop by dbSettings(Key.BOOTLOOP, 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 4b28e59de..21b8e76de 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 @@ -25,7 +25,7 @@ object RebootMenu { R.id.action_reboot_safe_mode -> { val status = !item.isChecked item.isChecked = status - Config.safemode = if (status) 2 else 0 + Config.bootloop = if (status) 2 else 0 } else -> Unit } @@ -42,7 +42,7 @@ object RebootMenu { 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 + menu.menu.findItem(R.id.action_reboot_safe_mode).isChecked = Config.bootloop >= 2 } else { menu.menu.findItem(R.id.action_reboot_safe_mode).isVisible = false } diff --git a/native/src/core/bootstages.cpp b/native/src/core/bootstages.cpp index a70ca0196..9c0126610 100644 --- a/native/src/core/bootstages.cpp +++ b/native/src/core/bootstages.cpp @@ -122,14 +122,13 @@ static bool check_key_combo() { } static bool check_safe_mode() { - int safe_mode; + int bootloop_cnt; db_settings dbs; - get_db_settings(dbs, SAFEMODE_CONFIG); - safe_mode = dbs[SAFEMODE_CONFIG]; - - set_db_settings(SAFEMODE_CONFIG, safe_mode + 1); - - return safe_mode >= 2 || get_prop("persist.sys.safemode", true) == "1" || + get_db_settings(dbs, BOOTLOOP_COUNT); + bootloop_cnt = dbs[BOOTLOOP_COUNT]; + // Increment the bootloop counter + set_db_settings(BOOTLOOP_COUNT, bootloop_cnt + 1); + return bootloop_cnt >= 2 || get_prop("persist.sys.safemode", true) == "1" || get_prop("ro.sys.safemode") == "1" || check_key_combo(); } @@ -197,7 +196,8 @@ void MagiskD::boot_complete() const { LOGI("** boot-complete triggered\n"); - set_db_settings(SAFEMODE_CONFIG, 0); + // Reset the bootloop counter once we have boot-complete + set_db_settings(BOOTLOOP_COUNT, 0); // At this point it's safe to create the folder if (access(SECURE_DIR, F_OK) != 0) diff --git a/native/src/core/db.cpp b/native/src/core/db.cpp index bffbe0981..595f6ec19 100644 --- a/native/src/core/db.cpp +++ b/native/src/core/db.cpp @@ -117,7 +117,7 @@ db_settings::db_settings() { data[SU_MNT_NS] = NAMESPACE_MODE_REQUESTER; data[DENYLIST_CONFIG] = false; data[ZYGISK_CONFIG] = MagiskD::get()->is_emulator(); - data[SAFEMODE_CONFIG] = false; + data[BOOTLOOP_COUNT] = 0; } int db_settings::get_idx(string_view key) const { diff --git a/native/src/core/include/db.hpp b/native/src/core/include/db.hpp index 9fba8d13a..f99920b9a 100644 --- a/native/src/core/include/db.hpp +++ b/native/src/core/include/db.hpp @@ -40,7 +40,7 @@ constexpr const char *DB_SETTING_KEYS[] = { "mnt_ns", "denylist", "zygisk", - "safemode", + "bootloop", }; // Settings key indices @@ -50,7 +50,7 @@ enum { SU_MNT_NS, DENYLIST_CONFIG, ZYGISK_CONFIG, - SAFEMODE_CONFIG, + BOOTLOOP_COUNT, }; // Values for root_access