Refactor version handling

This commit is contained in:
topjohnwu 2020-06-28 06:51:58 -07:00
parent 594f268885
commit 3c78344812
6 changed files with 36 additions and 29 deletions

View File

@ -22,6 +22,7 @@ android {
multiDexEnabled true
versionName props['appVersion']
versionCode props['appVersionCode'] as Integer
buildConfigField 'int', 'LATEST_MAGISK', props['versionCode'] ?: 'Integer.MAX_VALUE'
javaCompileOptions {
annotationProcessorOptions {

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk.core
import android.os.Process
import com.topjohnwu.magisk.BuildConfig
object Const {
@ -24,9 +25,10 @@ object Const {
object Version {
const val MIN_VERSION = "v19.0"
const val MIN_VERCODE = 19000
const val PROVIDER_CONNECT = 20200
const val DYNAMIC_PATH = 20400
const val SEPOLICY_REDESIGN = 20416
fun atLeast_20_2() = Info.env.magiskVersionCode >= 20200
fun atLeast_20_4() = Info.env.magiskVersionCode >= 20400
fun atLeastCanary() = Info.env.magiskVersionCode > BuildConfig.LATEST_MAGISK / 100 * 100
}
object ID {

View File

@ -9,7 +9,6 @@ import androidx.collection.ArrayMap
import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.magiskdb.PolicyDao
import com.topjohnwu.magisk.core.model.MagiskPolicy
import com.topjohnwu.magisk.core.model.toPolicy
@ -38,7 +37,7 @@ abstract class SuRequestHandler(
val name = intent.getStringExtra("socket") ?: return false
try {
if (Info.env.magiskVersionCode >= Const.Version.SEPOLICY_REDESIGN) {
if (Const.Version.atLeastCanary()) {
val server = LocalServerSocket(name)
val futureSocket = Shell.EXECUTOR.submit(Callable { server.accept() })
try {

View File

@ -103,8 +103,7 @@ object PatchAPK {
}
private fun patchAndHide(context: Context, label: String): Boolean {
val dlStub = !isRunningAsStub && SDK_INT >= 28 &&
Info.env.magiskVersionCode >= Const.Version.PROVIDER_CONNECT
val dlStub = !isRunningAsStub && SDK_INT >= 28 && Const.Version.atLeast_20_2()
val src = if (dlStub) {
val stub = File(context.cacheDir, "stub.apk")
val svc = get<GithubRawServices>()

View File

@ -16,30 +16,35 @@ class RootInit : Shell.Initializer() {
}
fun init(context: Context, shell: Shell): Boolean {
val job = shell.newJob()
if (Info.env.magiskVersionCode >= Const.Version.DYNAMIC_PATH) {
job.add("export ASH_STANDALONE=1")
.add("[ -x /data/adb/magisk/busybox ] && exec /data/adb/magisk/busybox sh")
.add("MAGISKTMP=$(magisk --path)/.magisk")
shell.newJob().apply {
if (Const.Version.atLeast_20_4()) {
add("MAGISKTMP=$(magisk --path)/.magisk")
} else {
job.add("export PATH=\"/sbin/.magisk/busybox:\$PATH\"")
.add("MAGISKTMP=/sbin/.magisk")
add("MAGISKTMP=/sbin/.magisk")
}
job.add(context.rawResource(R.raw.manager))
if (Const.Version.atLeastCanary()) {
add("export ASH_STANDALONE=1")
add("[ -x /data/adb/magisk/busybox ] && exec /data/adb/magisk/busybox sh")
} else {
add("export PATH=\"\$MAGISKTMP/busybox:\$PATH\"")
}
add(context.rawResource(R.raw.manager))
if (shell.isRoot) {
job.add(context.rawResource(R.raw.util_functions))
add(context.rawResource(R.raw.util_functions))
}
job.add("mm_init").exec()
add("mm_init")
}.exec()
fun getvar(name: String) = ShellUtils.fastCmd(shell, "echo \$$name").toBoolean()
fun getvar(name: String) = ShellUtils.fastCmd(shell, "echo \$$name")
fun getBool(name: String) = getvar(name).toBoolean()
Const.MAGISKTMP = ShellUtils.fastCmd(shell, "echo \$MAGISKTMP")
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")
Const.MAGISKTMP = getvar("MAGISKTMP")
Info.keepVerity = getBool("KEEPVERITY")
Info.keepEnc = getBool("KEEPFORCEENCRYPT")
Info.isSAR = getBool("SYSTEM_ROOT")
Info.ramdisk = getBool("RAMDISKEXIST")
Info.recovery = getBool("RECOVERYMODE")
Info.isAB = getBool("ISAB")
return true
}

View File

@ -145,4 +145,5 @@ mm_init() {
get_flags
run_migrations
SHA1=$(grep_prop SHA1 $MAGISKTMP/config)
check_boot_ramdisk && RAMDISKEXIST=true || RAMDISKEXIST=false
}