Skip to content

Commit

Permalink
Manually trigger broadcast tests if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Oct 22, 2019
1 parent a18c552 commit 71136d7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/com/topjohnwu/magisk/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/topjohnwu/magisk/Info.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/topjohnwu/magisk/utils/RootInit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
}
}

0 comments on commit 71136d7

Please sign in to comment.