|
|
|
@ -34,7 +34,6 @@ import mozilla.components.service.fxa.manager.FxaAccountManager
|
|
|
|
|
import mozilla.components.service.fxa.sync.GlobalSyncableStoreProvider
|
|
|
|
|
import mozilla.components.support.base.log.logger.Logger
|
|
|
|
|
import org.mozilla.fenix.Experiments
|
|
|
|
|
import org.mozilla.fenix.FeatureFlags
|
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
|
import org.mozilla.fenix.components.metrics.Event
|
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
@ -72,11 +71,7 @@ class BackgroundServices(
|
|
|
|
|
// NB: flipping this flag back and worth is currently not well supported and may need hand-holding.
|
|
|
|
|
// Consult with the android-components peers before changing.
|
|
|
|
|
// See https://github.com/mozilla/application-services/issues/1308
|
|
|
|
|
capabilities = if (FeatureFlags.sendTabEnabled) {
|
|
|
|
|
setOf(DeviceCapability.SEND_TAB)
|
|
|
|
|
} else {
|
|
|
|
|
emptySet()
|
|
|
|
|
}
|
|
|
|
|
capabilities = setOf(DeviceCapability.SEND_TAB)
|
|
|
|
|
)
|
|
|
|
|
// If sync has been turned off on the server then disable syncing.
|
|
|
|
|
private val syncConfig = if (context.isInExperiment(Experiments.asFeatureSyncDisabled)) {
|
|
|
|
@ -175,58 +170,56 @@ class BackgroundServices(
|
|
|
|
|
).also {
|
|
|
|
|
Settings.getInstance(context).fxaHasSyncedItems = syncConfig?.syncableStores?.isNotEmpty() ?: false
|
|
|
|
|
|
|
|
|
|
if (FeatureFlags.sendTabEnabled) {
|
|
|
|
|
it.registerForDeviceEvents(deviceEventObserver, ProcessLifecycleOwner.get(), false)
|
|
|
|
|
|
|
|
|
|
// Enable push if we have the config.
|
|
|
|
|
if (pushConfig != null) {
|
|
|
|
|
|
|
|
|
|
// Register our account observer so we know how to update our push subscriptions.
|
|
|
|
|
it.register(accountObserver)
|
|
|
|
|
|
|
|
|
|
val logger = Logger("AutoPushFeature")
|
|
|
|
|
|
|
|
|
|
// Notify observers for Services' messages.
|
|
|
|
|
push.registerForPushMessages(
|
|
|
|
|
PushType.Services,
|
|
|
|
|
object : Bus.Observer<PushType, String> {
|
|
|
|
|
override fun onEvent(type: PushType, message: String) {
|
|
|
|
|
it.authenticatedAccount()?.deviceConstellation()
|
|
|
|
|
?.processRawEventAsync(message)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
ProcessLifecycleOwner.get(),
|
|
|
|
|
false
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Notify observers for subscription changes.
|
|
|
|
|
push.registerForSubscriptions(object : PushSubscriptionObserver {
|
|
|
|
|
override fun onSubscriptionAvailable(subscription: AutoPushSubscription) {
|
|
|
|
|
// Update for only the services subscription.
|
|
|
|
|
if (subscription.type == PushType.Services) {
|
|
|
|
|
logger.info("New push subscription received for FxA")
|
|
|
|
|
it.authenticatedAccount()?.deviceConstellation()
|
|
|
|
|
?.setDevicePushSubscriptionAsync(
|
|
|
|
|
DevicePushSubscription(
|
|
|
|
|
endpoint = subscription.endpoint,
|
|
|
|
|
publicKey = subscription.publicKey,
|
|
|
|
|
authKey = subscription.authKey
|
|
|
|
|
)
|
|
|
|
|
it.registerForDeviceEvents(deviceEventObserver, ProcessLifecycleOwner.get(), false)
|
|
|
|
|
|
|
|
|
|
// Enable push if we have the config.
|
|
|
|
|
if (pushConfig != null) {
|
|
|
|
|
|
|
|
|
|
// Register our account observer so we know how to update our push subscriptions.
|
|
|
|
|
it.register(accountObserver)
|
|
|
|
|
|
|
|
|
|
val logger = Logger("AutoPushFeature")
|
|
|
|
|
|
|
|
|
|
// Notify observers for Services' messages.
|
|
|
|
|
push.registerForPushMessages(
|
|
|
|
|
PushType.Services,
|
|
|
|
|
object : Bus.Observer<PushType, String> {
|
|
|
|
|
override fun onEvent(type: PushType, message: String) {
|
|
|
|
|
it.authenticatedAccount()?.deviceConstellation()
|
|
|
|
|
?.processRawEventAsync(message)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
ProcessLifecycleOwner.get(),
|
|
|
|
|
false
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Notify observers for subscription changes.
|
|
|
|
|
push.registerForSubscriptions(object : PushSubscriptionObserver {
|
|
|
|
|
override fun onSubscriptionAvailable(subscription: AutoPushSubscription) {
|
|
|
|
|
// Update for only the services subscription.
|
|
|
|
|
if (subscription.type == PushType.Services) {
|
|
|
|
|
logger.info("New push subscription received for FxA")
|
|
|
|
|
it.authenticatedAccount()?.deviceConstellation()
|
|
|
|
|
?.setDevicePushSubscriptionAsync(
|
|
|
|
|
DevicePushSubscription(
|
|
|
|
|
endpoint = subscription.endpoint,
|
|
|
|
|
publicKey = subscription.publicKey,
|
|
|
|
|
authKey = subscription.authKey
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}, 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 prefResetSubKey = "reset_broken_push_subscription"
|
|
|
|
|
if (!preferences.getBoolean(prefResetSubKey, false)) {
|
|
|
|
|
preferences.edit().putBoolean(prefResetSubKey, true).apply()
|
|
|
|
|
logger.info("Forcing push registration renewal")
|
|
|
|
|
push.forceRegistrationRenewal()
|
|
|
|
|
}
|
|
|
|
|
}, 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 prefResetSubKey = "reset_broken_push_subscription"
|
|
|
|
|
if (!preferences.getBoolean(prefResetSubKey, false)) {
|
|
|
|
|
preferences.edit().putBoolean(prefResetSubKey, true).apply()
|
|
|
|
|
logger.info("Forcing push registration renewal")
|
|
|
|
|
push.forceRegistrationRenewal()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CoroutineScope(Dispatchers.Main).launch { it.initAsync().await() }
|
|
|
|
|