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 multiDexEnabled true
versionName props['appVersion'] versionName props['appVersion']
versionCode props['appVersionCode'] as Integer versionCode props['appVersionCode'] as Integer
buildConfigField 'int', 'LATEST_MAGISK', props['versionCode'] ?: 'Integer.MAX_VALUE'
javaCompileOptions { javaCompileOptions {
annotationProcessorOptions { annotationProcessorOptions {

View File

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

View File

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

View File

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

View File

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

View File

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