From 187f583c955dbd220e890a47a056904b700b1a23 Mon Sep 17 00:00:00 2001 From: canyie Date: Sun, 24 Sep 2023 16:22:24 +0800 Subject: [PATCH] Fix $RECOVERYMODE from config being incorrectly overridden Move legacy SAR checking logic into mount_partitions, and avoid calling get_flags before check_boot_ramdisk Fix #7346 --- app/src/main/res/raw/manager.sh | 14 ++++--------- scripts/util_functions.sh | 37 +++++++++++++++++---------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/app/src/main/res/raw/manager.sh b/app/src/main/res/raw/manager.sh index a59ef4fe6..37bb5b35c 100644 --- a/app/src/main/res/raw/manager.sh +++ b/app/src/main/res/raw/manager.sh @@ -195,6 +195,9 @@ mount_partitions() { # Check whether non rootfs root dir exists SYSTEM_AS_ROOT=false grep ' / ' /proc/mounts | grep -qv 'rootfs' && SYSTEM_AS_ROOT=true + + LEGACYSAR=false + grep ' / ' /proc/mounts | grep -q '/dev/root' && LEGACYSAR=true } get_flags() { @@ -210,15 +213,6 @@ get_flags() { PATCHVBMETAFLAG=true fi [ -z $RECOVERYMODE ] && RECOVERYMODE=false - if $SYSTEM_AS_ROOT; then - if grep ' / ' /proc/mounts | grep -q '/dev/root'; then - LEGACYSAR=true - else - LEGACYSAR=false - fi - else - LEGACYSAR=false - fi } run_migrations() { return; } @@ -231,9 +225,9 @@ grep_prop() { return; } app_init() { mount_partitions - get_flags RAMDISKEXIST=false check_boot_ramdisk && RAMDISKEXIST=true + get_flags run_migrations SHA1=$(grep_prop SHA1 $MAGISKTMP/.magisk/config) check_encryption diff --git a/scripts/util_functions.sh b/scripts/util_functions.sh index cfb79b8b2..42bcaf2c8 100644 --- a/scripts/util_functions.sh +++ b/scripts/util_functions.sh @@ -279,7 +279,7 @@ mount_ro_ensure() { } # After calling this method, the following variables will be set: -# SLOT, SYSTEM_AS_ROOT +# SLOT, SYSTEM_AS_ROOT, LEGACYSAR mount_partitions() { # Check A/B slot SLOT=$(grep_cmdline androidboot.slot_suffix) @@ -313,10 +313,27 @@ mount_partitions() { fi fi $SYSTEM_AS_ROOT && ui_print "- Device is system-as-root" + + LEGACYSAR=false + if $BOOTMODE; then + grep ' / ' /proc/mounts | grep -q '/dev/root' && LEGACYSAR=true + else + # Recovery mode, assume devices that don't use dynamic partitions are legacy SAR + local IS_DYNAMIC=false + if grep -q 'androidboot.super_partition' /proc/cmdline; then + IS_DYNAMIC=true + elif [ -n "$(find_block super)" ]; then + IS_DYNAMIC=true + fi + if $SYSTEM_AS_ROOT && ! $IS_DYNAMIC; then + LEGACYSAR=true + ui_print "- Legacy SAR, force kernel to load rootfs" + fi + fi } # After calling this method, the following variables will be set: -# ISENCRYPTED, PATCHVBMETAFLAG, LEGACYSAR, +# ISENCRYPTED, PATCHVBMETAFLAG, # KEEPVERITY, KEEPFORCEENCRYPT, RECOVERYMODE get_flags() { if grep ' /data ' /proc/mounts | grep -q 'dm-'; then @@ -335,22 +352,6 @@ get_flags() { PATCHVBMETAFLAG=true ui_print "- No vbmeta partition, patch vbmeta in boot image" fi - LEGACYSAR=false - if $BOOTMODE; then - grep ' / ' /proc/mounts | grep -q '/dev/root' && LEGACYSAR=true - else - # Recovery mode, assume devices that don't use dynamic partitions are legacy SAR - local IS_DYNAMIC=false - if grep -q 'androidboot.super_partition' /proc/cmdline; then - IS_DYNAMIC=true - elif [ -n "$(find_block super)" ]; then - IS_DYNAMIC=true - fi - if $SYSTEM_AS_ROOT && ! $IS_DYNAMIC; then - LEGACYSAR=true - ui_print "- Legacy SAR, force kernel to load rootfs" - fi - fi # Overridable config flags with safe defaults getvar KEEPVERITY