Properly detect advanced device info

This commit is contained in:
topjohnwu 2020-02-10 16:33:58 -08:00
parent e85d5e54e2
commit 9471577b3b
5 changed files with 37 additions and 30 deletions

View File

@ -24,12 +24,15 @@ object Info {
@JvmStatic @JvmStatic
var stub: DynAPK.Data? = null // Stub var stub: DynAPK.Data? = null // Stub
@JvmStatic // Toggle-able options
var keepVerity = false @JvmStatic var keepVerity = false
@JvmStatic @JvmStatic var keepEnc = false
var keepEnc = false @JvmStatic var recovery = false
@JvmStatic
var recovery = false // Immutable device state
@JvmStatic var isSAR = false
@JvmStatic var isAB = false
@JvmStatic var ramdisk = false
val isConnected by lazy { val isConnected by lazy {
KObservableField(false).also { field -> KObservableField(false).also { field ->

View File

@ -26,17 +26,20 @@ class RootInit : Shell.Initializer() {
} }
job.add( job.add(
"export BOOTMODE=true",
"mount_partitions", "mount_partitions",
"get_flags", "get_flags",
"run_migrations", "run_migrations"
"export BOOTMODE=true"
).exec() ).exec()
fun getvar(name: String) = ShellUtils.fastCmd(shell, "echo \$$name").toBoolean() fun getvar(name: String) = ShellUtils.fastCmd(shell, "echo \$$name").toBoolean()
Info.keepVerity = getvar("KEEPVERITY") Info.keepVerity = getvar("KEEPVERITY")
Info.keepEnc = getvar("KEEPFORCEENCRYPT") Info.keepEnc = getvar("KEEPFORCEENCRYPT")
Info.isSAR = getvar("SYSTEM_ROOT")
Info.ramdisk = shell.newJob().add("check_boot_ramdisk").exec().isSuccess
Info.recovery = getvar("RECOVERYMODE") Info.recovery = getvar("RECOVERYMODE")
Info.isAB = getvar("ISAB")
return true return true
} }

View File

@ -38,10 +38,8 @@ import com.topjohnwu.magisk.core.utils.Utils
import com.topjohnwu.magisk.core.utils.currentLocale import com.topjohnwu.magisk.core.utils.currentLocale
import com.topjohnwu.magisk.utils.DynamicClassLoader import com.topjohnwu.magisk.utils.DynamicClassLoader
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ShellUtils
import java.io.File import java.io.File
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.text.SimpleDateFormat
import java.lang.reflect.Array as JArray import java.lang.reflect.Array as JArray
val packageName: String get() = get<Context>().packageName val packageName: String get() = get<Context>().packageName
@ -320,20 +318,6 @@ fun Context.hasPermissions(vararg permissions: String) = permissions.all {
ContextCompat.checkSelfPermission(this, it) == PERMISSION_GRANTED 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() { fun Activity.hideKeyboard() {
val view = currentFocus ?: return val view = currentFocus ?: return
getSystemService<InputMethodManager>() getSystemService<InputMethodManager>()

View File

@ -7,8 +7,6 @@
<import type="android.os.Build" /> <import type="android.os.Build" />
<import type="com.topjohnwu.magisk.extensions.XAndroidKt" />
<import type="com.topjohnwu.magisk.extensions.XSUKt" /> <import type="com.topjohnwu.magisk.extensions.XSUKt" />
<import type="com.topjohnwu.magisk.R" /> <import type="com.topjohnwu.magisk.R" />
@ -186,7 +184,6 @@
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
style="@style/W.Home.Card" style="@style/W.Home.Card"
goneUnless="@{XSUKt.hasRoot}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -220,7 +217,7 @@
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right" style="@style/W.Home.ItemContent.Right"
android:text="@{XAndroidKt.isAB ? @string/yes : @string/no}" android:text="@{Info.isAB ? @string/yes : @string/no}"
tools:text="Yes" /> tools:text="Yes" />
</LinearLayout> </LinearLayout>
@ -237,7 +234,7 @@
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right" style="@style/W.Home.ItemContent.Right"
android:text="@{XAndroidKt.isSAR ? @string/yes : @string/no}" android:text="@{Info.isSAR ? @string/yes : @string/no}"
tools:text="Yes" /> tools:text="Yes" />
</LinearLayout> </LinearLayout>
@ -254,7 +251,7 @@
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right" style="@style/W.Home.ItemContent.Right"
android:text="@{Info.recovery ? @string/no : @string/yes }" android:text="@{Info.ramdisk ? @string/yes : @string/no }"
tools:text="Yes" /> tools:text="Yes" />
</LinearLayout> </LinearLayout>

View File

@ -122,6 +122,26 @@ force_pm_install() {
return $res 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 # Non-root util_functions
########################## ##########################