1
0
Fork 0

FxA WebChannels integration

This patch includes:
- WebChannels support enabled by default, with ability to disable it via remote flag
- expanded FxA telemetry (closes #4971)

Co-authored-by: Arturo Mejia <arturomejiamarmol@gmail.com>
master
Grisha Kruglov 2019-08-22 16:56:13 -07:00 committed by Emily Kager
parent 8f97d247a6
commit a4097cd380
6 changed files with 58 additions and 13 deletions

View File

@ -25,6 +25,7 @@ import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.session.Session import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.engine.EngineView import mozilla.components.concept.engine.EngineView
import mozilla.components.service.fxa.sync.SyncReason
import mozilla.components.support.base.feature.BackHandler import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.ktx.kotlin.isUrl import mozilla.components.support.ktx.kotlin.isUrl
import mozilla.components.support.ktx.kotlin.toNormalizedUrl import mozilla.components.support.ktx.kotlin.toNormalizedUrl
@ -112,7 +113,7 @@ open class HomeActivity : AppCompatActivity() {
accountManager.initAsync().await() accountManager.initAsync().await()
// If we're authenticated, kick-off a sync and a device state refresh. // If we're authenticated, kick-off a sync and a device state refresh.
accountManager.authenticatedAccount()?.let { accountManager.authenticatedAccount()?.let {
accountManager.syncNowAsync(startup = true, debounce = true) accountManager.syncNowAsync(SyncReason.Startup, debounce = true)
it.deviceConstellation().pollForEventsAsync().await() it.deviceConstellation().pollForEventsAsync().await()
} }
} }

View File

@ -31,6 +31,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import mozilla.components.browser.session.Session import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager import mozilla.components.browser.session.SessionManager
import mozilla.components.feature.accounts.FxaCapability
import mozilla.components.feature.accounts.FxaWebChannelFeature import mozilla.components.feature.accounts.FxaWebChannelFeature
import mozilla.components.feature.app.links.AppLinksFeature import mozilla.components.feature.app.links.AppLinksFeature
import mozilla.components.feature.contextmenu.ContextMenuFeature import mozilla.components.feature.contextmenu.ContextMenuFeature
@ -380,7 +381,8 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
customTabSessionId, customTabSessionId,
requireComponents.core.engine, requireComponents.core.engine,
requireComponents.core.sessionManager, requireComponents.core.sessionManager,
requireComponents.backgroundServices.accountManager requireComponents.backgroundServices.accountManager,
setOf(FxaCapability.CHOOSE_WHAT_TO_SYNC)
), ),
owner = this, owner = this,
view = view view = view

View File

