Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix $RECOVERYMODE from config being incorrectly overridden #7381

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions app/src/main/res/raw/manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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; }
Expand All @@ -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
Expand Down
37 changes: 19 additions & 18 deletions scripts/util_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down