diff --git a/app/src/fennecProduction/java/org/mozilla/fenix/MigratingFenixApplication.kt b/app/src/fennecProduction/java/org/mozilla/fenix/MigratingFenixApplication.kt index e5d213d0dc..7273b971c9 100644 --- a/app/src/fennecProduction/java/org/mozilla/fenix/MigratingFenixApplication.kt +++ b/app/src/fennecProduction/java/org/mozilla/fenix/MigratingFenixApplication.kt @@ -4,25 +4,32 @@ package org.mozilla.fenix -import mozilla.components.support.ktx.android.content.isMainProcess +import kotlinx.coroutines.runBlocking import mozilla.components.support.migration.FennecMigrator /** * An application class which knows how to migrate Fennec data. */ class MigratingFenixApplication : FenixApplication() { - override fun setupApplication() { - super.setupApplication() + override fun setupInMainProcessOnly() { + migrateGeckoBlocking() - // Same check as is present in super.setupApplication: - if (!isMainProcess()) { - // If this is not the main process then do not continue with the migration here. - // Migration only needs to be done in our app's main process and should not be done in other processes like - // a GeckoView child process or the crash handling process. Most importantly we never want to end up in a - // situation where we create a GeckoRuntime from the Gecko child process. - return + super.setupInMainProcessOnly() + + migrateDataAsynchronously() + } + + private fun migrateGeckoBlocking() { + val migrator = FennecMigrator.Builder(this, this.components.analytics.crashReporter) + .migrateGecko() + .build() + + runBlocking { + 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) diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index 8082c42418..a124192f99 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -9,6 +9,7 @@ import android.app.Application import android.os.Build import android.os.Build.VERSION.SDK_INT import android.os.StrictMode +import androidx.annotation.CallSuper import androidx.appcompat.app.AppCompatDelegate import androidx.core.content.getSystemService import io.reactivex.plugins.RxJavaPlugins @@ -51,17 +52,7 @@ open class FenixApplication : Application() { override fun onCreate() { super.onCreate() - setupApplication() - } - - open fun setupApplication() { - setupCrashReporting() - setDayNightTheme() - - setupMegazord() - setupLogging() - registerRxExceptionHandling() - enableStrictMode() + setupInAllProcesses() if (!isMainProcess()) { // If this is not the main process then do not continue with the initialization here. Everything that @@ -71,6 +62,30 @@ open class FenixApplication : Application() { return } + setupInMainProcessOnly() + } + + @CallSuper + open fun setupInAllProcesses() { + setupCrashReporting() + + // We want the log messages of all builds to go to Android logcat + Log.addSink(AndroidLogSink()) + } + + @CallSuper + open fun setupInMainProcessOnly() { + setupMegazord() + + // We want rust logging to go through the log sinks. + // This has to happen after initializing the megazord. + RustLog.enable() + + setDayNightTheme() + + registerRxExceptionHandling() + enableStrictMode() + // Make sure the engine is initialized and ready to use. components.core.engine.warmUp() @@ -138,14 +153,6 @@ open class FenixApplication : Application() { // no-op, LeakCanary is disabled by default } - private fun setupLogging() { - // We want the log messages of all builds to go to Android logcat - Log.addSink(AndroidLogSink()) - // We want rust logging to go through the log sinks. - // This has to happen after initializing the megazord. - RustLog.enable() - } - private fun loadExperiments(): Deferred { val experimentsFile = File(filesDir, EXPERIMENTS_JSON_FILENAME) val experimentSource = KintoExperimentSource( diff --git a/app/src/test/java/org/mozilla/fenix/TestApplication.kt b/app/src/test/java/org/mozilla/fenix/TestApplication.kt index 49adfbbeee..f074b6549f 100644 --- a/app/src/test/java/org/mozilla/fenix/TestApplication.kt +++ b/app/src/test/java/org/mozilla/fenix/TestApplication.kt @@ -10,6 +10,7 @@ class TestApplication : FenixApplication() { override val components = TestComponents(this) - override fun setupApplication() { - } + override fun setupInAllProcesses() = Unit + + override fun setupInMainProcessOnly() = Unit }