Closes #7645: Disable push service when migrating
parent
ee7f16b2b4
commit
61570b5238
|
@ -87,7 +87,7 @@ class BackgroundServices(
|
|||
syncPeriodInMinutes = 240L) // four hours
|
||||
}
|
||||
|
||||
private val pushService by lazy { FirebasePush() }
|
||||
val pushService by lazy { FirebasePush() }
|
||||
|
||||
val push by lazy { makePushConfig()?.let { makePush(it) } }
|
||||
|
||||
|
|
|
@ -29,6 +29,14 @@ class MigratingFenixApplication : FenixApplication() {
|
|||
|
||||
val migrationStore by lazy { MigrationStore() }
|
||||
|
||||
val migrationPushSubscriber by lazy {
|
||||
MigrationPushSubscriber(
|
||||
this,
|
||||
components.backgroundServices.pushService,
|
||||
migrationStore
|
||||
)
|
||||
}
|
||||
|
||||
override fun setupInMainProcessOnly() {
|
||||
// These migrations need to run before regular initialization happens.
|
||||
migrateBlocking()
|
||||
|
@ -37,6 +45,7 @@ class MigratingFenixApplication : FenixApplication() {
|
|||
super.setupInMainProcessOnly()
|
||||
|
||||
// The rest of the migrations can happen now.
|
||||
migrationPushSubscriber.start()
|
||||
migrator.startMigrationIfNeeded(migrationStore, MigrationService::class.java)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
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.lib.state.ext.flowScoped
|
||||
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.
|
||||
*/
|
||||
class MigrationPushSubscriber(
|
||||
private val context: Context,
|
||||
private val service: PushService,
|
||||
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 ->
|
||||
if (state.progress == MigrationProgress.COMPLETED) {
|
||||
service.start(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue