From 9f3faa43fe477baf602d5a423f53d78e3a95b75f Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Fri, 7 Feb 2020 17:46:51 -0800 Subject: [PATCH] For #4674 - Adds marketing data as a collection choice --- .../fenix/components/metrics/AdjustMetricsService.kt | 2 ++ .../fenix/components/metrics/LeanplumMetricsService.kt | 3 +++ .../org/mozilla/fenix/settings/DataChoicesFragment.kt | 9 +++++++++ app/src/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 +++++ 6 files changed, 25 insertions(+) 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 4fcbe4aa0..f1f6aa019 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 @@ -18,6 +18,8 @@ import org.mozilla.fenix.ext.settings class AdjustMetricsService(private val application: Application) : MetricsService { override fun start() { + if (!application.settings().isMarketingTelemetryEnabled) return + if ((BuildConfig.ADJUST_TOKEN.isNullOrBlank())) { Log.i(LOGTAG, "No adjust token defined") diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt index b265e5eda..d2e5ba3fe 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt @@ -56,6 +56,8 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ private val token = Token(LeanplumId, LeanplumToken) override fun start() { + if (!application.settings().isMarketingTelemetryEnabled) return + val applicationSetLocale = LocaleManager.getCurrentLocale(application) val currentLocale = when (applicationSetLocale != null) { true -> applicationSetLocale.isO3Language @@ -96,6 +98,7 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ } override fun stop() { + if (application.settings().isMarketingTelemetryEnabled) return // As written in LeanPlum SDK documentation, "This prevents Leanplum from communicating with the server." // as this "isTestMode" flag is checked before LeanPlum SDK does anything. // Also has the benefit effect of blocking the display of already downloaded messages. 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 c42b61fa7..72fd05104 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt @@ -51,6 +51,15 @@ class DataChoicesFragment : PreferenceFragmentCompat() { onPreferenceChangeListener = SharedPreferenceUpdater() } + findPreference(getPreferenceKey(R.string.pref_key_telemetry))?.apply { + isChecked = context.settings().isMarketingTelemetryEnabled + + val appName = context.getString(R.string.app_name) + summary = context.getString(R.string.preferences_marketing_data_description, appName) + + onPreferenceChangeListener = SharedPreferenceUpdater() + } + findPreference(getPreferenceKey(R.string.pref_key_experimentation))?.apply { isChecked = context.settings().isExperimentationEnabled isVisible = Config.channel.isReleaseOrBeta 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 9309379be..b92397958 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -122,6 +122,11 @@ class Settings private constructor( default = true ) + val isMarketingTelemetryEnabled by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_marketing_telemetry), + default = true + ) + val isExperimentationEnabled by booleanPreference( appContext.getPreferenceKey(R.string.pref_key_experimentation), default = true diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index c41013781..21bf3082e 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -49,6 +49,7 @@ pref_key_telemetry + pref_key_marketing_telemetry pref_key_crash_reporter pref_key_mozilla_location_service pref_key_fenix_health_report diff --git a/app/src/main/res/xml/data_choices_preferences.xml b/app/src/main/res/xml/data_choices_preferences.xml index 3bb80773f..72c1d7fcc 100644 --- a/app/src/main/res/xml/data_choices_preferences.xml +++ b/app/src/main/res/xml/data_choices_preferences.xml @@ -9,6 +9,11 @@ android:summary="@string/preferences_usage_data_description" android:title="@string/preference_usage_data" app:iconSpaceReserved="false" /> +