Skip loading magisk in charger mode

This commit is contained in:
LoveSy
2026-02-01 14:53:51 +08:00
committed by John Wu
parent e729eec636
commit b55f597ccf
4 changed files with 15 additions and 4 deletions

View File

@@ -143,6 +143,8 @@ void BootConfig::set(const kv_pairs &kv) noexcept {
strscpy(hardware_plat.data(), value.data(), hardware_plat.size());
} else if (key == "androidboot.fstab_suffix") {
strscpy(fstab_suffix.data(), value.data(), fstab_suffix.size());
} else if (key == "androidboot.mode") {
strscpy(boot_mode.data(), value.data(), boot_mode.size());
} else if (key == "qemu") {
emulator = true;
} else if (key == "androidboot.partition_map") {

View File

@@ -9,6 +9,10 @@ impl BootConfig {
debug!("force_normal_boot=[{}]", self.force_normal_boot);
debug!("rootwait=[{}]", self.rootwait);
unsafe {
debug!(
"boot_mode=[{}]",
Utf8CStr::from_ptr_unchecked(self.boot_mode.as_ptr())
);
debug!(
"slot=[{}]",
Utf8CStr::from_ptr_unchecked(self.slot.as_ptr())

View File

@@ -24,6 +24,7 @@ impl MagiskInit {
fstab_suffix: [0; 32],
hardware: [0; 32],
hardware_plat: [0; 32],
boot_mode: [0; 16],
partition_map: Vec::new(),
},
}
@@ -87,8 +88,8 @@ impl MagiskInit {
self.patch_rw_root();
}
fn recovery(&self) {
info!("Ramdisk is recovery, abort");
fn recovery_or_charger(&self) {
info!("Charger mode or ramdisk is recovery, abort");
self.restore_ramdisk_init();
cstr!("/.backup").remove_all().ok();
}
@@ -151,8 +152,11 @@ impl MagiskInit {
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() {
self.recovery();
} 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() {
self.first_stage();
} else {

View File

@@ -35,6 +35,7 @@ pub mod ffi {
fstab_suffix: [c_char; 32],
hardware: [c_char; 32],
hardware_plat: [c_char; 32],
boot_mode: [c_char; 16],
partition_map: Vec<KeyValue>,
}