Fix device detection scripts and logic

This commit is contained in:
topjohnwu 2023-08-28 22:13:24 -07:00
parent b1363ee479
commit 75d905a56d
8 changed files with 58 additions and 57 deletions

View File

@ -114,7 +114,6 @@ object Config : PreferenceConfig, DBConfig {
@JvmField var keepVerity = false @JvmField var keepVerity = false
@JvmField var keepEnc = false @JvmField var keepEnc = false
@JvmField var patchVbmeta = false
@JvmField var recovery = false @JvmField var recovery = false
var bootId by preference(Key.BOOT_ID, "") var bootId by preference(Key.BOOT_ID, "")

View File

@ -32,7 +32,7 @@ object Info {
@JvmField val isZygiskEnabled = System.getenv("ZYGISK_ENABLED") == "1" @JvmField val isZygiskEnabled = System.getenv("ZYGISK_ENABLED") == "1"
@JvmStatic val isFDE get() = crypto == "block" @JvmStatic val isFDE get() = crypto == "block"
@JvmField var ramdisk = false @JvmField var ramdisk = false
@JvmField var vbmeta = false var patchBootVbmeta = false
var crypto = "" var crypto = ""
var noDataExec = false var noDataExec = false
var isRooted = false var isRooted = false

View File

@ -490,7 +490,7 @@ abstract class MagiskInstallImpl protected constructor(
"cd $installDir", "cd $installDir",
"KEEPFORCEENCRYPT=${Config.keepEnc} " + "KEEPFORCEENCRYPT=${Config.keepEnc} " +
"KEEPVERITY=${Config.keepVerity} " + "KEEPVERITY=${Config.keepVerity} " +
"PATCHVBMETAFLAG=${Config.patchVbmeta} " + "PATCHVBMETAFLAG=${Info.patchBootVbmeta} " +
"RECOVERYMODE=${Config.recovery} " + "RECOVERYMODE=${Config.recovery} " +
"LEGACYSAR=${Info.legacySAR} " + "LEGACYSAR=${Info.legacySAR} " +
"sh boot_patch.sh $srcBoot") "sh boot_patch.sh $srcBoot")

View File

@ -73,18 +73,17 @@ class ShellInit : Shell.Initializer() {
fun getVar(name: String) = fastCmd("echo \$$name") fun getVar(name: String) = fastCmd("echo \$$name")
fun getBool(name: String) = getVar(name).toBoolean() fun getBool(name: String) = getVar(name).toBoolean()
Info.isSAR = getBool("SYSTEM_ROOT") Info.isSAR = getBool("SYSTEM_AS_ROOT")
Info.ramdisk = getBool("RAMDISKEXIST") Info.ramdisk = getBool("RAMDISKEXIST")
Info.vbmeta = getBool("VBMETAEXIST")
Info.isAB = getBool("ISAB") Info.isAB = getBool("ISAB")
Info.crypto = getVar("CRYPTOTYPE") Info.crypto = getVar("CRYPTOTYPE")
Info.patchBootVbmeta = getBool("PATCHVBMETAFLAG")
Info.legacySAR = getBool("LEGACYSAR") Info.legacySAR = getBool("LEGACYSAR")
// Default presets // Default presets
Config.recovery = getBool("RECOVERYMODE") Config.recovery = getBool("RECOVERYMODE")
Config.keepVerity = getBool("KEEPVERITY") Config.keepVerity = getBool("KEEPVERITY")
Config.keepEnc = getBool("KEEPFORCEENCRYPT") Config.keepEnc = getBool("KEEPFORCEENCRYPT")
Config.patchVbmeta = getBool("PATCHVBMETAFLAG")
return true return true
} }

View File

@ -104,7 +104,6 @@ class InstallViewModel(svc: NetworkService, markwon: Markwon) : BaseViewModel()
step, step,
Config.keepVerity, Config.keepVerity,
Config.keepEnc, Config.keepEnc,
Config.patchVbmeta,
Config.recovery Config.recovery
)) ))
} }
@ -115,7 +114,6 @@ class InstallViewModel(svc: NetworkService, markwon: Markwon) : BaseViewModel()
step = it.step step = it.step
Config.keepVerity = it.keepVerity Config.keepVerity = it.keepVerity
Config.keepEnc = it.keepEnc Config.keepEnc = it.keepEnc
Config.patchVbmeta = it.patchVbmeta
Config.recovery = it.recovery Config.recovery = it.recovery
} }
} }
@ -136,7 +134,6 @@ class InstallViewModel(svc: NetworkService, markwon: Markwon) : BaseViewModel()
val step: Int, val step: Int,
val keepVerity: Boolean, val keepVerity: Boolean,
val keepEnc: Boolean, val keepEnc: Boolean,
val patchVbmeta: Boolean,
val recovery: Boolean, val recovery: Boolean,
) : Parcelable ) : Parcelable

