diff --git a/app/src/migration/AndroidManifest.xml b/app/src/migration/AndroidManifest.xml index 12ced483c..91b8afc31 100644 --- a/app/src/migration/AndroidManifest.xml +++ b/app/src/migration/AndroidManifest.xml @@ -12,6 +12,7 @@ + diff --git a/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt b/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt index bf001a2ad..7356df2d9 100644 --- a/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt +++ b/app/src/migration/java/org/mozilla/fenix/MigratingFenixApplication.kt @@ -4,6 +4,7 @@ package org.mozilla.fenix +import android.content.Context import kotlinx.coroutines.runBlocking 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. */ 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() { migrateGeckoBlocking() super.setupInMainProcessOnly() - migrateDataAsynchronously() + migrator.startMigrationServiceIfNeeded(MigrationService::class.java) } private fun migrateGeckoBlocking() { @@ -28,19 +42,8 @@ class MigratingFenixApplication : FenixApplication() { migrator.migrateAsync().await() } } +} - private fun migrateDataAsynchronously() { - val migrator = 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() - - migrator.migrateAsync() - } +fun Context.getMigratorFromApplication(): FennecMigrator { + return (applicationContext as MigratingFenixApplication).migrator } diff --git a/app/src/migration/java/org/mozilla/fenix/MigrationService.kt b/app/src/migration/java/org/mozilla/fenix/MigrationService.kt new file mode 100644 index 000000000..6eef420c8 --- /dev/null +++ b/app/src/migration/java/org/mozilla/fenix/MigrationService.kt @@ -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() } +}