From dc65a2b8842a3a787c9749189e11c2edb8bd04dd Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 15 May 2022 01:01:54 -0700 Subject: [PATCH] Introduce new debug channel --- app/src/main/java/com/topjohnwu/magisk/core/Config.kt | 3 +++ .../topjohnwu/magisk/data/repository/NetworkService.kt | 6 ++++-- app/src/main/res/values/arrays.xml | 1 + build.py | 8 ++++---- .../main/java/com/topjohnwu/magisk/DownloadActivity.java | 6 ++++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt index e5b283002..26a09bef8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt @@ -70,6 +70,7 @@ object Config : PreferenceModel, DBConfig { const val BETA_CHANNEL = 1 const val CUSTOM_CHANNEL = 2 const val CANARY_CHANNEL = 3 + const val DEBUG_CHANNEL = 4 // root access mode const val ROOT_ACCESS_DISABLED = 0 @@ -106,6 +107,8 @@ object Config : PreferenceModel, DBConfig { private val defaultChannel = if (BuildConfig.DEBUG) + Value.DEBUG_CHANNEL + else if (Const.APP_IS_CANARY) Value.CANARY_CHANNEL else Value.DEFAULT_CHANNEL diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt index e7568ebe6..96ec749f0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt @@ -4,6 +4,7 @@ import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Config.Value.BETA_CHANNEL import com.topjohnwu.magisk.core.Config.Value.CANARY_CHANNEL import com.topjohnwu.magisk.core.Config.Value.CUSTOM_CHANNEL +import com.topjohnwu.magisk.core.Config.Value.DEBUG_CHANNEL import com.topjohnwu.magisk.core.Config.Value.DEFAULT_CHANNEL import com.topjohnwu.magisk.core.Config.Value.STABLE_CHANNEL import com.topjohnwu.magisk.core.Info @@ -24,12 +25,12 @@ class NetworkService( DEFAULT_CHANNEL, STABLE_CHANNEL -> fetchStableUpdate() BETA_CHANNEL -> fetchBetaUpdate() CANARY_CHANNEL -> fetchCanaryUpdate() + DEBUG_CHANNEL -> fetchDebugUpdate() CUSTOM_CHANNEL -> fetchCustomUpdate(Config.customChannelUrl) else -> throw IllegalArgumentException() } if (info.magisk.versionCode < Info.env.versionCode && - Config.updateChannel == DEFAULT_CHANNEL - ) { + Config.updateChannel == DEFAULT_CHANNEL) { Config.updateChannel = BETA_CHANNEL info = fetchBetaUpdate() } @@ -40,6 +41,7 @@ class NetworkService( private suspend fun fetchStableUpdate() = pages.fetchUpdateJSON("stable.json") private suspend fun fetchBetaUpdate() = pages.fetchUpdateJSON("beta.json") private suspend fun fetchCanaryUpdate() = pages.fetchUpdateJSON("canary.json") + private suspend fun fetchDebugUpdate() = pages.fetchUpdateJSON("debug.json") private suspend fun fetchCustomUpdate(url: String) = raw.fetchCustomUpdate(url) private inline fun safe(factory: () -> T): T? { diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 999411173..2ae1f87e3 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -65,6 +65,7 @@ @string/settings_update_beta @string/settings_update_custom Canary + Debug diff --git a/build.py b/build.py index 0790fe357..62355e81c 100755 --- a/build.py +++ b/build.py @@ -275,8 +275,8 @@ def write_if_diff(file_name, text): f.write(text) -def dump_bin_header(): - stub = op.join(config['outdir'], 'stub-release.apk') +def dump_bin_header(args): + stub = op.join(config['outdir'], f'stub-{"release" if args.release else "debug"}.apk') if not op.exists(stub): error('Build stub APK before building "magiskinit"') mkdir_p(native_gen_path) @@ -353,7 +353,7 @@ def build_binary(args): flag = '' if 'magiskinit' in args.target: - dump_bin_header() + dump_bin_header(args) flag += ' B_INIT=1' if 'resetprop' in args.target: @@ -370,7 +370,7 @@ def build_binary(args): def build_apk(args, module): - build_type = 'Release' if args.release or module == 'stub' else 'Debug' + build_type = 'Release' if args.release else 'Debug' proc = execv([gradlew, f'{module}:assemble{build_type}', '-PconfigPath=' + op.abspath(args.config)]) diff --git a/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java b/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java index 8208e1a8d..450988b89 100644 --- a/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java +++ b/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java @@ -40,7 +40,9 @@ import io.michaelrocks.paranoid.Obfuscate; public class DownloadActivity extends Activity { private static final String APP_NAME = "Magisk"; - private static final String CANARY_URL = "https://topjohnwu.github.io/magisk-files/canary.json"; + private static final String JSON_URL = BuildConfig.DEBUG ? + "https://topjohnwu.github.io/magisk-files/debug.json" : + "https://topjohnwu.github.io/magisk-files/canary.json"; private String apkLink = BuildConfig.APK_URL; private Context themed; @@ -105,7 +107,7 @@ public class DownloadActivity extends Activity { private void fetchCanary() { dialog = ProgressDialog.show(themed, "", "", true); - request(CANARY_URL).getAsJSONObject(json -> { + request(JSON_URL).getAsJSONObject(json -> { dialog.dismiss(); try { apkLink = json.getJSONObject("magisk").getString("link");