From 9c25d274d0d3c6549f607ce1298471ca6627a8d4 Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Wed, 15 Jan 2020 21:10:07 -0800 Subject: [PATCH] Enable firebase auto-init, force push renewal after migration --- app/src/main/AndroidManifest.xml | 2 +- .../fenix/MigratingFenixApplication.kt | 5 ++-- ...hSubscriber.kt => MigrationPushRenewer.kt} | 23 ++++++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) rename app/src/migration/java/org/mozilla/fenix/{MigrationPushSubscriber.kt => MigrationPushRenewer.kt} (54%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a9d68bd73..2ad6f51c2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -229,7 +229,7 @@ + android:value="true" /> diff --git a/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt b/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt index c40efbe1f..ab2aa2036 100644 --- a/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt +++ b/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt @@ -28,9 +28,8 @@ class MigratingFenixApplication : FenixApplication() { } val migrationPushSubscriber by lazy { - MigrationPushSubscriber( - this, - components.backgroundServices.pushService, + MigrationPushRenewer( + components.backgroundServices.push, components.migrationStore ) } diff --git a/app/src/migration/java/org/mozilla/fenix/MigrationPushSubscriber.kt b/app/src/migration/java/org/mozilla/fenix/MigrationPushRenewer.kt similarity index 54% rename from app/src/migration/java/org/mozilla/fenix/MigrationPushSubscriber.kt rename to app/src/migration/java/org/mozilla/fenix/MigrationPushRenewer.kt index 55c8e813a..c45df6722 100644 --- a/app/src/migration/java/org/mozilla/fenix/MigrationPushSubscriber.kt +++ b/app/src/migration/java/org/mozilla/fenix/MigrationPushRenewer.kt @@ -4,33 +4,34 @@ package org.mozilla.fenix -import android.content.Context import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect -import mozilla.components.concept.push.PushService +import mozilla.components.concept.push.PushProcessor import mozilla.components.lib.state.ext.flowScoped +import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.migration.state.MigrationProgress import mozilla.components.support.migration.state.MigrationStore /** - * Migration-aware subscriber that disables the push service during an active migration - * and re-enables when complete. + * Force-renews push subscription after migration was complete. */ -class MigrationPushSubscriber( - private val context: Context, - private val service: PushService, +class MigrationPushRenewer( + private val service: PushProcessor?, private val store: MigrationStore ) { @UseExperimental(ExperimentalCoroutinesApi::class) fun start() { - // Stop the service if it is already started. - service.stop() - // Observe for migration completed. store.flowScoped { flow -> flow.collect { state -> + Logger("MigrationPushRenewer").debug("Migration state: ${state.progress}") if (state.progress == MigrationProgress.COMPLETED) { - service.start(context) + Logger("MigrationPushRenewer").debug("Renewing registration....") + + // This should force a recreation of firebase device token, re-registration with + // the autopush service, and subsequent update of the FxA device record with + // new push subscription information. + service?.renewRegistration() } } }