From 71136d7347be3bb92be61c4de38e56ba7fdeceff Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 22 Oct 2019 16:04:20 -0400 Subject: [PATCH] Manually trigger broadcast tests if necessary --- app/src/main/java/com/topjohnwu/magisk/Const.kt | 3 ++- app/src/main/java/com/topjohnwu/magisk/Info.kt | 8 ++++++-- .../topjohnwu/magisk/model/receiver/GeneralReceiver.kt | 2 ++ .../main/java/com/topjohnwu/magisk/ui/SplashActivity.kt | 2 +- app/src/main/java/com/topjohnwu/magisk/utils/RootInit.kt | 9 +++++++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/Const.kt b/app/src/main/java/com/topjohnwu/magisk/Const.kt index 1f6dd169f..79738f20f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Const.kt +++ b/app/src/main/java/com/topjohnwu/magisk/Const.kt @@ -22,8 +22,9 @@ object Const { const val MANAGER_CONFIGS = ".tmp.magisk.config" val USER_ID = Process.myUid() / 100000 - object MagiskVersion { + object Version { const val MIN_SUPPORT = 18000 + const val CONNECT_MODE = 20002 } object ID { diff --git a/app/src/main/java/com/topjohnwu/magisk/Info.kt b/app/src/main/java/com/topjohnwu/magisk/Info.kt index 1e5e63649..54de52dd6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Info.kt +++ b/app/src/main/java/com/topjohnwu/magisk/Info.kt @@ -20,13 +20,17 @@ object Info { val str = ShellUtils.fastCmd("magisk -v").split(":".toRegex())[0] val code = ShellUtils.fastCmd("magisk -V").toInt() val hide = Shell.su("magiskhide --status").exec().isSuccess - Env(code, str, hide) + var mode = Int.MAX_VALUE + if (code >= Const.Version.CONNECT_MODE) + mode = Shell.su("magisk --connect-mode").exec().code + Env(code, str, hide, mode) }.getOrElse { Env() } class Env( val magiskVersionCode: Int = -1, val magiskVersionString: String = "", - hide: Boolean = false + hide: Boolean = false, + var connectionMode: Int = Int.MAX_VALUE ) { val magiskHide get() = Config.magiskHide diff --git a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt index 6a0ca9a4f..86ade4d75 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt @@ -79,6 +79,8 @@ open class GeneralReceiver : BaseReceiver() { NOTIFY -> SuLogger.handleNotify(context, intent) TEST -> { val mode = intent.getIntExtra("mode", 1 shl 1) + if (mode > Info.env.connectionMode) + Info.env.connectionMode = mode Shell.su("magisk --connect-mode $mode").submit() } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt index f31ffbc4c..f0316b7fe 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt @@ -21,7 +21,7 @@ open class SplashActivity : Activity() { super.onCreate(savedInstanceState) Shell.getShell { - if (Info.env.magiskVersionCode > 0 && Info.env.magiskVersionCode < Const.MagiskVersion.MIN_SUPPORT) { + if (Info.env.magiskVersionCode > 0 && Info.env.magiskVersionCode < Const.Version.MIN_SUPPORT) { AlertDialog.Builder(this) .setTitle(R.string.unsupport_magisk_title) .setMessage(R.string.unsupport_magisk_message) diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/RootInit.kt b/app/src/main/java/com/topjohnwu/magisk/utils/RootInit.kt index e503b84ea..c9b13c70c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/RootInit.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/RootInit.kt @@ -17,6 +17,9 @@ class RootInit : Shell.Initializer() { } fun init(context: Context, shell: Shell): Boolean { + // Invalidate env state if shell is recreated + Info.envRef.invalidate() + val job = shell.newJob() if (shell.isRoot) { job.add(context.rawResource(R.raw.util_functions)) @@ -35,6 +38,12 @@ class RootInit : Shell.Initializer() { Info.keepVerity = ShellUtils.fastCmd("echo \$KEEPVERITY").toBoolean() Info.keepEnc = ShellUtils.fastCmd("echo \$KEEPFORCEENCRYPT").toBoolean() Info.recovery = ShellUtils.fastCmd("echo \$RECOVERYMODE").toBoolean() + + if (Info.env.connectionMode == 0) { + // Manually trigger broadcast test + Shell.su("magisk --broadcast-test").exec() + } + return true } }