|
|
|
@ -6,6 +6,7 @@ package org.mozilla.fenix.components
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.os.Build
|
|
|
|
|
import android.preference.PreferenceManager
|
|
|
|
|
import androidx.lifecycle.ProcessLifecycleOwner
|
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
@ -13,7 +14,6 @@ import kotlinx.coroutines.launch
|
|
|
|
|
import mozilla.components.browser.storage.sync.PlacesBookmarksStorage
|
|
|
|
|
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
|
|
|
|
|
import mozilla.components.concept.push.Bus
|
|
|
|
|
import mozilla.components.concept.push.PushProcessor
|
|
|
|
|
import mozilla.components.concept.sync.AccountObserver
|
|
|
|
|
import mozilla.components.concept.sync.DeviceCapability
|
|
|
|
|
import mozilla.components.concept.sync.DeviceEvent
|
|
|
|
@ -76,7 +76,7 @@ class BackgroundServices(
|
|
|
|
|
SyncConfig(setOf("history", "bookmarks"), syncPeriodInMinutes = 240L) // four hours
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val pushConfig by lazy {
|
|
|
|
|
val pushConfig by lazy {
|
|
|
|
|
val projectIdKey = context.getString(R.string.pref_key_push_project_id)
|
|
|
|
|
val resId = context.resources.getIdentifier(projectIdKey, "string", context.packageName)
|
|
|
|
|
if (resId == 0) {
|
|
|
|
@ -88,7 +88,7 @@ class BackgroundServices(
|
|
|
|
|
|
|
|
|
|
val pushService by lazy { FirebasePush() }
|
|
|
|
|
|
|
|
|
|
private val push by lazy {
|
|
|
|
|
val push by lazy {
|
|
|
|
|
AutoPushFeature(context = context, service = pushService, config = pushConfig!!).also {
|
|
|
|
|
// Notify observers for Services' messages.
|
|
|
|
|
it.registerForPushMessages(PushType.Services, object : Bus.Observer<PushType, String> {
|
|
|
|
@ -101,6 +101,8 @@ class BackgroundServices(
|
|
|
|
|
// Notify observers for subscription changes.
|
|
|
|
|
it.registerForSubscriptions(object : PushSubscriptionObserver {
|
|
|
|
|
override fun onSubscriptionAvailable(subscription: AutoPushSubscription) {
|
|
|
|
|
// Update for only the services subscription.
|
|
|
|
|
if (subscription.type == PushType.Services) {
|
|
|
|
|
accountManager.authenticatedAccount()?.deviceConstellation()
|
|
|
|
|
?.setDevicePushSubscriptionAsync(
|
|
|
|
|
DevicePushSubscription(
|
|
|
|
@ -110,7 +112,20 @@ class BackgroundServices(
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, ProcessLifecycleOwner.get(), false)
|
|
|
|
|
|
|
|
|
|
// For all the current Fenix users, we need to remove the current push token and
|
|
|
|
|
// re-subscribe again on the right push server. We should never do this otherwise!
|
|
|
|
|
// Should be removed after majority of our users are correctly subscribed.
|
|
|
|
|
// See: https://github.com/mozilla-mobile/fenix/issues/4218
|
|
|
|
|
|
|
|
|
|
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
|
val prefResetSubKey = "reset_broken_push_subscription"
|
|
|
|
|
if (preferences.getBoolean(prefResetSubKey, true)) {
|
|
|
|
|
preferences.edit().putBoolean(prefResetSubKey, false).apply()
|
|
|
|
|
it.forceRegistrationRenewal()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -118,11 +133,6 @@ class BackgroundServices(
|
|
|
|
|
// Make the "history" and "bookmark" stores accessible to workers spawned by the sync manager.
|
|
|
|
|
GlobalSyncableStoreProvider.configureStore("history" to historyStorage)
|
|
|
|
|
GlobalSyncableStoreProvider.configureStore("bookmarks" to bookmarkStorage)
|
|
|
|
|
|
|
|
|
|
// Sets the PushFeature as the singleton instance for push messages to go to.
|
|
|
|
|
if (FeatureFlags.sendTabEnabled && pushConfig != null) {
|
|
|
|
|
PushProcessor.install(push)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val deviceEventObserver = object : DeviceEventsObserver {
|
|
|
|
|