From a2984e6863cb16dfafb6573e81979958cd27d3a8 Mon Sep 17 00:00:00 2001 From: Travis Long Date: Wed, 23 Jun 2021 11:56:51 -0500 Subject: [PATCH] [SDK-279] Adds a way to switch to the "preview" collection in Nimbus This adds a toggle/switch to the debug settings menu that causes Nimbus to use the "preview" collection rather than the "main" collection when it initializes. Since it is only applied during init, it does require a restart in order to take effect. --- .../main/java/org/mozilla/fenix/experiments/NimbusSetup.kt | 6 +++++- .../org/mozilla/fenix/settings/SecretSettingsFragment.kt | 6 ++++++ app/src/main/java/org/mozilla/fenix/utils/Settings.kt | 5 +++++ app/src/main/res/values/preference_keys.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/secret_settings_preferences.xml | 5 +++++ 6 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/experiments/NimbusSetup.kt b/app/src/main/java/org/mozilla/fenix/experiments/NimbusSetup.kt index e5917d2df3..e2f14e671e 100644 --- a/app/src/main/java/org/mozilla/fenix/experiments/NimbusSetup.kt +++ b/app/src/main/java/org/mozilla/fenix/experiments/NimbusSetup.kt @@ -31,7 +31,11 @@ fun createNimbus(context: Context, url: String?): NimbusApi { // Eventually we'll want to use `NimbusDisabled` when we have no NIMBUS_ENDPOINT. // but we keep this here to not mix feature flags and how we configure Nimbus. val serverSettings = if (!url.isNullOrBlank()) { - NimbusServerSettings(url = Uri.parse(url)) + if (context.settings().nimbusUsePreview) { + NimbusServerSettings(url = Uri.parse(url), collection = "nimbus-preview") + } else { + NimbusServerSettings(url = Uri.parse(url)) + } } else { null } diff --git a/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt index ba967cc0df..e4903f27c4 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt @@ -41,5 +41,11 @@ class SecretSettingsFragment : PreferenceFragmentCompat() { } } } + + requirePreference(R.string.pref_key_nimbus_use_preview).apply { + isVisible = true + isChecked = context.settings().nimbusUsePreview + onPreferenceChangeListener = SharedPreferenceUpdater() + } } } 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 fd87cea445..7c27923227 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -353,6 +353,11 @@ class Settings(private val appContext: Context) : PreferencesHolder { default = false ) + var nimbusUsePreview by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_nimbus_use_preview), + default = false + ) + /** * Indicates the last time when the user was interacting with the [BrowserFragment], * This is useful to determine if the user has to start on the [HomeFragment] diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 1ad043092b..2861fe18cf 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -284,4 +284,5 @@ pref_key_show_address_feature pref_key_nimbus_experiments + pref_key_nimbus_use_preview diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eea4bc6332..2c952a08ad 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1764,5 +1764,6 @@ Close + Use Nimbus Preview Collection (requires restart) diff --git a/app/src/main/res/xml/secret_settings_preferences.xml b/app/src/main/res/xml/secret_settings_preferences.xml index 00cad6fe82..4492a6d160 100644 --- a/app/src/main/res/xml/secret_settings_preferences.xml +++ b/app/src/main/res/xml/secret_settings_preferences.xml @@ -15,4 +15,9 @@ android:title="@string/preferences_debug_settings_allow_third_party_root_certs" android:summary="@string/preferences_debug_settings_allow_third_party_root_certs_summary" app:iconSpaceReserved="false" /> +