Update device state detection

This commit is contained in:
topjohnwu 2020-09-23 04:40:44 -07:00
parent b59e05c63e
commit ca9f9fee9a
5 changed files with 70 additions and 26 deletions

View File

@ -29,9 +29,10 @@ object Info {
// Device state // Device state
@JvmStatic var isSAR = false @JvmStatic var isSAR = false
@JvmStatic var isAB = false @JvmStatic var isAB = false
@JvmStatic var isFBE = false @JvmStatic val isFBE get() = crypto == "file"
@JvmStatic var ramdisk = false @JvmStatic var ramdisk = false
@JvmStatic var hasGMS = true @JvmStatic var hasGMS = true
@JvmStatic var crypto = ""
val isConnected by lazy { val isConnected by lazy {
ObservableBoolean(false).also { field -> ObservableBoolean(false).also { field ->

View File

@ -10,7 +10,6 @@ import com.topjohnwu.magisk.core.wrap
import com.topjohnwu.magisk.ktx.rawResource import com.topjohnwu.magisk.ktx.rawResource
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ShellUtils import com.topjohnwu.superuser.ShellUtils
import com.topjohnwu.superuser.io.SuFile
class RootInit : Shell.Initializer() { class RootInit : Shell.Initializer() {
@ -20,8 +19,9 @@ class RootInit : Shell.Initializer() {
fun init(context: Context, shell: Shell): Boolean { fun init(context: Context, shell: Shell): Boolean {
shell.newJob().apply { shell.newJob().apply {
add("export SDK_INT=${Build.VERSION.SDK_INT}")
if (Const.Version.atLeast_20_4()) { if (Const.Version.atLeast_20_4()) {
add("export MAGISKTMP=$(magisk --path)/.magisk") add("export MAGISKTMP=\$(magisk --path)/.magisk")
} else { } else {
add("export MAGISKTMP=/sbin/.magisk") add("export MAGISKTMP=/sbin/.magisk")
} }
@ -45,10 +45,7 @@ class RootInit : Shell.Initializer() {
Info.isSAR = getBool("SYSTEM_ROOT") Info.isSAR = getBool("SYSTEM_ROOT")
Info.ramdisk = getBool("RAMDISKEXIST") Info.ramdisk = getBool("RAMDISKEXIST")
Info.isAB = getBool("ISAB") Info.isAB = getBool("ISAB")
Info.crypto = getvar("CRYPTOTYPE")
// FBE does not exist pre 7.0
if (Build.VERSION.SDK_INT >= 24)
Info.isFBE = SuFile("/data/unencrypted").exists()
// Default presets // Default presets
Config.recovery = getBool("RECOVERYMODE") Config.recovery = getBool("RECOVERYMODE")

View File

@ -121,7 +121,7 @@
<LinearLayout <LinearLayout
android:id="@+id/home_magisk_installed_version" android:id="@+id/home_magisk_installed_version"
style="@style/W.Home.Item.Bottom" style="@style/W.Home.Item"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_latest_version"> app:layout_constraintTop_toBottomOf="@+id/home_magisk_latest_version">
@ -136,6 +136,23 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/home_device_details_recovery"
style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="@+id/home_magisk_installed_version"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_installed_version">
<TextView
style="@style/W.Home.ItemContent"
android:text="Ramdisk" />
<TextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Info.ramdisk ? @string/yes : @string/no }"
tools:text="Yes" />
</LinearLayout>
<androidx.constraintlayout.widget.Barrier <androidx.constraintlayout.widget.Barrier
android:id="@+id/home_magisk_barrier" android:id="@+id/home_magisk_barrier"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -178,19 +195,19 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/home_device_details_recovery" android:id="@+id/home_device_details_crypto"
style="@style/W.Home.Item.Bottom" style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="@+id/home_device_details_sar" app:layout_constraintStart_toStartOf="@+id/home_device_details_sar"
app:layout_constraintTop_toBottomOf="@+id/home_device_details_sar"> app:layout_constraintTop_toBottomOf="@+id/home_device_details_sar">
<TextView <TextView
style="@style/W.Home.ItemContent" style="@style/W.Home.ItemContent"
android:text="Ramdisk" /> android:text="Crypto" />
<TextView <TextView
style="@style/W.Home.ItemContent.Right" style="@style/W.Home.ItemContent.Right"
android:text="@{Info.ramdisk ? @string/yes : @string/no }" android:text="@{Info.crypto}"
tools:text="Yes" /> tools:text="N/A" />
</LinearLayout> </LinearLayout>

View File

@ -48,7 +48,7 @@ restore_imgs() {
for name in dtb dtbo; do for name in dtb dtbo; do
[ -f $BACKUPDIR/${name}.img.gz ] || continue [ -f $BACKUPDIR/${name}.img.gz ] || continue
local IMAGE=`find_block $name$SLOT` local IMAGE=$(find_block $name$SLOT)
[ -z $IMAGE ] && continue [ -z $IMAGE ] && continue
flash_image $BACKUPDIR/${name}.img.gz $IMAGE flash_image $BACKUPDIR/${name}.img.gz $IMAGE
done done
@ -60,7 +60,7 @@ post_ota() {
cd $1 cd $1
chmod 755 bootctl chmod 755 bootctl
./bootctl hal-info || return ./bootctl hal-info || return
[ `./bootctl get-current-slot` -eq 0 ] && SLOT_NUM=1 || SLOT_NUM=0 [ $(./bootctl get-current-slot) -eq 0 ] && SLOT_NUM=1 || SLOT_NUM=0
./bootctl set-active-boot-slot $SLOT_NUM ./bootctl set-active-boot-slot $SLOT_NUM
cat << EOF > post-fs-data.d/post_ota.sh cat << EOF > post-fs-data.d/post_ota.sh
${1}/bootctl mark-boot-successful ${1}/bootctl mark-boot-successful
@ -103,36 +103,61 @@ check_boot_ramdisk() {
# Create boolean ISAB # Create boolean ISAB
[ -z $SLOT ] && ISAB=false || ISAB=true [ -z $SLOT ] && ISAB=false || ISAB=true
# If we are running as recovery mode, then we do not have ramdisk in boot # If we are running as recovery mode, then we do not have ramdisk
$RECOVERYMODE && return 1 [ "$RECOVERYMODE" = "true" ] && return 1
# If we are A/B, then we must have ramdisk # If we are A/B, then we must have ramdisk
$ISAB && return 0 $ISAB && return 0
# If we are using legacy SAR, but not AB, we do not have ramdisk in boot # If we are using legacy SAR, but not A/B, assume we do not have ramdisk
if grep ' / ' /proc/mounts | grep -q '/dev/root'; then if grep ' / ' /proc/mounts | grep -q '/dev/root'; then
# Override recovery mode to true # Override recovery mode to true if not set
RECOVERYMODE=true [ -z $RECOVERYMODE ] && RECOVERYMODE=true
return 1 return 1
fi fi
return 0 return 0
} }
check_encryption() {
if $ISENCRYPTED; then
if [ $SDK_INT -lt 24 ]; then
CRYPTOTYPE="block"
elif [ -d /data/unencrypted ]; then
CRYPTOTYPE="file"
else
# First see what the system tells us
CRYPTOTYPE=$(getprop ro.crypto.type)
if [ -z $CRYPTOTYPE ]; then
# If not mounting through device mapper, we are FBE
if grep ' /data ' /proc/mounts | grep -qv 'dm-'; then
CRYPTOTYPE="file"
else
# We are either FDE or metadata encryption (which is also FBE)
grep -q ' /metadata ' /proc/mounts && CRYPTOTYPE="file" || CRYPTOTYPE="block"
fi
fi
fi
else
CRYPTOTYPE="N/A"
fi
}
########################## ##########################
# Non-root util_functions # Non-root util_functions
########################## ##########################
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
grep ' / ' /proc/mounts | grep -qv 'rootfs' && SYSTEM_ROOT=true || SYSTEM_ROOT=false grep ' / ' /proc/mounts | grep -qv 'rootfs' && SYSTEM_ROOT=true || SYSTEM_ROOT=false
} }
get_flags() { get_flags() {
$SYSTEM_ROOT && KEEPVERITY=true || KEEPVERITY=false KEEPVERITY=$SYSTEM_ROOT
[ "`getprop ro.crypto.state`" = "encrypted" ] && KEEPFORCEENCRYPT=true || KEEPFORCEENCRYPT=false [ "$(getprop ro.crypto.state)" = "encrypted" ] && ISENCRYPTED=true || ISENCRYPTED=false
RECOVERYMODE=false KEEPFORCEENCRYPT=$ISENCRYPTED
# Do NOT preset RECOVERYMODE here
} }
run_migrations() { return; } run_migrations() { return; }
@ -150,4 +175,7 @@ mm_init() {
run_migrations run_migrations
SHA1=$(grep_prop SHA1 $MAGISKTMP/config) SHA1=$(grep_prop SHA1 $MAGISKTMP/config)
check_boot_ramdisk && RAMDISKEXIST=true || RAMDISKEXIST=false check_boot_ramdisk && RAMDISKEXIST=true || RAMDISKEXIST=false
check_encryption
# Make sure RECOVERYMODE has value
[ -z $RECOVERYMODE ] && RECOVERYMODE=false
} }

View File

@ -364,10 +364,11 @@ get_flags() {
fi fi
fi fi
if [ -z $KEEPFORCEENCRYPT ]; then if [ -z $KEEPFORCEENCRYPT ]; then
grep ' /data ' /proc/mounts | grep -q 'dm-' && FDE=true || FDE=false ISENCRYPTED=false
[ -d /data/unencrypted ] && FBE=true || FBE=false grep ' /data ' /proc/mounts | grep -q 'dm-' && ISENCRYPTED=true
[ -d /data/unencrypted ] && ISENCRYPTED=true
# No data access means unable to decrypt in recovery # No data access means unable to decrypt in recovery
if $FDE || $FBE || ! $DATA; then if $ISENCRYPTED || ! $DATA; then
KEEPFORCEENCRYPT=true KEEPFORCEENCRYPT=true
ui_print "- Encrypted data, keep forceencrypt" ui_print "- Encrypted data, keep forceencrypt"
else else