From 9471577b3becad487c67a004e5661974cbd79b15 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 10 Feb 2020 16:33:58 -0800 Subject: [PATCH] Properly detect advanced device info --- .../java/com/topjohnwu/magisk/core/Info.kt | 15 ++++++++------ .../topjohnwu/magisk/core/utils/RootInit.kt | 7 +++++-- .../topjohnwu/magisk/extensions/XAndroid.kt | 16 --------------- .../main/res/layout/include_home_device.xml | 9 +++------ app/src/main/res/raw/manager.sh | 20 +++++++++++++++++++ 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt index b706a9ceb..e036bd318 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt @@ -24,12 +24,15 @@ object Info { @JvmStatic var stub: DynAPK.Data? = null // Stub - @JvmStatic - var keepVerity = false - @JvmStatic - var keepEnc = false - @JvmStatic - var recovery = false + // Toggle-able options + @JvmStatic var keepVerity = false + @JvmStatic var keepEnc = false + @JvmStatic var recovery = false + + // Immutable device state + @JvmStatic var isSAR = false + @JvmStatic var isAB = false + @JvmStatic var ramdisk = false val isConnected by lazy { KObservableField(false).also { field -> diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt index 417eb3e05..1ef1c4704 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt @@ -26,17 +26,20 @@ class RootInit : Shell.Initializer() { } job.add( + "export BOOTMODE=true", "mount_partitions", "get_flags", - "run_migrations", - "export BOOTMODE=true" + "run_migrations" ).exec() fun getvar(name: String) = ShellUtils.fastCmd(shell, "echo \$$name").toBoolean() Info.keepVerity = getvar("KEEPVERITY") Info.keepEnc = getvar("KEEPFORCEENCRYPT") + Info.isSAR = getvar("SYSTEM_ROOT") + Info.ramdisk = shell.newJob().add("check_boot_ramdisk").exec().isSuccess Info.recovery = getvar("RECOVERYMODE") + Info.isAB = getvar("ISAB") return true } diff --git a/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt b/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt index ee268bc6d..3cc8a6be6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt +++ b/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt @@ -38,10 +38,8 @@ import com.topjohnwu.magisk.core.utils.Utils import com.topjohnwu.magisk.core.utils.currentLocale import com.topjohnwu.magisk.utils.DynamicClassLoader import com.topjohnwu.superuser.Shell -import com.topjohnwu.superuser.ShellUtils import java.io.File import java.io.FileNotFoundException -import java.text.SimpleDateFormat import java.lang.reflect.Array as JArray val packageName: String get() = get().packageName @@ -320,20 +318,6 @@ fun Context.hasPermissions(vararg permissions: String) = permissions.all { ContextCompat.checkSelfPermission(this, it) == PERMISSION_GRANTED } -private val securityLevelFormatter get() = SimpleDateFormat("yyyy-MM-dd", - currentLocale -) - -val isSAR - get() = ShellUtils - .fastCmd("grep_prop ro.build.system_root_image") - .let { it.isNotEmpty() && it.toBoolean() } - -val isAB - get() = ShellUtils - .fastCmd("grep_prop ro.build.ab_update") - .let { it.isNotEmpty() && it.toBoolean() } - fun Activity.hideKeyboard() { val view = currentFocus ?: return getSystemService() diff --git a/app/src/main/res/layout/include_home_device.xml b/app/src/main/res/layout/include_home_device.xml index 269d75080..bd6789592 100644 --- a/app/src/main/res/layout/include_home_device.xml +++ b/app/src/main/res/layout/include_home_device.xml @@ -7,8 +7,6 @@ - - @@ -186,7 +184,6 @@ @@ -220,7 +217,7 @@ @@ -237,7 +234,7 @@ @@ -254,7 +251,7 @@ diff --git a/app/src/main/res/raw/manager.sh b/app/src/main/res/raw/manager.sh index 4edf547b8..7222f6986 100644 --- a/app/src/main/res/raw/manager.sh +++ b/app/src/main/res/raw/manager.sh @@ -122,6 +122,26 @@ force_pm_install() { return $res } +check_boot_ramdisk() { + # Create boolean ISAB + [ -z $SLOT ] && ISAB=false || ISAB=true + + # If we are running as recovery mode, then we do not have ramdisk in boot + $RECOVERYMODE && return 1 + + # If we are A/B, then we must have ramdisk + $ISAB && return 0 + + # If we are using legacy SAR, but not AB, we do not have ramdisk in boot + if grep ' / ' /proc/mounts | grep -q '/dev/root'; then + # Override recovery mode to true + RECOVERYMODE=true + return 1 + fi + + return 0 +} + ########################## # Non-root util_functions ##########################