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
parent
8f97d247a6
commit
a4097cd380
|
@ -25,6 +25,7 @@ import mozilla.components.browser.search.SearchEngine
|
|||
import mozilla.components.browser.session.Session
|
||||
import mozilla.components.browser.session.SessionManager
|
||||
import mozilla.components.concept.engine.EngineView
|
||||
import mozilla.components.service.fxa.sync.SyncReason
|
||||
import mozilla.components.support.base.feature.BackHandler
|
||||
import mozilla.components.support.ktx.kotlin.isUrl
|
||||
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
|
||||
|
@ -112,7 +113,7 @@ open class HomeActivity : AppCompatActivity() {
|
|||
accountManager.initAsync().await()
|
||||
// If we're authenticated, kick-off a sync and a device state refresh.
|
||||
accountManager.authenticatedAccount()?.let {
|
||||
accountManager.syncNowAsync(startup = true, debounce = true)
|
||||
accountManager.syncNowAsync(SyncReason.Startup, debounce = true)
|
||||
it.deviceConstellation().pollForEventsAsync().await()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.withContext
|
||||
import mozilla.components.browser.session.Session
|
||||
import mozilla.components.browser.session.SessionManager
|
||||
import mozilla.components.feature.accounts.FxaCapability
|
||||
import mozilla.components.feature.accounts.FxaWebChannelFeature
|
||||
import mozilla.components.feature.app.links.AppLinksFeature
|
||||
import mozilla.components.feature.contextmenu.ContextMenuFeature
|
||||
|
@ -380,7 +381,8 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
|
|||
customTabSessionId,
|
||||
requireComponents.core.engine,
|
||||
requireComponents.core.sessionManager,
|
||||
requireComponents.backgroundServices.accountManager
|
||||
requireComponents.backgroundServices.accountManager,
|
||||
setOf(FxaCapability.CHOOSE_WHAT_TO_SYNC)
|
||||
),
|
||||
owner = this,
|
||||
view = view
|
||||
|
|
|
@ -94,7 +94,7 @@ class BackgroundServices(
|
|||
val syncConfig = if (context.isInExperiment(Experiments.asFeatureSyncDisabled)) {
|
||||
null
|
||||
} 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() }
|
||||
|
@ -103,8 +103,8 @@ class BackgroundServices(
|
|||
|
||||
init {
|
||||
// Make the "history" and "bookmark" stores accessible to workers spawned by the sync manager.
|
||||
GlobalSyncableStoreProvider.configureStore(SyncEngine.HISTORY to historyStorage)
|
||||
GlobalSyncableStoreProvider.configureStore(SyncEngine.BOOKMARKS to bookmarkStorage)
|
||||
GlobalSyncableStoreProvider.configureStore(SyncEngine.History to historyStorage)
|
||||
GlobalSyncableStoreProvider.configureStore(SyncEngine.Bookmarks to bookmarkStorage)
|
||||
}
|
||||
|
||||
private val deviceEventObserver = object : DeviceEventsObserver {
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.view.View
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.preference.CheckBoxPreference
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.Preference
|
||||
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.DeviceConstellationObserver
|
||||
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.SyncEnginesStorage
|
||||
import mozilla.components.service.fxa.sync.SyncReason
|
||||
import mozilla.components.service.fxa.sync.SyncStatusObserver
|
||||
import mozilla.components.service.fxa.sync.getLastSynced
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.components.StoreProvider
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.getPreferenceKey
|
||||
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)
|
||||
|
||||
// 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() {
|
||||
lifecycleScope.launch {
|
||||
requireComponents.analytics.metrics.track(Event.SyncAccountSyncNow)
|
||||
// Trigger a sync.
|
||||
requireComponents.backgroundServices.accountManager.syncNowAsync().await()
|
||||
requireComponents.backgroundServices.accountManager.syncNowAsync(SyncReason.User).await()
|
||||
// Poll for device events & update devices.
|
||||
accountManager.authenticatedAccount()
|
||||
?.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.
|
||||
lifecycleScope.launch(Main) {
|
||||
accountManager.authenticatedAccount()
|
||||
?.deviceConstellation()
|
||||
?.setDeviceNameAsync(newValue)
|
||||
?.await()
|
||||
context?.let {
|
||||
accountManager.authenticatedAccount()
|
||||
?.deviceConstellation()
|
||||
?.setDeviceNameAsync(newValue, it)
|
||||
?.await()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -229,6 +271,8 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
|
|||
val time = getLastSynced(requireContext())
|
||||
accountSettingsStore.dispatch(AccountSettingsFragmentAction.SyncEnded(time))
|
||||
}
|
||||
// Make sure out sync engine checkboxes are up-to-date.
|
||||
updateSyncEngineStates()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,13 +15,11 @@
|
|||
<androidx.preference.CheckBoxPreference
|
||||
android:key="@string/pref_key_sync_bookmarks"
|
||||
android:defaultValue="true"
|
||||
android:enabled="false"
|
||||
android:title="@string/preferences_sync_bookmarks" />
|
||||
|
||||
<androidx.preference.CheckBoxPreference
|
||||
android:key="@string/pref_key_sync_history"
|
||||
android:defaultValue="true"
|
||||
android:enabled="false"
|
||||
android:title="@string/preferences_sync_history" />
|
||||
|
||||
<androidx.preference.EditTextPreference
|
||||
|
|
|
@ -42,7 +42,7 @@ object Versions {
|
|||
// that we depend on directly for the fenix-megazord (and for it's
|
||||
// forUnitTest variant), and it's important that it be kept in
|
||||
// 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 adjust = "4.11.4"
|
||||
|
|
Loading…
Reference in New Issue