Properly detect advanced device info
This commit is contained in:
parent
e85d5e54e2
commit
9471577b3b
@ -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 ->
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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<Context>().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<InputMethodManager>()
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
<import type="android.os.Build" />
|
||||
|
||||
<import type="com.topjohnwu.magisk.extensions.XAndroidKt" />
|
||||
|
||||
<import type="com.topjohnwu.magisk.extensions.XSUKt" />
|
||||
|
||||
<import type="com.topjohnwu.magisk.R" />
|
||||
@ -186,7 +184,6 @@
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
style="@style/W.Home.Card"
|
||||
goneUnless="@{XSUKt.hasRoot}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
@ -220,7 +217,7 @@
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
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" />
|
||||
|
||||
</LinearLayout>
|
||||
@ -237,7 +234,7 @@
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
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" />
|
||||
|
||||
</LinearLayout>
|
||||
@ -254,7 +251,7 @@
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
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" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -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
|
||||
##########################
|
||||
|
Loading…
Reference in New Issue
Block a user