From 91b280e5f073e2c2d5d34a719420b2e31f27fa8d Mon Sep 17 00:00:00 2001 From: vladikoff Date: Wed, 29 May 2019 18:33:38 -0400 Subject: [PATCH] [fenix] Add application-services fretboard feature flags --- CHANGELOG.md | 1 + .../main/java/org/mozilla/fenix/Experiments.kt | 8 ++++++-- .../main/java/org/mozilla/fenix/HomeActivity.kt | 2 +- .../fenix/components/BackgroundServices.kt | 15 ++++++++++++--- .../fenix/settings/AccountSettingsFragment.kt | 16 +++++++++------- .../mozilla/fenix/settings/TurnOnSyncFragment.kt | 7 +++++++ 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4331e11c75..242f6564c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - #2903 - Fixed crash when trying to rate the app on a devices without the play store app. - #2419 - Adds a deletion state to the history component - #1570 - Enables the opening of links by other apps. Disabled in #3359. +- #3200 - Adds application-services fretboard feature flags for FxA and Sync. ### Changed - #2673 - Fixed can't upload files using third party apps from the file manager. diff --git a/app/src/main/java/org/mozilla/fenix/Experiments.kt b/app/src/main/java/org/mozilla/fenix/Experiments.kt index dea0116381..2fe8355087 100644 --- a/app/src/main/java/org/mozilla/fenix/Experiments.kt +++ b/app/src/main/java/org/mozilla/fenix/Experiments.kt @@ -10,11 +10,15 @@ import mozilla.components.service.fretboard.ExperimentDescriptor const val EXPERIMENTS_JSON_FILENAME = "experiments.json" const val EXPERIMENTS_BASE_URL = "https://settings.prod.mozaws.net/v1" const val EXPERIMENTS_BUCKET_NAME = "main" -// TODO Change this after fenix-experiments is created -const val EXPERIMENTS_COLLECTION_NAME = "focus-experiments" +// collection name below, see https://bugzilla.mozilla.org/show_bug.cgi?id=1523395 for ownership details +const val EXPERIMENTS_COLLECTION_NAME = "fenix-experiments" object Experiments { val AATestDescriptor = ExperimentDescriptor("AAtest") + // application services flag to disable the Firefox Sync syncManager + val asFeatureSyncDisabled = ExperimentDescriptor("asFeatureSyncDisabled") + // application services flag to disable Firefox Accounts pairing button. + val asFeatureFxAPairingDisabled = ExperimentDescriptor("asFeatureFxAPairingDisabled") } val Context.app: FenixApplication diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 98fee05bbd..bfff887158 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -115,7 +115,7 @@ open class HomeActivity : AppCompatActivity() { components.backgroundServices.accountManager.initAsync().await() // If we're authenticated, kick-off a sync and a device state refresh. components.backgroundServices.accountManager.authenticatedAccount()?.let { - components.backgroundServices.syncManager.syncNow(startup = true) + components.backgroundServices.syncManager?.syncNow(startup = true) it.deviceConstellation().refreshDeviceStateAsync().await() } } diff --git a/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt b/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt index 131f78626b..928f0f4012 100644 --- a/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt +++ b/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt @@ -6,6 +6,7 @@ package org.mozilla.fenix.components import android.content.Context import androidx.lifecycle.ProcessLifecycleOwner +import androidx.work.WorkManager import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -21,7 +22,9 @@ import mozilla.components.service.fxa.Config import mozilla.components.service.fxa.manager.DeviceTuple import mozilla.components.service.fxa.manager.FxaAccountManager import mozilla.components.support.base.log.logger.Logger +import org.mozilla.fenix.Experiments import org.mozilla.fenix.R +import org.mozilla.fenix.isInExperiment import org.mozilla.fenix.test.Mockable /** @@ -53,9 +56,15 @@ class BackgroundServices( GlobalSyncableStoreProvider.configureStore("bookmarks" to bookmarkStorage) } - val syncManager = BackgroundSyncManager("https://identity.mozilla.com/apps/oldsync").also { - it.addStore("history") - it.addStore("bookmarks") + // if sync has been turned off on the server then make `syncManager` null + val syncManager = if (context.isInExperiment(Experiments.asFeatureSyncDisabled)) { + WorkManager.getInstance().cancelUniqueWork("Periodic") + null + } else { + BackgroundSyncManager("https://identity.mozilla.com/apps/oldsync").also { + it.addStore("history") + it.addStore("bookmarks") + } } private val deviceEventObserver = object : DeviceEventsObserver { diff --git a/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt index b73298899d..d6fe662a0a 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt @@ -108,11 +108,13 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope { // Current sync state updateLastSyncedTimePref(context!!, preferenceSyncNow) - if (requireComponents.backgroundServices.syncManager.isSyncRunning()) { - preferenceSyncNow.title = getString(R.string.sync_syncing_in_progress) - preferenceSyncNow.isEnabled = false - } else { - preferenceSyncNow.isEnabled = true + requireComponents.backgroundServices.syncManager?.let { + if (it.isSyncRunning()) { + preferenceSyncNow.title = getString(R.string.sync_syncing_in_progress) + preferenceSyncNow.isEnabled = false + } else { + preferenceSyncNow.isEnabled = true + } } } @@ -133,7 +135,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope { // NB: ObserverRegistry will take care of cleaning up internal references to 'observer' and // 'owner' when appropriate. - requireComponents.backgroundServices.syncManager.register(syncStatusObserver, owner = this, autoPause = true) + requireComponents.backgroundServices.syncManager?.register(syncStatusObserver, owner = this, autoPause = true) } private fun getClickListenerForSignOut(): Preference.OnPreferenceClickListener { @@ -150,7 +152,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope { return Preference.OnPreferenceClickListener { // Trigger a sync. requireComponents.analytics.metrics.track(Event.SyncAccountSyncNow) - requireComponents.backgroundServices.syncManager.syncNow() + requireComponents.backgroundServices.syncManager?.syncNow() // Poll for device events. launch { accountManager.authenticatedAccount() diff --git a/app/src/main/java/org/mozilla/fenix/settings/TurnOnSyncFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/TurnOnSyncFragment.kt index ced7d35ee4..012505076a 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/TurnOnSyncFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/TurnOnSyncFragment.kt @@ -14,11 +14,13 @@ import mozilla.components.concept.sync.AccountObserver import mozilla.components.concept.sync.OAuthAccount import mozilla.components.concept.sync.Profile import mozilla.components.support.ktx.android.content.hasCamera +import org.mozilla.fenix.Experiments import org.mozilla.fenix.R import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.getPreferenceKey import org.mozilla.fenix.ext.requireComponents +import org.mozilla.fenix.isInExperiment @SuppressWarnings("TooManyFunctions") class TurnOnSyncFragment : PreferenceFragmentCompat(), AccountObserver { @@ -57,6 +59,11 @@ class TurnOnSyncFragment : PreferenceFragmentCompat(), AccountObserver { preferenceNewAccount?.onPreferenceClickListener = getClickListenerForCreateAccount() preferencePairSignIn?.onPreferenceClickListener = getClickListenerForPairing() preferencePairSignIn?.isVisible = context?.hasCamera() ?: true + + // if FxA pairing has been turned off on the server + if (context?.isInExperiment(Experiments.asFeatureFxAPairingDisabled)!!) { + preferencePairSignIn?.isVisible = false + } } private fun getClickListenerForSignIn(): Preference.OnPreferenceClickListener {