Guard env state behind cached objects

This commit is contained in:
topjohnwu
2019-10-22 15:37:55 -04:00
parent 9656878ef3
commit a18c552ddf
9 changed files with 68 additions and 28 deletions
@@ -0,0 +1,24 @@
package com.topjohnwu.magisk.utils
class CachedValue<T>(private val factory: () -> T) : Lazy<T> {
private var _val : T? = null
override val value: T
get() {
val local = _val
return local ?: synchronized(this) {
val newInstance = factory()
_val = newInstance
newInstance
}
}
override fun isInitialized() = _val != null
fun invalidate() {
synchronized(this) {
_val = null
}
}
}
@@ -20,9 +20,8 @@ class RootInit : Shell.Initializer() {
val job = shell.newJob()
if (shell.isRoot) {
job.add(context.rawResource(R.raw.util_functions))
.add(context.rawResource(R.raw.utils))
.add(context.rawResource(R.raw.utils))
Const.MAGISK_DISABLE_FILE = SuFile("/cache/.disable_magisk")
Info.loadMagiskInfo()
} else {
job.add(context.rawResource(R.raw.nonroot_utils))
}