Magisk/app/src/main/java/com/topjohnwu/magisk/Info.kt

67 lines
1.9 KiB
Kotlin
Raw Normal View History

2019-08-08 07:59:23 +00:00
package com.topjohnwu.magisk
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
import com.topjohnwu.magisk.extensions.get
import com.topjohnwu.magisk.extensions.subscribeK
2019-08-08 07:59:23 +00:00
import com.topjohnwu.magisk.model.entity.UpdateInfo
2019-10-22 19:37:55 +00:00
import com.topjohnwu.magisk.utils.CachedValue
import com.topjohnwu.magisk.utils.KObservableField
2019-08-08 07:59:23 +00:00
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ShellUtils
2019-10-24 09:21:42 +00:00
val isRunningAsStub get() = Info.stub != null
2019-08-08 07:59:23 +00:00
object Info {
2019-10-22 19:37:55 +00:00
val envRef = CachedValue { loadState() }
2019-08-08 07:59:23 +00:00
@JvmStatic
2019-10-24 09:21:42 +00:00
val env by envRef // Local
var remote = UpdateInfo() // Remote
var stub: DynAPK.Data? = null // Stub
2019-08-08 07:59:23 +00:00
@JvmStatic
2019-08-08 07:59:23 +00:00
var keepVerity = false
@JvmStatic
2019-08-08 07:59:23 +00:00
var keepEnc = false
@JvmStatic
2019-08-08 07:59:23 +00:00
var recovery = false
val isConnected by lazy {
KObservableField(false).also { field ->
ReactiveNetwork.observeNetworkConnectivity(get())
.subscribeK {
field.value = it.available()
}
}
}
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
var mode = -1
if (code >= Const.Version.CONNECT_MODE) {
mode = Shell.su("magisk --connect-mode").exec().code
if (mode == 0) {
// Manually trigger broadcast test
Shell.su("magisk --broadcast-test").exec()
}
}
Env(code, str, hide, mode)
2019-10-22 19:37:55 +00:00
}.getOrElse { Env() }
class Env(
val magiskVersionCode: Int = -1,
val magiskVersionString: String = "",
hide: Boolean = false,
var connectionMode: Int = -1
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
}
}
}