Skip to content

Commit

Permalink
SDK-158 Use disabled/no-op version of Nimbus object to eliminate unne…
Browse files Browse the repository at this point in the history
…cessary Rust call (mozilla-mobile#17372) r=christian
  • Loading branch information
jhugman authored and csadilek committed Jan 13, 2021
1 parent 5f080bd commit 44d9c30
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions app/src/main/java/org/mozilla/fenix/components/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.StrictMode
import mozilla.components.lib.crash.CrashReporter
import mozilla.components.lib.crash.service.CrashReporterService
import mozilla.components.lib.crash.service.GleanCrashReporterService
import mozilla.components.lib.crash.service.MozillaSocorroService
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 org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config
Expand Down Expand Up @@ -104,29 +107,35 @@ class Analytics(
)
}

val experiments by lazyMonitored {
val url: String? = BuildConfig.NIMBUS_ENDPOINT
val serverSettings = if (!url.isNullOrBlank()) {
NimbusServerSettings(url = Uri.parse(url))
} else {
null
}
Nimbus(context, serverSettings).apply {
if (FeatureFlags.nimbusExperiments) {
val experiments: NimbusApi by lazyMonitored {
if (FeatureFlags.nimbusExperiments) {
// Eventually we'll want to use `NimbusDisabled` when we have no NIMBUS_ENDPOINT.
// but we keep this here to not mix feature flags and how we configure Nimbus.
val url: String? = BuildConfig.NIMBUS_ENDPOINT
val serverSettings = if (!url.isNullOrBlank()) {
NimbusServerSettings(url = Uri.parse(url))
} else {
null
}

NimbusEnabled(context, serverSettings).apply {
// 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.
// However, the user may have opt-ed out of mako experiments already, so
// we should respect that setting here.
val enabled = context.settings().isExperimentationEnabled
val enabled =
context.components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
context.settings().isExperimentationEnabled
}
if (!enabled) {
globalUserParticipation = enabled
}
context.settings().isExperimentationEnabled = globalUserParticipation

// 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.
updateExperiments()
}
} else {
NimbusDisabled()
}
}
}
Expand Down

0 comments on commit 44d9c30

Please sign in to comment.