mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/4982: Migrate Gecko files before initializing engine. (https://github.com/mozilla-mobile/fenix/pull/6738)
This commit is contained in:
parent
3635ac49a7
commit
38e97e4f16
@ -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)
|
||||
|
@ -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<Boolean> {
|
||||
val experimentsFile = File(filesDir, EXPERIMENTS_JSON_FILENAME)
|
||||
val experimentSource = KintoExperimentSource(
|
||||
|
@ -10,6 +10,7 @@ class TestApplication : FenixApplication() {
|
||||
|
||||
override val components = TestComponents(this)
|
||||
|
||||
override fun setupApplication() {
|
||||
}
|
||||
override fun setupInAllProcesses() = Unit
|
||||
|
||||
override fun setupInMainProcessOnly() = Unit
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user