1
0
Fork 0

Fix breaking services APIs changes

master
Grisha Kruglov 2019-09-04 13:56:22 -07:00 committed by Sebastian Kaspari
parent 2c7fd93c7d
commit 231924f5eb
8 changed files with 23 additions and 14 deletions

View File

@ -16,6 +16,7 @@ import mozilla.components.browser.storage.sync.PlacesBookmarksStorage
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
import mozilla.components.concept.push.Bus
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.DeviceCapability
import mozilla.components.concept.sync.DeviceEvent
import mozilla.components.concept.sync.DeviceEventsObserver
@ -30,6 +31,7 @@ import mozilla.components.feature.push.PushType
import mozilla.components.service.fxa.DeviceConfig
import mozilla.components.service.fxa.ServerConfig
import mozilla.components.service.fxa.SyncConfig
import mozilla.components.service.fxa.SyncEngine
import mozilla.components.service.fxa.manager.FxaAccountManager
import mozilla.components.service.fxa.sync.GlobalSyncableStoreProvider
import mozilla.components.support.base.log.logger.Logger
@ -77,7 +79,7 @@ class BackgroundServices(
private val syncConfig = if (context.isInExperiment(Experiments.asFeatureSyncDisabled)) {
null
} else {
SyncConfig(setOf("history", "bookmarks"), syncPeriodInMinutes = 240L) // four hours
SyncConfig(setOf(SyncEngine.HISTORY, SyncEngine.BOOKMARKS), syncPeriodInMinutes = 240L) // four hours
}
val pushConfig by lazy {
@ -102,8 +104,8 @@ class BackgroundServices(
init {
// Make the "history" and "bookmark" stores accessible to workers spawned by the sync manager.
GlobalSyncableStoreProvider.configureStore("history" to historyStorage)
GlobalSyncableStoreProvider.configureStore("bookmarks" to bookmarkStorage)
GlobalSyncableStoreProvider.configureStore(SyncEngine.HISTORY to historyStorage)
GlobalSyncableStoreProvider.configureStore(SyncEngine.BOOKMARKS to bookmarkStorage)
}
private val deviceEventObserver = object : DeviceEventsObserver {
@ -139,8 +141,8 @@ class BackgroundServices(
Settings.getInstance(context).fxaSignedIn = false
}
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
if (newAccount) {
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
if (authType != AuthType.Existing) {
push.subscribeForType(PushType.Services)
}
@ -168,7 +170,7 @@ class BackgroundServices(
// See https://github.com/mozilla-mobile/android-components/issues/3732
setOf("https://identity.mozilla.com/apps/oldsync")
).also {
Settings.getInstance(context).fxaHasSyncedItems = syncConfig?.syncableStores?.isNotEmpty() ?: false
Settings.getInstance(context).fxaHasSyncedItems = syncConfig?.supportedEngines?.isNotEmpty() ?: false
it.registerForDeviceEvents(deviceEventObserver, ProcessLifecycleOwner.get(), false)

View File

@ -5,6 +5,7 @@
package org.mozilla.fenix.customtabs
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import org.mozilla.fenix.ext.components
@ -17,7 +18,7 @@ class AuthCustomTabActivity : CustomTabActivity() {
/**
* Navigate away from this activity when we have successful authentication
*/
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
finish()
}
}

View File

@ -41,6 +41,7 @@ import mozilla.components.browser.menu.BrowserMenu
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import mozilla.components.feature.tab.collections.TabCollection
@ -761,8 +762,8 @@ class HomeFragment : Fragment(), AccountObserver {
}
}
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
if (newAccount) {
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
if (authType != AuthType.Existing) {
view?.let {
FenixSnackbar.make(it, Snackbar.LENGTH_SHORT).setText(
it.context.getString(R.string.onboarding_firefox_account_sync_is_on)

View File

@ -34,6 +34,7 @@ import mozilla.appservices.places.BookmarkRoot
import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.base.feature.BackHandler
@ -242,7 +243,7 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), BackHandler, Accou
return bookmarkView.onBackPressed()
}
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
bookmarkInteractor.onSignedIn()
lifecycleScope.launch {
refreshBookmarks()

View File

@ -29,6 +29,7 @@ import kotlinx.coroutines.withContext
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getColorFromAttr
@ -127,7 +128,7 @@ class SelectBookmarkFolderFragment : Fragment(), AccountObserver {
else -> super.onOptionsItemSelected(item)
}
}
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
bookmarkInteractor.onSignedIn()
}

View File

@ -12,6 +12,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import kotlinx.coroutines.launch
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getPreferenceKey
@ -66,7 +67,7 @@ class AccountProblemFragment : PreferenceFragmentCompat(), AccountObserver {
}
// We're told our auth problems have been fixed; close this fragment.
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) = closeFragment()
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) = closeFragment()
// We're told there are no more auth problems since there is no more account; close this fragment.
override fun onLoggedOut() = closeFragment()

View File

@ -24,6 +24,7 @@ import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import kotlinx.coroutines.launch
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import org.mozilla.fenix.BrowserDirection
@ -326,7 +327,7 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
Navigation.findNavController(view!!).navigate(directions)
}
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
lifecycleScope.launch {
context?.let {
updateAccountUIState(it, it.components.backgroundServices.accountManager.accountProfile())

View File

@ -15,6 +15,7 @@ import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import kotlinx.android.synthetic.main.fragment_turn_on_sync.view.*
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
@ -72,7 +73,7 @@ class TurnOnSyncFragment : Fragment(), AccountObserver {
return view
}
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
FenixSnackbar.make(view!!, FenixSnackbar.LENGTH_SHORT)
.setText(requireContext().getString(R.string.sync_syncing_in_progress))
.show()