SDK-158 Use disabled/no-op version of Nimbus object to eliminate unnecessary Rust call (#17372) r=christian

upstream-sync
jhugman 3 years ago committed by GitHub
parent 7092f8d3eb
commit 7a3524fae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,7 +15,9 @@ import mozilla.components.lib.crash.service.CrashReporterService
import mozilla.components.lib.crash.service.GleanCrashReporterService import mozilla.components.lib.crash.service.GleanCrashReporterService
import mozilla.components.lib.crash.service.MozillaSocorroService import mozilla.components.lib.crash.service.MozillaSocorroService
import mozilla.components.lib.crash.service.SentryService import mozilla.components.lib.crash.service.SentryService
import mozilla.components.service.nimbus.Nimbus import mozilla.components.service.nimbus.NimbusApi
import mozilla.components.service.nimbus.Nimbus as NimbusEnabled
import mozilla.components.service.nimbus.NimbusDisabled
import mozilla.components.service.nimbus.NimbusServerSettings import mozilla.components.service.nimbus.NimbusServerSettings
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config import org.mozilla.fenix.Config
@ -105,32 +107,36 @@ class Analytics(
) )
} }
val experiments by lazyMonitored { val experiments: NimbusApi by lazyMonitored {
val url: String? = BuildConfig.NIMBUS_ENDPOINT if (FeatureFlags.nimbusExperiments) {
val serverSettings = if (!url.isNullOrBlank()) { // Eventually we'll want to use `NimbusDisabled` when we have no NIMBUS_ENDPOINT.
NimbusServerSettings(url = Uri.parse(url)) // but we keep this here to not mix feature flags and how we configure Nimbus.
} else { val url: String? = BuildConfig.NIMBUS_ENDPOINT
null val serverSettings = if (!url.isNullOrBlank()) {
} NimbusServerSettings(url = Uri.parse(url))
Nimbus(context, serverSettings).apply { } else {
if (FeatureFlags.nimbusExperiments) { null
}
NimbusEnabled(context, serverSettings).apply {
// Global opt out state is stored in Nimbus, and shouldn't be toggled to `true` // Global opt out state is stored in Nimbus, and shouldn't be toggled to `true`
// from the app unless the user does so from a UI control. // from the app unless the user does so from a UI control.
// However, the user may have opt-ed out of mako experiments already, so // However, the user may have opt-ed out of mako experiments already, so
// we should respect that setting here. // we should respect that setting here.
val enabled = context.components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) { val enabled =
context.settings().isExperimentationEnabled context.components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
} context.settings().isExperimentationEnabled
}
if (!enabled) { if (!enabled) {
globalUserParticipation = enabled globalUserParticipation = enabled
} }
}
}.apply {
if (FeatureFlags.nimbusExperiments) {
// Nimbus should look after downloading experiment definitions from remote settings // Nimbus should look after downloading experiment definitions from remote settings
// on another thread, and making sure we don't hit the server each time we start. // on another thread, and making sure we don't hit the server each time we start.
updateExperiments() updateExperiments()
} }
} else {
NimbusDisabled()
} }
} }
} }

Loading…
Cancel
Save