Enable firebase auto-init, force push renewal after migration
parent
7f988a85d0
commit
9c25d274d0
|
@ -229,7 +229,7 @@
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="firebase_messaging_auto_init_enabled"
|
android:name="firebase_messaging_auto_init_enabled"
|
||||||
android:value="false" />
|
android:value="true" />
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="firebase_analytics_collection_enabled"
|
android:name="firebase_analytics_collection_enabled"
|
||||||
android:value="false" />
|
android:value="false" />
|
||||||
|
|
|
@ -28,9 +28,8 @@ class MigratingFenixApplication : FenixApplication() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val migrationPushSubscriber by lazy {
|
val migrationPushSubscriber by lazy {
|
||||||
MigrationPushSubscriber(
|
MigrationPushRenewer(
|
||||||
this,
|
components.backgroundServices.push,
|
||||||
components.backgroundServices.pushService,
|
|
||||||
components.migrationStore
|
components.migrationStore
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,33 +4,34 @@
|
||||||
|
|
||||||
package org.mozilla.fenix
|
package org.mozilla.fenix
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.collect
|
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.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.MigrationProgress
|
||||||
import mozilla.components.support.migration.state.MigrationStore
|
import mozilla.components.support.migration.state.MigrationStore
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migration-aware subscriber that disables the push service during an active migration
|
* Force-renews push subscription after migration was complete.
|
||||||
* and re-enables when complete.
|
|
||||||
*/
|
*/
|
||||||
class MigrationPushSubscriber(
|
class MigrationPushRenewer(
|
||||||
private val context: Context,
|
private val service: PushProcessor?,
|
||||||
private val service: PushService,
|
|
||||||
private val store: MigrationStore
|
private val store: MigrationStore
|
||||||
) {
|
) {
|
||||||
@UseExperimental(ExperimentalCoroutinesApi::class)
|
@UseExperimental(ExperimentalCoroutinesApi::class)
|
||||||
fun start() {
|
fun start() {
|
||||||
// Stop the service if it is already started.
|
|
||||||
service.stop()
|
|
||||||
|
|
||||||
// Observe for migration completed.
|
// Observe for migration completed.
|
||||||
store.flowScoped { flow ->
|
store.flowScoped { flow ->
|
||||||
flow.collect { state ->
|
flow.collect { state ->
|
||||||
|
Logger("MigrationPushRenewer").debug("Migration state: ${state.progress}")
|
||||||
if (state.progress == MigrationProgress.COMPLETED) {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue