From 0675a18a3aaa51334ed724605b776af5db1469f4 Mon Sep 17 00:00:00 2001 From: lsx Date: Fri, 24 Jul 2026 19:33:17 +0800 Subject: [PATCH] init: check charger mode before force_normal_boot b55f597c ("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. --- native/src/init/init.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/native/src/init/init.rs b/native/src/init/init.rs index 60dfe16d1..59f5b31d1 100644 --- a/native/src/init/init.rs +++ b/native/src/init/init.rs @@ -148,13 +148,19 @@ impl MagiskInit { let argv1 = unsafe { *self.argv.offset(1) }; if !argv1.is_null() && unsafe { CStr::from_ptr(argv1) == c"selinux_setup" } { self.second_stage(); + } else if unsafe { CStr::from_ptr(self.config.boot_mode.as_ptr()) } == c"charger" { + // Charger (off-mode charging) must abort before any normal-boot path + // (skip_initramfs / force_normal_boot). Some devices (e.g. Motorola) set + // androidboot.force_normal_boot=1 during off-mode charging, which would otherwise + // route to first_stage() and load Magisk in charger mode, bumping the never-reset + // bootloop counter until safe mode trips. AOSP likewise treats charger first. + self.recovery_or_charger(); } else if self.config.skip_initramfs { self.legacy_system_as_root(); } else if self.config.force_normal_boot { self.first_stage(); } else if cstr!("/sbin/recovery").exists() || cstr!("/system/bin/recovery").exists() - || unsafe { CStr::from_ptr(self.config.boot_mode.as_ptr()) } == c"charger" { self.recovery_or_charger(); } else if self.check_two_stage() {