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
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 ->

View File

@@ -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
}

View File

@@ -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>()