From d3cbb93b887ca883629375aae03d4a58839a8ad4 Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Tue, 27 Aug 2019 15:56:16 -0400 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/4295 - Adds Experiments Pref to Data Collection Settings (https://github.com/mozilla-mobile/fenix/pull/4915) --- .../main/java/org/mozilla/fenix/FenixApplication.kt | 12 +++++++----- .../mozilla/fenix/settings/DataChoicesFragment.kt | 5 +++++ .../main/java/org/mozilla/fenix/utils/Settings.kt | 5 +++++ app/src/main/res/values/preference_keys.xml | 1 + app/src/main/res/xml/data_choices_preferences.xml | 5 +++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index ab9ee7db2f..1772ed25cf 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -74,12 +74,14 @@ open class FenixApplication : Application() { experimentLoader = loadExperiments() // Enable the service-experiments component - Experiments.initialize( - applicationContext, - mozilla.components.service.experiments.Configuration( - httpClient = lazy(LazyThreadSafetyMode.NONE) { components.core.client } + if (Settings.getInstance(this).isExperimentationEnabled) { + Experiments.initialize( + applicationContext, + mozilla.components.service.experiments.Configuration( + httpClient = lazy(LazyThreadSafetyMode.NONE) { components.core.client } + ) ) - ) + } // When the `fenix-test-2019-08-05` experiment is active, record its branch in Glean // telemetry. This will be used to validate that the experiment system correctly enrolls diff --git a/app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt index 78f18813e1..31d2cfb308 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt @@ -63,5 +63,10 @@ class DataChoicesFragment : PreferenceFragmentCompat() { onPreferenceChangeListener = SharedPreferenceUpdater() } + + findPreference(getPreferenceKey(R.string.pref_key_experimentation))?.apply { + isChecked = Settings.getInstance(context).isExperimentationEnabled + 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 f7cbb46410..057cba83b7 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -90,6 +90,11 @@ class Settings private constructor( default = true ) + val isExperimentationEnabled by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_experimentation), + default = true + ) + val shouldAutoBounceQuickActionSheet: Boolean get() = autoBounceQuickActionSheetCount < autoBounceMaximumCount diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 74af3953ae..da1a71a8de 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -27,6 +27,7 @@ pref_key_theme pref_key_leakcanary pref_key_remote_debugging + pref_key_experimentation pref_key_telemetry diff --git a/app/src/main/res/xml/data_choices_preferences.xml b/app/src/main/res/xml/data_choices_preferences.xml index 4a3783d69c..3bb80773fd 100644 --- a/app/src/main/res/xml/data_choices_preferences.xml +++ b/app/src/main/res/xml/data_choices_preferences.xml @@ -9,4 +9,9 @@ android:summary="@string/preferences_usage_data_description" android:title="@string/preference_usage_data" app:iconSpaceReserved="false" /> +