diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e2fab45..9955b8f2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - #2308 - Update the deprecated BitmapDrawable constructor - #1311 - Enable downloads in custom tabs. - #1874 - Added TOP info panel dialog for custom tabs. +- #1735 - Adds API to see the release channel ### Changed - #1429 - Updated site permissions ui for MVP diff --git a/app/build.gradle b/app/build.gradle index 4e294bbf0..99abd693b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,8 +32,7 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunnerArguments clearPackageData: 'true' manifestPlaceholders.isRaptorEnabled = "false" - buildConfigField "boolean", "IS_RELEASED", "false" - resValue "bool", "IS_NOT_RELEASED", "true" + resValue "bool", "IS_DEBUG", "true" } def releaseTemplate = { @@ -55,13 +54,11 @@ android { applicationIdSuffix ".raptor" } nightly releaseTemplate >> { - buildConfigField "boolean", "IS_RELEASED", "true" - resValue "bool", "IS_NOT_RELEASED", "false" + resValue "bool", "IS_DEBUG", "false" } beta releaseTemplate >> { applicationIdSuffix ".beta" - buildConfigField "boolean", "IS_RELEASED", "true" - resValue "bool", "IS_NOT_RELEASED", "false" + resValue "bool", "IS_DEBUG", "false" } } @@ -133,9 +130,10 @@ android.applicationVariants.all { variant -> def buildType = variant.buildType.name def versionCode = null - def isReleased = variant.buildType.buildConfigFields['IS_RELEASED']?.value ?: false + def releaseChannels = ["nightly", "beta", "release"] + def isReleased = releaseChannels.contains(buildType) - buildConfigField 'Boolean', 'COLLECTIONS_ENABLED', (buildType != "release").toString() + buildConfigField 'Boolean', 'COLLECTIONS_ENABLED', (!isReleased).toString() if (isReleased) { versionCode = generatedVersionCode diff --git a/app/src/main/java/org/mozilla/fenix/Config.kt b/app/src/main/java/org/mozilla/fenix/Config.kt new file mode 100644 index 000000000..cc65a4439 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/Config.kt @@ -0,0 +1,24 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix + +enum class ReleaseChannel { + Debug, Nightly, Beta, Release; + + val isReleased: Boolean + get() = when (this) { + Release, Beta, Nightly -> true + else -> false + } +} + +object Config { + val channel = when (BuildConfig.BUILD_TYPE) { + "release" -> ReleaseChannel.Release + "beta" -> ReleaseChannel.Beta + "nightly" -> ReleaseChannel.Nightly + else -> ReleaseChannel.Debug + } +} diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt index b761c6da8..a52b9657f 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt @@ -11,6 +11,8 @@ import com.adjust.sdk.Adjust import com.adjust.sdk.AdjustConfig import com.adjust.sdk.LogLevel import org.mozilla.fenix.BuildConfig +import org.mozilla.fenix.Config + import java.lang.IllegalStateException class AdjustMetricsService(private val application: Application) : MetricsService { @@ -18,7 +20,7 @@ class AdjustMetricsService(private val application: Application) : MetricsServic if ((BuildConfig.ADJUST_TOKEN.isNullOrEmpty())) { Log.i(LOGTAG, "No adjust token defined") - if (BuildConfig.IS_RELEASED) { + if (Config.channel.isReleased) { throw IllegalStateException("No adjust token defined for release build") } diff --git a/app/src/main/java/org/mozilla/fenix/settings/AboutFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/AboutFragment.kt index f84937ac3..21c269293 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/AboutFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/AboutFragment.kt @@ -13,8 +13,9 @@ import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.core.content.pm.PackageInfoCompat import kotlinx.android.synthetic.main.fragment_about.* +import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.R -import org.mozilla.geckoview.BuildConfig +import org.mozilla.geckoview.BuildConfig as GeckoViewBuildConfig class AboutFragment : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -30,7 +31,7 @@ class AboutFragment : Fragment() { val aboutText = try { val packageInfo = requireContext().packageManager.getPackageInfo(requireContext().packageName, 0) val geckoVersion = PackageInfoCompat.getLongVersionCode(packageInfo).toString() + " \uD83E\uDD8E " + - BuildConfig.MOZ_APP_VERSION + "-" + BuildConfig.MOZ_APP_BUILDID + GeckoViewBuildConfig.MOZ_APP_VERSION + "-" + GeckoViewBuildConfig.MOZ_APP_BUILDID String.format( "%s (Build #%s)", packageInfo.versionName, @@ -40,7 +41,7 @@ class AboutFragment : Fragment() { "" } - val buildDate = org.mozilla.fenix.BuildConfig.BUILD_DATE + val buildDate = BuildConfig.BUILD_DATE val content = resources.getString(R.string.about_content, appName) about_text.text = aboutText diff --git a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt index 8df75d5d4..131cc2e0c 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -24,10 +24,10 @@ import mozilla.components.concept.sync.OAuthAccount import mozilla.components.concept.sync.Profile import kotlin.coroutines.CoroutineContext import mozilla.components.service.fxa.FxaUnauthorizedException -import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.FenixApplication import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.BrowserDirection +import org.mozilla.fenix.Config import org.mozilla.fenix.R import org.mozilla.fenix.ext.getPreferenceKey import org.mozilla.fenix.ext.requireComponents @@ -206,7 +206,7 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse preferenceMakeDefaultBrowser?.onPreferenceClickListener = getClickListenerForMakeDefaultBrowser() - if (!BuildConfig.IS_RELEASED) { + if (!Config.channel.isReleased) { preferenceLeakCanary?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> (context?.applicationContext as FenixApplication).toggleLeakCanary(newValue as Boolean) diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index a4fb28fba..8a43b5fe8 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -9,6 +9,7 @@ import android.content.Context.MODE_PRIVATE import android.content.SharedPreferences import mozilla.components.feature.sitepermissions.SitePermissionsRules import org.mozilla.fenix.BuildConfig +import org.mozilla.fenix.Config import org.mozilla.fenix.R import org.mozilla.fenix.ext.getPreferenceKey import java.security.InvalidParameterException @@ -52,7 +53,7 @@ class Settings private constructor(context: Context) { val isCrashReportingEnabled: Boolean get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_crash_reporter), true) && - BuildConfig.CRASH_REPORTING && BuildConfig.IS_RELEASED + BuildConfig.CRASH_REPORTING && Config.channel.isReleased val isRemoteDebuggingEnabled: Boolean get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_remote_debugging), false) diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index df0f8a556..004b92403 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -62,7 +62,7 @@ android:icon="@drawable/ic_info" android:key="@string/pref_key_leakcanary" android:title="@string/preference_leakcanary" - app:isPreferenceVisible="@bool/IS_NOT_RELEASED" /> + app:isPreferenceVisible="@bool/IS_DEBUG" />