Pier Angelo Vendrame pushed to branch tor-browser-96.3.0-11.0-1 at The Tor Project / Applications / fenix
Commits:
-
9431b234
by Pier Angelo Vendrame at 2022-05-20T19:45:26+02:00
3 changed files:
- app/src/main/java/org/mozilla/fenix/FenixApplication.kt
- app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt
- app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt
Changes:
... | ... | @@ -151,6 +151,10 @@ open class FenixApplication : LocaleAwareApplication(), Provider { |
151 | 151 | @OptIn(DelicateCoroutinesApi::class) // GlobalScope usage
|
152 | 152 | protected open fun initializeGlean() {
|
153 | 153 | val telemetryEnabled = settings().isTelemetryEnabled
|
154 | + if (!telemetryEnabled) {
|
|
155 | + logger.debug("Preventing Glean from initializing, since telemetry is disabled")
|
|
156 | + return
|
|
157 | + }
|
|
154 | 158 | |
155 | 159 | logger.debug("Initializing Glean (uploadEnabled=$telemetryEnabled, isFennec=${Config.channel.isFennec})")
|
156 | 160 |
... | ... | @@ -8,6 +8,7 @@ import android.content.Context |
8 | 8 | import mozilla.components.service.glean.Glean
|
9 | 9 | import mozilla.components.service.glean.private.NoExtraKeys
|
10 | 10 | import mozilla.components.support.base.log.logger.Logger
|
11 | +import org.mozilla.fenix.BuildConfig
|
|
11 | 12 | import org.mozilla.fenix.GleanMetrics.Addons
|
12 | 13 | import org.mozilla.fenix.GleanMetrics.AndroidAutofill
|
13 | 14 | import org.mozilla.fenix.GleanMetrics.AndroidKeystoreExperiment
|
... | ... | @@ -85,6 +86,9 @@ private class EventWrapper<T : Enum<T>>( |
85 | 86 | }
|
86 | 87 | |
87 | 88 | fun track(event: Event) {
|
89 | + if (BuildConfig.DATA_COLLECTION_DISABLED) {
|
|
90 | + return
|
|
91 | + }
|
|
88 | 92 | val extras = if (keyMapper != null) {
|
89 | 93 | event.extras?.mapKeys { (key) ->
|
90 | 94 | keyMapper.invoke(key.toString().asCamelCase())
|
... | ... | @@ -938,6 +942,12 @@ class GleanMetricsService( |
938 | 942 | private val installationPing = FirstSessionPing(context)
|
939 | 943 | |
940 | 944 | override fun start() {
|
945 | + if (BuildConfig.DATA_COLLECTION_DISABLED) {
|
|
946 | + Logger.debug("Data collection is disabled, not initializing Glean.")
|
|
947 | + initialized = true
|
|
948 | + return
|
|
949 | + }
|
|
950 | + |
|
941 | 951 | logger.debug("Enabling Glean.")
|
942 | 952 | // Initialization of Glean already happened in FenixApplication.
|
943 | 953 | Glean.setUploadEnabled(true)
|
... | ... | @@ -965,10 +975,12 @@ class GleanMetricsService( |
965 | 975 | }
|
966 | 976 | |
967 | 977 | override fun track(event: Event) {
|
968 | - event.wrapper?.track(event)
|
|
978 | + if (!BuildConfig.DATA_COLLECTION_DISABLED) {
|
|
979 | + event.wrapper?.track(event)
|
|
980 | + }
|
|
969 | 981 | }
|
970 | 982 | |
971 | 983 | override fun shouldTrack(event: Event): Boolean {
|
972 | - return event.wrapper != null
|
|
984 | + return !BuildConfig.DATA_COLLECTION_DISABLED && event.wrapper != null
|
|
973 | 985 | }
|
974 | 986 | } |
... | ... | @@ -152,7 +152,11 @@ internal class ReleaseMetricController( |
152 | 152 | |
153 | 153 | private fun isInitialized(type: MetricServiceType): Boolean = initialized.contains(type)
|
154 | 154 | |
155 | - private fun isTelemetryEnabled(@Suppress("UNUSED_PARAMETER") type: MetricServiceType): Boolean = false
|
|
155 | + private fun isTelemetryEnabled(type: MetricServiceType): Boolean =
|
|
156 | + !BuildConfig.DATA_COLLECTION_DISABLED && when (type) {
|
|
157 | + MetricServiceType.Data -> isDataTelemetryEnabled()
|
|
158 | + MetricServiceType.Marketing -> isMarketingDataTelemetryEnabled()
|
|
159 | + }
|
|
156 | 160 | |
157 | 161 | @Suppress("LongMethod", "MaxLineLength")
|
158 | 162 | private fun Fact.toEvent(): Event? = when {
|