Skip to content

Commit 0675a18

Browse files
vv19ca0topjohnwu
authored andcommitted
init: check charger mode before force_normal_boot
b55f597 ("Skip loading magisk in charger mode") aborts when androidboot.mode=charger, but the check sits after the force_normal_boot branch. Devices that set androidboot.force_normal_boot=1 during off-mode charging (e.g. some Motorola models) take force_normal_boot -> first_stage() and never reach the charger check, so Magisk still loads in charger mode and bumps the never-reset bootloop counter until safe mode trips. Move the charger check ahead of skip_initramfs/force_normal_boot so charger boots abort regardless, matching AOSP treating charger mode first. Fixes #9967.
1 parent a5bca88 commit 0675a18

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

native/src/init/init.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,19 @@ impl MagiskInit {
148148
let argv1 = unsafe { *self.argv.offset(1) };
149149
if !argv1.is_null() && unsafe { CStr::from_ptr(argv1) == c"selinux_setup" } {
150150
self.second_stage();
151+
} else if unsafe { CStr::from_ptr(self.config.boot_mode.as_ptr()) } == c"charger" {
152+
// Charger (off-mode charging) must abort before any normal-boot path
153+
// (skip_initramfs / force_normal_boot). Some devices (e.g. Motorola) set
154+
// androidboot.force_normal_boot=1 during off-mode charging, which would otherwise
155+
// route to first_stage() and load Magisk in charger mode, bumping the never-reset
156+
// bootloop counter until safe mode trips. AOSP likewise treats charger first.
157+
self.recovery_or_charger();
151158
} else if self.config.skip_initramfs {
152159
self.legacy_system_as_root();
153160
} else if self.config.force_normal_boot {
154161
self.first_stage();
155162
} else if cstr!("/sbin/recovery").exists()
156163
|| cstr!("/system/bin/recovery").exists()
157-
|| unsafe { CStr::from_ptr(self.config.boot_mode.as_ptr()) } == c"charger"
158164
{
159165
self.recovery_or_charger();
160166
} else if self.check_two_stage() {

0 commit comments

Comments
 (0)