|
|
|
@ -50,7 +50,6 @@ import mozilla.components.service.glean.net.ConceptFetchHttpUploader
|
|
|
|
|
import mozilla.components.support.base.facts.register
|
|
|
|
|
import mozilla.components.support.base.log.Log
|
|
|
|
|
import mozilla.components.support.base.log.logger.Logger
|
|
|
|
|
import mozilla.components.support.base.observer.Observable
|
|
|
|
|
import mozilla.components.support.ktx.android.content.isMainProcess
|
|
|
|
|
import mozilla.components.support.ktx.android.content.runOnlyInMainProcess
|
|
|
|
|
import mozilla.components.support.locale.LocaleAwareApplication
|
|
|
|
@ -59,8 +58,6 @@ import mozilla.components.support.rusthttp.RustHttpConfig
|
|
|
|
|
import mozilla.components.support.rustlog.RustLog
|
|
|
|
|
import mozilla.components.support.utils.logElapsedTime
|
|
|
|
|
import mozilla.components.support.webextensions.WebExtensionSupport
|
|
|
|
|
import org.mozilla.experiments.nimbus.NimbusInterface
|
|
|
|
|
import org.mozilla.experiments.nimbus.internal.EnrolledExperiment
|
|
|
|
|
import org.mozilla.fenix.GleanMetrics.Addons
|
|
|
|
|
import org.mozilla.fenix.GleanMetrics.AndroidAutofill
|
|
|
|
|
import org.mozilla.fenix.GleanMetrics.CustomizeHome
|
|
|
|
@ -134,6 +131,10 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We can initialize Nimbus before Glean because Glean will queue messages
|
|
|
|
|
// before it's initialized.
|
|
|
|
|
initializeNimbus()
|
|
|
|
|
|
|
|
|
|
// We need to always initialize Glean and do it early here.
|
|
|
|
|
initializeGlean()
|
|
|
|
|
|
|
|
|
@ -201,7 +202,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
|
|
|
|
|
|
|
|
|
|
run {
|
|
|
|
|
// Attention: Do not invoke any code from a-s in this scope.
|
|
|
|
|
val megazordSetup = setupMegazord()
|
|
|
|
|
val megazordSetup = finishSetupMegazord()
|
|
|
|
|
|
|
|
|
|
setDayNightTheme()
|
|
|
|
|
components.strictMode.enableStrictMode(true)
|
|
|
|
@ -222,6 +223,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
|
|
|
|
|
}
|
|
|
|
|
restoreBrowserState()
|
|
|
|
|
restoreDownloads()
|
|
|
|
|
restoreMessaging()
|
|
|
|
|
|
|
|
|
|
// Just to make sure it is impossible for any application-services pieces
|
|
|
|
|
// to invoke parts of itself that require complete megazord initialization
|
|
|
|
@ -415,6 +417,15 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
|
|
|
|
|
.install(this)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected open fun initializeNimbus() {
|
|
|
|
|
beginSetupMegazord()
|
|
|
|
|
|
|
|
|
|
// This lazily constructs the Nimbus object…
|
|
|
|
|
val nimbus = components.analytics.experiments
|
|
|
|
|
// … which we then can populate the feature configuration.
|
|
|
|
|
FxNimbus.initialize { nimbus }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initiate Megazord sequence! Megazord Battle Mode!
|
|
|
|
|
*
|
|
|
|
@ -424,54 +435,40 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
|
|
|
|
|
* Documentation on what megazords are, and why they're needed:
|
|
|
|
|
* - https://github.com/mozilla/application-services/blob/master/docs/design/megazords.md
|
|
|
|
|
* - https://mozilla.github.io/application-services/docs/applications/consuming-megazord-libraries.html
|
|
|
|
|
*
|
|
|
|
|
* This is the initialization of the megazord without setting up networking, i.e. needing the
|
|
|
|
|
* engine for networking. This should do the minimum work necessary as it is done on the main
|
|
|
|
|
* thread, early in the app startup sequence.
|
|
|
|
|
*/
|
|
|
|
|
@OptIn(DelicateCoroutinesApi::class) // GlobalScope usage
|
|
|
|
|
private fun setupMegazord(): Deferred<Unit> {
|
|
|
|
|
private fun beginSetupMegazord() {
|
|
|
|
|
// Note: Megazord.init() must be called as soon as possible ...
|
|
|
|
|
Megazord.init()
|
|
|
|
|
// Give the generated FxNimbus a closure to lazily get the Nimbus object
|
|
|
|
|
FxNimbus.initialize { components.analytics.experiments }
|
|
|
|
|
return GlobalScope.async(Dispatchers.IO) {
|
|
|
|
|
|
|
|
|
|
initializeRustErrors(components.analytics.crashReporter)
|
|
|
|
|
// ... but RustHttpConfig.setClient() and RustLog.enable() can be called later.
|
|
|
|
|
RustHttpConfig.setClient(lazy { components.core.client })
|
|
|
|
|
|
|
|
|
|
// Once application-services has switched to using the new
|
|
|
|
|
// error reporting system, RustLog shouldn't input a CrashReporter
|
|
|
|
|
// anymore.
|
|
|
|
|
// (https://github.com/mozilla/application-services/issues/4981).
|
|
|
|
|
RustLog.enable(components.analytics.crashReporter)
|
|
|
|
|
// We want to ensure Nimbus is initialized as early as possible so we can
|
|
|
|
|
// experiment on features close to startup.
|
|
|
|
|
// But we need viaduct (the RustHttp client) to be ready before we do.
|
|
|
|
|
components.analytics.experiments.apply {
|
|
|
|
|
setupNimbusObserver(this)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun setupNimbusObserver(nimbus: Observable<NimbusInterface.Observer>) {
|
|
|
|
|
nimbus.register(
|
|
|
|
|
object : NimbusInterface.Observer {
|
|
|
|
|
override fun onUpdatesApplied(updated: List<EnrolledExperiment>) {
|
|
|
|
|
onNimbusStartupAndUpdate()
|
|
|
|
|
@OptIn(DelicateCoroutinesApi::class) // GlobalScope usage
|
|
|
|
|
private fun finishSetupMegazord(): Deferred<Unit> {
|
|
|
|
|
return GlobalScope.async(Dispatchers.IO) {
|
|
|
|
|
RustHttpConfig.setClient(lazy { components.core.client })
|
|
|
|
|
|
|
|
|
|
// Now viaduct (the RustHttp client) is initialized we can ask Nimbus to fetch
|
|
|
|
|
// experiments recipes from the server.
|
|
|
|
|
components.analytics.experiments.fetchExperiments()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun onNimbusStartupAndUpdate() {
|
|
|
|
|
// When Nimbus has successfully started up, we can apply our engine settings experiment.
|
|
|
|
|
// Any previous value that was set on the engine will be overridden from those set in
|
|
|
|
|
// Core.Engine.DefaultSettings.
|
|
|
|
|
// NOTE ⚠️: Any startup experiment we want to run needs to have it's value re-applied here.
|
|
|
|
|
components.core.engine.settings.trackingProtectionPolicy =
|
|
|
|
|
components.core.trackingProtectionPolicyFactory.createTrackingProtectionPolicy()
|
|
|
|
|
|
|
|
|
|
val settings = settings()
|
|
|
|
|
if (settings.isExperimentationEnabled) {
|
|
|
|
|
private fun restoreMessaging() {
|
|
|
|
|
if (settings().isExperimentationEnabled) {
|
|
|
|
|
components.appStore.dispatch(AppAction.MessagingAction.Restore)
|
|
|
|
|
}
|
|
|
|
|
reportHomeScreenSectionMetrics(settings)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onTrimMemory(level: Int) {
|
|
|
|
|