Run migration in background service.
In order to avoid a half done migration we are moving the migration to a background service (that is running in the "foreground"). This is the Fenix part of: https://github.com/mozilla-mobile/android-components/issues/4879master
parent
5268db15ea
commit
a83717dd7b
|
@ -12,6 +12,7 @@
|
||||||
<application
|
<application
|
||||||
android:name="org.mozilla.fenix.MigratingFenixApplication"
|
android:name="org.mozilla.fenix.MigratingFenixApplication"
|
||||||
tools:replace="android:name">
|
tools:replace="android:name">
|
||||||
|
<service android:name="org.mozilla.fenix.MigrationService" />
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
package org.mozilla.fenix
|
package org.mozilla.fenix
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import mozilla.components.support.migration.FennecMigrator
|
import mozilla.components.support.migration.FennecMigrator
|
||||||
|
|
||||||
|
@ -11,12 +12,25 @@ import mozilla.components.support.migration.FennecMigrator
|
||||||
* An application class which knows how to migrate Fennec data.
|
* An application class which knows how to migrate Fennec data.
|
||||||
*/
|
*/
|
||||||
class MigratingFenixApplication : FenixApplication() {
|
class MigratingFenixApplication : FenixApplication() {
|
||||||
|
val migrator by lazy {
|
||||||
|
FennecMigrator.Builder(this, this.components.analytics.crashReporter)
|
||||||
|
.migrateOpenTabs(this.components.core.sessionManager)
|
||||||
|
.migrateHistory(this.components.core.historyStorage)
|
||||||
|
.migrateBookmarks(this.components.core.bookmarksStorage)
|
||||||
|
.migrateLogins(
|
||||||
|
this.components.core.passwordsStorage.store,
|
||||||
|
this.components.core.passwordsEncryptionKey
|
||||||
|
)
|
||||||
|
.migrateFxa(this.components.backgroundServices.accountManager)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
override fun setupInMainProcessOnly() {
|
override fun setupInMainProcessOnly() {
|
||||||
migrateGeckoBlocking()
|
migrateGeckoBlocking()
|
||||||
|
|
||||||
super.setupInMainProcessOnly()
|
super.setupInMainProcessOnly()
|
||||||
|
|
||||||
migrateDataAsynchronously()
|
migrator.startMigrationServiceIfNeeded(MigrationService::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun migrateGeckoBlocking() {
|
private fun migrateGeckoBlocking() {
|
||||||
|
@ -28,19 +42,8 @@ class MigratingFenixApplication : FenixApplication() {
|
||||||
migrator.migrateAsync().await()
|
migrator.migrateAsync().await()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private fun migrateDataAsynchronously() {
|
|
||||||
val migrator = FennecMigrator.Builder(this, this.components.analytics.crashReporter)
|
fun Context.getMigratorFromApplication(): FennecMigrator {
|
||||||
.migrateOpenTabs(this.components.core.sessionManager)
|
return (applicationContext as MigratingFenixApplication).migrator
|
||||||
.migrateHistory(this.components.core.historyStorage)
|
|
||||||
.migrateBookmarks(this.components.core.bookmarksStorage)
|
|
||||||
.migrateLogins(
|
|
||||||
this.components.core.passwordsStorage.store,
|
|
||||||
this.components.core.passwordsEncryptionKey
|
|
||||||
)
|
|
||||||
.migrateFxa(this.components.backgroundServices.accountManager)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
migrator.migrateAsync()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
/* 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 mozilla.components.support.migration.AbstractMigrationService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Background service for running the migration from legacy Firefox for Android (Fennec).
|
||||||
|
*/
|
||||||
|
class MigrationService : AbstractMigrationService() {
|
||||||
|
override val migrator by lazy { getMigratorFromApplication() }
|
||||||
|
}
|
Loading…
Reference in New Issue