From 1e7e06d1cc741b0b70dcf4f6d24bae0b5022d066 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 17 Feb 2020 22:05:32 -0800 Subject: [PATCH] Proper canary version detection --- .../java/com/topjohnwu/magisk/core/Config.kt | 42 +++++-------------- .../java/com/topjohnwu/magisk/core/Info.kt | 2 + .../com/topjohnwu/magisk/core/utils/Utils.kt | 2 - .../magisk/ui/settings/SettingsItems.kt | 3 +- .../topjohnwu/magisk/DownloadActivity.java | 2 +- 5 files changed, 15 insertions(+), 36 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 2d1db941d..246ccd48a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt @@ -106,7 +106,7 @@ object Config : PreferenceModel, DBConfig { } private val defaultChannel = - if (Utils.isCanary) { + if (isCanaryVersion) { if (BuildConfig.DEBUG) Value.CANARY_DEBUG_CHANNEL else @@ -116,24 +116,12 @@ object Config : PreferenceModel, DBConfig { var bootId by preference(Key.BOOT_ID, "") var downloadPath by preference(Key.DOWNLOAD_PATH, Environment.DIRECTORY_DOWNLOADS) - var repoOrder by preference( - Key.REPO_ORDER, - Value.ORDER_DATE - ) + var repoOrder by preference(Key.REPO_ORDER, Value.ORDER_DATE) var suDefaultTimeout by preferenceStrInt(Key.SU_REQUEST_TIMEOUT, 10) - var suAutoReponse by preferenceStrInt( - Key.SU_AUTO_RESPONSE, - Value.SU_PROMPT - ) - var suNotification by preferenceStrInt( - Key.SU_NOTIFICATION, - Value.NOTIFICATION_TOAST - ) - var updateChannel by preferenceStrInt( - Key.UPDATE_CHANNEL, - defaultChannel - ) + var suAutoReponse by preferenceStrInt(Key.SU_AUTO_RESPONSE, Value.SU_PROMPT) + var suNotification by preferenceStrInt(Key.SU_NOTIFICATION, Value.NOTIFICATION_TOAST) + var updateChannel by preferenceStrInt(Key.UPDATE_CHANNEL, defaultChannel) var safetyNotice by preference(Key.SAFETY, true) var darkThemeExtended by preference( @@ -153,26 +141,16 @@ object Config : PreferenceModel, DBConfig { var customChannelUrl by preference(Key.CUSTOM_CHANNEL, "") var locale by preference(Key.LOCALE, "") - var rootMode by dbSettings( - Key.ROOT_ACCESS, - Value.ROOT_ACCESS_APPS_AND_ADB - ) - var suMntNamespaceMode by dbSettings( - Key.SU_MNT_NS, - Value.NAMESPACE_MODE_REQUESTER - ) - var suMultiuserMode by dbSettings( - Key.SU_MULTIUSER_MODE, - Value.MULTIUSER_MODE_OWNER_ONLY - ) + var rootMode by dbSettings(Key.ROOT_ACCESS, Value.ROOT_ACCESS_APPS_AND_ADB) + var suMntNamespaceMode by dbSettings(Key.SU_MNT_NS, Value.NAMESPACE_MODE_REQUESTER) + var suMultiuserMode by dbSettings(Key.SU_MULTIUSER_MODE, Value.MULTIUSER_MODE_OWNER_ONLY) var suBiometric by dbSettings(Key.SU_BIOMETRIC, false) var suManager by dbStrings(Key.SU_MANAGER, "", true) var keyStoreRaw by dbStrings(Key.KEYSTORE, "", true) // Always return a path in external storage where we can write - val downloadDirectory - get() = - Utils.ensureDownloadPath(downloadPath) ?: get().getExternalFilesDir(null)!! + val downloadDirectory get() = + Utils.ensureDownloadPath(downloadPath) ?: get().getExternalFilesDir(null)!! private const val SU_FINGERPRINT = "su_fingerprint" diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt index e036bd318..b45265595 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt @@ -1,6 +1,7 @@ package com.topjohnwu.magisk.core import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork +import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.DynAPK import com.topjohnwu.magisk.core.model.UpdateInfo import com.topjohnwu.magisk.extensions.get @@ -13,6 +14,7 @@ import java.io.FileInputStream import java.io.IOException val isRunningAsStub get() = Info.stub != null +val isCanaryVersion = !BuildConfig.VERSION_NAME.contains(".") object Info { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/Utils.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/Utils.kt index 1ab7849e7..068e6d503 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/Utils.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/Utils.kt @@ -17,8 +17,6 @@ import java.util.concurrent.TimeUnit object Utils { - val isCanary: Boolean = BuildConfig.VERSION_NAME.contains("-") - fun toast(msg: CharSequence, duration: Int) { UiThreadHandler.run { Toast.makeText(get(), msg, duration).show() } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt index a4234216b..6933c4022 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt @@ -12,6 +12,7 @@ import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info +import com.topjohnwu.magisk.core.isCanaryVersion import com.topjohnwu.magisk.core.utils.* import com.topjohnwu.magisk.databinding.DialogSettingsAppNameBinding import com.topjohnwu.magisk.databinding.DialogSettingsDownloadPathBinding @@ -140,7 +141,7 @@ object UpdateChannel : SettingsItem.Selector() { override val title = R.string.settings_update_channel_title.asTransitive() override val entries = resources.getStringArray(R.array.update_channel).let { - if (!Utils.isCanary && Config.updateChannel < Config.Value.CANARY_CHANNEL) + if (!isCanaryVersion && Config.updateChannel < Config.Value.CANARY_CHANNEL) it.take(it.size - 2).toTypedArray() else it } override val entryValues = resources.getStringArray(R.array.value_array) diff --git a/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java b/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java index 4aa789f8d..87e79d151 100644 --- a/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java +++ b/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java @@ -27,7 +27,7 @@ import static com.topjohnwu.magisk.DelegateApplication.MANAGER_APK; public class DownloadActivity extends Activity { - private static final boolean CANARY = BuildConfig.VERSION_NAME.contains("-"); + private static final boolean CANARY = !BuildConfig.VERSION_NAME.contains("."); private static final String URL = BuildConfig.DEV_CHANNEL != null ? BuildConfig.DEV_CHANNEL : RawData.urlBase() + (BuildConfig.DEBUG ? RawData.debug() : (CANARY ? RawData.canary() : RawData.stable()));