Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Close #26041: Re-set TrackingProtectionPolicy after Nimbus SDK is initialized #26228

Merged
merged 2 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/src/main/java/org/mozilla/fenix/FenixApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,28 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
private fun setupNimbusObserver(nimbus: Observable<NimbusInterface.Observer>) {
nimbus.register(object : NimbusInterface.Observer {
override fun onUpdatesApplied(updated: List<EnrolledExperiment>) {
// To workaround a caching bug in Nimbus that appears when we try to query an
// experiment **before** `FxNimbus.initialize` is called we need to set the `api`
// value again so that we can still access the NimbusApi that is wrapped
// in `FxNimbus.initialize.getSdk`.
//
// We set this value here to minimize the race between setting the `api` value and
// the callers of FxNimbus.
// See: https://github.com/mozilla/application-services/issues/5075
FxNimbus.api = components.analytics.experiments
jonalmeida marked this conversation as resolved.
Show resolved Hide resolved
onNimbusStartupAndUpdate()
}
})
}

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()
jonalmeida marked this conversation as resolved.
Show resolved Hide resolved

val settings = settings()
if (FeatureFlags.messagingFeature && settings.isExperimentationEnabled) {
components.appStore.dispatch(AppAction.MessagingAction.Restore)
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,8 @@ class Settings(private val appContext: Context) : PreferencesHolder {
true
)

val enabledTotalCookieProtection: Boolean by lazy {
FxNimbus.features.engineSettings.value().totalCookieProtectionEnabled
}
val enabledTotalCookieProtection: Boolean
get() = FxNimbus.features.engineSettings.value().totalCookieProtectionEnabled
jonalmeida marked this conversation as resolved.
Show resolved Hide resolved

val blockCookiesSelectionInCustomTrackingProtection by stringPreference(
appContext.getPreferenceKey(R.string.pref_key_tracking_protection_custom_cookies_select),
Expand Down