View File

@ -193,30 +193,32 @@ check_encryption() {
mount_partitions() { mount_partitions() {
[ "$(getprop ro.build.ab_update)" = "true" ] && SLOT=$(getprop ro.boot.slot_suffix) [ "$(getprop ro.build.ab_update)" = "true" ] && SLOT=$(getprop ro.boot.slot_suffix)
# Check whether non rootfs root dir exists # Check whether non rootfs root dir exists
SYSTEM_ROOT=false SYSTEM_AS_ROOT=false
grep ' / ' /proc/mounts | grep -qv 'rootfs' && SYSTEM_ROOT=true grep ' / ' /proc/mounts | grep -qv 'rootfs' && SYSTEM_AS_ROOT=true
} }
get_flags() { get_flags() {
KEEPVERITY=$SYSTEM_ROOT KEEPVERITY=$SYSTEM_AS_ROOT
ISENCRYPTED=false ISENCRYPTED=false
[ "$(getprop ro.crypto.state)" = "encrypted" ] && ISENCRYPTED=true [ "$(getprop ro.crypto.state)" = "encrypted" ] && ISENCRYPTED=true
KEEPFORCEENCRYPT=$ISENCRYPTED KEEPFORCEENCRYPT=$ISENCRYPTED
VBMETAEXIST=false
if [ -n "$(getprop ro.boot.vbmeta.device)" -o -n "$(getprop ro.boot.vbmeta.size)" ]; then if [ -n "$(getprop ro.boot.vbmeta.device)" -o -n "$(getprop ro.boot.vbmeta.size)" ]; then
VBMETAEXIST=true
elif getprop ro.product.ab_ota_partitions | grep -wq vbmeta; then
VBMETAEXIST=true
fi
# Preset PATCHVBMETAFLAG to false in the non-root case
PATCHVBMETAFLAG=false PATCHVBMETAFLAG=false
# Make sure RECOVERYMODE has value elif getprop ro.product.ab_ota_partitions | grep -wq vbmeta; then
PATCHVBMETAFLAG=false
else
PATCHVBMETAFLAG=true
fi
[ -z $RECOVERYMODE ] && RECOVERYMODE=false [ -z $RECOVERYMODE ] && RECOVERYMODE=false
if $SYSTEM_AS_ROOT; then
if grep ' / ' /proc/mounts | grep -q '/dev/root'; then if grep ' / ' /proc/mounts | grep -q '/dev/root'; then
LEGACYSAR=true LEGACYSAR=true
else else
LEGACYSAR=false LEGACYSAR=false
fi fi
else
LEGACYSAR=false
fi
} }
run_migrations() { return; } run_migrations() { return; }

View File

@ -5,7 +5,7 @@
# #
# Usage: boot_patch.sh <bootimage> # Usage: boot_patch.sh <bootimage>
# #
# The following flags can be set in environment variables: # The following environment variables can configure the installation:
# KEEPVERITY, KEEPFORCEENCRYPT, PATCHVBMETAFLAG, RECOVERYMODE, LEGACYSAR # KEEPVERITY, KEEPFORCEENCRYPT, PATCHVBMETAFLAG, RECOVERYMODE, LEGACYSAR
# #
# This script should be placed in a directory with the following files: # This script should be placed in a directory with the following files:
@ -179,7 +179,6 @@ fi
echo "KEEPVERITY=$KEEPVERITY" > config echo "KEEPVERITY=$KEEPVERITY" > config
echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config
echo "PATCHVBMETAFLAG=$PATCHVBMETAFLAG" >> config
echo "RECOVERYMODE=$RECOVERYMODE" >> config echo "RECOVERYMODE=$RECOVERYMODE" >> config
if [ -n "$PREINITDEVICE" ]; then if [ -n "$PREINITDEVICE" ]; then
ui_print "- Pre-init storage partition: $PREINITDEVICE" ui_print "- Pre-init storage partition: $PREINITDEVICE"

View File

@ -279,7 +279,7 @@ mount_ro_ensure() {
} }
# After calling this method, the following variables will be set: # After calling this method, the following variables will be set:
# SLOT, SYSTEM_ROOT # SLOT, SYSTEM_AS_ROOT
mount_partitions() { mount_partitions() {
# Check A/B slot # Check A/B slot
SLOT=$(grep_cmdline androidboot.slot_suffix) SLOT=$(grep_cmdline androidboot.slot_suffix)
@ -297,7 +297,7 @@ mount_partitions() {
fi fi
mount_ro_ensure "system$SLOT app$SLOT" /system mount_ro_ensure "system$SLOT app$SLOT" /system
if [ -f /system/init -o -L /system/init ]; then if [ -f /system/init -o -L /system/init ]; then
SYSTEM_ROOT=true SYSTEM_AS_ROOT=true
setup_mntpoint /system_root setup_mntpoint /system_root
if ! mount --move /system /system_root; then if ! mount --move /system /system_root; then
umount /system umount /system
@ -307,63 +307,68 @@ mount_partitions() {
mount -o bind /system_root/system /system mount -o bind /system_root/system /system
else else
if grep ' / ' /proc/mounts | grep -qv 'rootfs' || grep -q ' /system_root ' /proc/mounts; then if grep ' / ' /proc/mounts | grep -qv 'rootfs' || grep -q ' /system_root ' /proc/mounts; then
SYSTEM_ROOT=true SYSTEM_AS_ROOT=true
else else
SYSTEM_ROOT=false SYSTEM_AS_ROOT=false
fi fi
fi fi
$SYSTEM_ROOT && ui_print "- Device is system-as-root" $SYSTEM_AS_ROOT && ui_print "- Device is system-as-root"
} }
# After calling this method, the following variables will be set: # After calling this method, the following variables will be set:
# KEEPVERITY, KEEPFORCEENCRYPT, RECOVERYMODE, PATCHVBMETAFLAG, # ISENCRYPTED, PATCHVBMETAFLAG, LEGACYSAR,
# ISENCRYPTED, VBMETAEXIST, LEGACYSAR # KEEPVERITY, KEEPFORCEENCRYPT, RECOVERYMODE
get_flags() { get_flags() {
if grep ' /data ' /proc/mounts | grep -q 'dm-'; then
ISENCRYPTED=true
elif [ "$(getprop ro.crypto.state)" = "encrypted" ]; then
ISENCRYPTED=true
elif [ "$DATA" = "false" ]
# No data access means unable to decrypt in recovery
ISENCRYPTED=true
else
ISENCRYPTED=false
fi
if [ -n "$(find_block vbmeta vbmeta_a)" ]; then
PATCHVBMETAFLAG=false
else
PATCHVBMETAFLAG=true
ui_print "- No vbmeta partition, patch vbmeta in boot image"
fi
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"
else
LEGACYSAR=false
fi
# Overridable config flags with safe defaults
getvar KEEPVERITY getvar KEEPVERITY
getvar KEEPFORCEENCRYPT getvar KEEPFORCEENCRYPT
getvar RECOVERYMODE getvar RECOVERYMODE
getvar PATCHVBMETAFLAG
if [ -z $KEEPVERITY ]; then if [ -z $KEEPVERITY ]; then
if $SYSTEM_ROOT; then if $SYSTEM_AS_ROOT; then
KEEPVERITY=true KEEPVERITY=true
ui_print "- System-as-root, keep dm/avb-verity" ui_print "- System-as-root, keep dm-verity"
else else
KEEPVERITY=false KEEPVERITY=false
fi fi
fi fi
ISENCRYPTED=false
grep ' /data ' /proc/mounts | grep -q 'dm-' && ISENCRYPTED=true
[ "$(getprop ro.crypto.state)" = "encrypted" ] && ISENCRYPTED=true
if [ -z $KEEPFORCEENCRYPT ]; then if [ -z $KEEPFORCEENCRYPT ]; then
# No data access means unable to decrypt in recovery if $ISENCRYPTED; then
if $ISENCRYPTED || ! $DATA; then
KEEPFORCEENCRYPT=true KEEPFORCEENCRYPT=true
ui_print "- Encrypted data, keep forceencrypt" ui_print "- Encrypted data, keep forceencrypt"
else else
KEEPFORCEENCRYPT=false KEEPFORCEENCRYPT=false
fi fi
fi fi
VBMETAEXIST=false
local VBMETAIMG=$(find_block vbmeta vbmeta_a)
[ -n "$VBMETAIMG" ] && VBMETAEXIST=true
if [ -z $PATCHVBMETAFLAG ]; then
if $VBMETAEXIST; then
PATCHVBMETAFLAG=false
else
PATCHVBMETAFLAG=true
ui_print "- No vbmeta partition, patch vbmeta in boot image"
fi
fi
[ -z $RECOVERYMODE ] && RECOVERYMODE=false [ -z $RECOVERYMODE ] && RECOVERYMODE=false
local IS_DYNAMIC=false
grep -q 'androidboot.super_partition' /proc/cmdline && IS_DYNAMIC=true
[ -b "/dev/block/by-name/super" ] && IS_DYNAMIC=true
if $SYSTEM_ROOT && ! $IS_DYNAMIC; then
LEGACYSAR=true
ui_print "- legacy SAR, force kernel to load rootfs"
else
LEGACYSAR=false
fi
} }
find_boot_image() { find_boot_image() {