From 8dcea3184044e85bc7e23b92ff095c2fc4b0abda Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Thu, 23 Jan 2020 17:06:04 +0100 Subject: [PATCH] [fenix] Closes https://github.com/mozilla-mobile/fenix/issues/7762: Initialize Glean later in Fennec builds. --- app/src/main/java/org/mozilla/fenix/Config.kt | 3 ++ .../org/mozilla/fenix/FenixApplication.kt | 33 +++++++++---------- .../fenix/MigratingFenixApplication.kt | 4 +++ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/Config.kt b/app/src/main/java/org/mozilla/fenix/Config.kt index b10f1b0c7d..db3d19d5e8 100644 --- a/app/src/main/java/org/mozilla/fenix/Config.kt +++ b/app/src/main/java/org/mozilla/fenix/Config.kt @@ -57,6 +57,9 @@ enum class ReleaseChannel { val isFennec: Boolean get() = this in fennecChannels + + val isFenix: Boolean + get() = !isFennec } object Config { diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index 344ad41368..3cda7d9605 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -59,21 +59,22 @@ open class FenixApplication : LocaleAwareApplication() { return } - // We need to always initialize Glean and do it early here. - // It is important that this initialization happens *here* before calling into - // setupInMainProcessOnly() which behaves differently for fenix and fennec builds. - val enableGlean = if (Config.channel.isFennec) { - // We are disabling Glean here because for Fennec builds we may not know yet whether - // we can enable telemetry yet. We first need to migrate the setting from Fennec to - // know the user's choice. The blocking migration in `MigratingFenixApplication` will - // notify glean once the value has been migrated. - false - } else { - // We initialize Glean with telemetry enabled (or disabled) early here so that we do not - // end up loosing data for components that collect telemetry very early. - settings().isTelemetryEnabled + if (Config.channel.isFenix) { + // We need to always initialize Glean and do it early here. + // Note that we are only initializing Glean here for "fenix" builds. "fennec" builds + // will initialize in MigratingFenixApplication because we first need to migrate the + // user's choice from Fennec. + initializeGlean() } - logger.debug("Initializing Glean (uploadEnabled=$enableGlean, isFennec=${Config.channel.isFennec})") + + setupInMainProcessOnly() + } + + protected fun initializeGlean() { + val telemetryEnabled = settings().isTelemetryEnabled + + logger.debug("Initializing Glean (uploadEnabled=$telemetryEnabled, isFennec=${Config.channel.isFennec})") + Glean.initialize( applicationContext = this, configuration = Configuration( @@ -81,10 +82,8 @@ open class FenixApplication : LocaleAwareApplication() { httpClient = ConceptFetchHttpUploader( lazy(LazyThreadSafetyMode.NONE) { components.core.client } )), - uploadEnabled = enableGlean + uploadEnabled = telemetryEnabled ) - - setupInMainProcessOnly() } @CallSuper diff --git a/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt b/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt index 972dfce588..d0a266d71f 100644 --- a/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt +++ b/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt @@ -38,6 +38,10 @@ class MigratingFenixApplication : FenixApplication() { // These migrations need to run before regular initialization happens. migrateBlocking() + // Now that we have migrated from Fennec whether the user wants to enable telemetry we can + // initialize Glean + initializeGlean() + // Fenix application initialization can happen now. super.setupInMainProcessOnly()