2019-08-08 07:59:23 +00:00
|
|
|
package com.topjohnwu.magisk
|
|
|
|
|
|
|
|
import com.topjohnwu.magisk.model.entity.UpdateInfo
|
2019-10-22 19:37:55 +00:00
|
|
|
import com.topjohnwu.magisk.utils.CachedValue
|
2019-08-08 07:59:23 +00:00
|
|
|
import com.topjohnwu.superuser.Shell
|
|
|
|
import com.topjohnwu.superuser.ShellUtils
|
|
|
|
|
|
|
|
object Info {
|
|
|
|
|
2019-10-22 19:37:55 +00:00
|
|
|
val envRef = CachedValue { loadState() }
|
2019-08-08 07:59:23 +00:00
|
|
|
|
2019-10-22 19:37:55 +00:00
|
|
|
val env by envRef // Local
|
|
|
|
var remote = UpdateInfo() // Remote
|
2019-08-08 07:59:23 +00:00
|
|
|
|
|
|
|
var keepVerity = false
|
|
|
|
var keepEnc = false
|
|
|
|
var recovery = false
|
|
|
|
|
2019-10-22 19:37:55 +00:00
|
|
|
private fun loadState() = runCatching {
|
|
|
|
val str = ShellUtils.fastCmd("magisk -v").split(":".toRegex())[0]
|
|
|
|
val code = ShellUtils.fastCmd("magisk -V").toInt()
|
|
|
|
val hide = Shell.su("magiskhide --status").exec().isSuccess
|
2019-10-22 20:04:20 +00:00
|
|
|
var mode = Int.MAX_VALUE
|
|
|
|
if (code >= Const.Version.CONNECT_MODE)
|
|
|
|
mode = Shell.su("magisk --connect-mode").exec().code
|
|
|
|
Env(code, str, hide, mode)
|
2019-10-22 19:37:55 +00:00
|
|
|
}.getOrElse { Env() }
|
|
|
|
|
|
|
|
class Env(
|
|
|
|
val magiskVersionCode: Int = -1,
|
|
|
|
val magiskVersionString: String = "",
|
2019-10-22 20:04:20 +00:00
|
|
|
hide: Boolean = false,
|
|
|
|
var connectionMode: Int = Int.MAX_VALUE
|
2019-10-22 19:37:55 +00:00
|
|
|
) {
|
|
|
|
val magiskHide get() = Config.magiskHide
|
|
|
|
|
|
|
|
init {
|
|
|
|
Config.magiskHide = hide
|
2019-08-08 07:59:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|