1
0
Fork 0

No issue: Reset push subscriptions

master
Jonathan Almeida 2019-07-26 11:12:24 -04:00 committed by Jonathan Almeida
parent e6487ba609
commit c8148e61d5
1 changed files with 5 additions and 2 deletions

View File

@ -89,6 +89,7 @@ class BackgroundServices(
val pushService by lazy { FirebasePush() } val pushService by lazy { FirebasePush() }
val push by lazy { val push by lazy {
val logger = Logger("AutoPushFeature")
AutoPushFeature(context = context, service = pushService, config = pushConfig!!).also { AutoPushFeature(context = context, service = pushService, config = pushConfig!!).also {
// Notify observers for Services' messages. // Notify observers for Services' messages.
it.registerForPushMessages(PushType.Services, object : Bus.Observer<PushType, String> { it.registerForPushMessages(PushType.Services, object : Bus.Observer<PushType, String> {
@ -103,6 +104,7 @@ class BackgroundServices(
override fun onSubscriptionAvailable(subscription: AutoPushSubscription) { override fun onSubscriptionAvailable(subscription: AutoPushSubscription) {
// Update for only the services subscription. // Update for only the services subscription.
if (subscription.type == PushType.Services) { if (subscription.type == PushType.Services) {
logger.info("New push subscription received for FxA")
accountManager.authenticatedAccount()?.deviceConstellation() accountManager.authenticatedAccount()?.deviceConstellation()
?.setDevicePushSubscriptionAsync( ?.setDevicePushSubscriptionAsync(
DevicePushSubscription( DevicePushSubscription(
@ -122,8 +124,9 @@ class BackgroundServices(
val preferences = PreferenceManager.getDefaultSharedPreferences(context) val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val prefResetSubKey = "reset_broken_push_subscription" val prefResetSubKey = "reset_broken_push_subscription"
if (preferences.getBoolean(prefResetSubKey, true)) { if (!preferences.getBoolean(prefResetSubKey, false)) {
preferences.edit().putBoolean(prefResetSubKey, false).apply() preferences.edit().putBoolean(prefResetSubKey, true).apply()
logger.info("Forcing push registration renewal")
it.forceRegistrationRenewal() it.forceRegistrationRenewal()
} }
} }