@ -94,7 +94,7 @@ class BackgroundServices(
val syncConfig = if (context.isInExperiment(Experiments.asFeatureSyncDisabled)) { val syncConfig = if (context.isInExperiment(Experiments.asFeatureSyncDisabled)) {
null null
} else { } else {
SyncConfig(setOf(SyncEngine.HISTORY, SyncEngine.BOOKMARKS), syncPeriodInMinutes = 240L) // four hours SyncConfig(setOf(SyncEngine.History, SyncEngine.Bookmarks), syncPeriodInMinutes = 240L) // four hours
} }
private val pushService by lazy { FirebasePush() } private val pushService by lazy { FirebasePush() }
@ -103,8 +103,8 @@ class BackgroundServices(
init { init {
// Make the "history" and "bookmark" stores accessible to workers spawned by the sync manager. // Make the "history" and "bookmark" stores accessible to workers spawned by the sync manager.
GlobalSyncableStoreProvider.configureStore(SyncEngine.HISTORY to historyStorage) GlobalSyncableStoreProvider.configureStore(SyncEngine.History to historyStorage)
GlobalSyncableStoreProvider.configureStore(SyncEngine.BOOKMARKS to bookmarkStorage) GlobalSyncableStoreProvider.configureStore(SyncEngine.Bookmarks to bookmarkStorage)
} }
private val deviceEventObserver = object : DeviceEventsObserver { private val deviceEventObserver = object : DeviceEventsObserver {

View File

@ -11,6 +11,7 @@ import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.preference.CheckBoxPreference
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
@ -22,13 +23,17 @@ import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.ConstellationState import mozilla.components.concept.sync.ConstellationState
import mozilla.components.concept.sync.DeviceConstellationObserver import mozilla.components.concept.sync.DeviceConstellationObserver
import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.service.fxa.SyncEngine
import mozilla.components.service.fxa.manager.FxaAccountManager import mozilla.components.service.fxa.manager.FxaAccountManager
import mozilla.components.service.fxa.manager.SyncEnginesStorage
import mozilla.components.service.fxa.sync.SyncReason
import mozilla.components.service.fxa.sync.SyncStatusObserver import mozilla.components.service.fxa.sync.SyncStatusObserver
import mozilla.components.service.fxa.sync.getLastSynced import mozilla.components.service.fxa.sync.getLastSynced
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.StoreProvider import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getPreferenceKey import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
@ -147,6 +152,27 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
} }
} }
// Make sure out sync engine checkboxes are up-to-date.
updateSyncEngineStates()
val historyNameKey = getPreferenceKey(R.string.pref_key_sync_history)
findPreference<CheckBoxPreference>(historyNameKey)?.apply {
setOnPreferenceChangeListener { _, newValue ->
SyncEnginesStorage(context).setStatus(SyncEngine.History, newValue as Boolean)
context.components.backgroundServices.accountManager.syncNowAsync(SyncReason.EngineChange)
true
}
}
val bookmarksNameKey = getPreferenceKey(R.string.pref_key_sync_bookmarks)
findPreference<CheckBoxPreference>(bookmarksNameKey)?.apply {
setOnPreferenceChangeListener { _, newValue ->
SyncEnginesStorage(context).setStatus(SyncEngine.Bookmarks, newValue as Boolean)
context.components.backgroundServices.accountManager.syncNowAsync(SyncReason.EngineChange)
true
}
}
deviceConstellation?.registerDeviceObserver(deviceConstellationObserver, owner = this, autoPause = true) deviceConstellation?.registerDeviceObserver(deviceConstellationObserver, owner = this, autoPause = true)
// NB: ObserverRegistry will take care of cleaning up internal references to 'observer' and // NB: ObserverRegistry will take care of cleaning up internal references to 'observer' and
@ -156,11 +182,25 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
) )
} }
private fun updateSyncEngineStates() {
val syncEnginesStatus = SyncEnginesStorage(context!!).getStatus()
val bookmarksNameKey = getPreferenceKey(R.string.pref_key_sync_bookmarks)
findPreference<CheckBoxPreference>(bookmarksNameKey)?.apply {
isEnabled = syncEnginesStatus.containsKey(SyncEngine.Bookmarks)
isChecked = syncEnginesStatus.getOrElse(SyncEngine.Bookmarks) { true }
}
val historyNameKey = getPreferenceKey(R.string.pref_key_sync_history)
findPreference<CheckBoxPreference>(historyNameKey)?.apply {
isEnabled = syncEnginesStatus.containsKey(SyncEngine.History)
isChecked = syncEnginesStatus.getOrElse(SyncEngine.History) { true }
}
}
private fun syncNow() { private fun syncNow() {
lifecycleScope.launch { lifecycleScope.launch {
requireComponents.analytics.metrics.track(Event.SyncAccountSyncNow) requireComponents.analytics.metrics.track(Event.SyncAccountSyncNow)
// Trigger a sync. // Trigger a sync.
requireComponents.backgroundServices.accountManager.syncNowAsync().await() requireComponents.backgroundServices.accountManager.syncNowAsync(SyncReason.User).await()
// Poll for device events & update devices. // Poll for device events & update devices.
accountManager.authenticatedAccount() accountManager.authenticatedAccount()
?.deviceConstellation()?.run { ?.deviceConstellation()?.run {
@ -176,10 +216,12 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
} }
// This may fail, and we'll have a disparity in the UI until `updateDeviceName` is called. // This may fail, and we'll have a disparity in the UI until `updateDeviceName` is called.
lifecycleScope.launch(Main) { lifecycleScope.launch(Main) {
accountManager.authenticatedAccount() context?.let {
?.deviceConstellation() accountManager.authenticatedAccount()
?.setDeviceNameAsync(newValue) ?.deviceConstellation()
?.await() ?.setDeviceNameAsync(newValue, it)
?.await()
}
} }
return true return true
} }
@ -229,6 +271,8 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
val time = getLastSynced(requireContext()) val time = getLastSynced(requireContext())
accountSettingsStore.dispatch(AccountSettingsFragmentAction.SyncEnded(time)) accountSettingsStore.dispatch(AccountSettingsFragmentAction.SyncEnded(time))
} }
// Make sure out sync engine checkboxes are up-to-date.
updateSyncEngineStates()
} }
} }

View File

@ -15,13 +15,11 @@
<androidx.preference.CheckBoxPreference <androidx.preference.CheckBoxPreference
android:key="@string/pref_key_sync_bookmarks" android:key="@string/pref_key_sync_bookmarks"
android:defaultValue="true" android:defaultValue="true"
android:enabled="false"
android:title="@string/preferences_sync_bookmarks" /> android:title="@string/preferences_sync_bookmarks" />
<androidx.preference.CheckBoxPreference <androidx.preference.CheckBoxPreference
android:key="@string/pref_key_sync_history" android:key="@string/pref_key_sync_history"
android:defaultValue="true" android:defaultValue="true"
android:enabled="false"
android:title="@string/preferences_sync_history" /> android:title="@string/preferences_sync_history" />
<androidx.preference.EditTextPreference <androidx.preference.EditTextPreference

View File

@ -42,7 +42,7 @@ object Versions {
// that we depend on directly for the fenix-megazord (and for it's // that we depend on directly for the fenix-megazord (and for it's
// forUnitTest variant), and it's important that it be kept in // forUnitTest variant), and it's important that it be kept in
// sync with the version used by android-components above. // sync with the version used by android-components above.
const val mozilla_appservices = "0.39.1" const val mozilla_appservices = "0.40.0"
const val autodispose = "1.1.0" const val autodispose = "1.1.0"
const val adjust = "4.11.4" const val adjust = "4.11.4"