parent
c5d496a35d
commit
8a330d413c
|
@ -4,25 +4,32 @@
|
||||||
|
|
||||||
package org.mozilla.fenix
|
package org.mozilla.fenix
|
||||||
|
|
||||||
import mozilla.components.support.ktx.android.content.isMainProcess
|
import kotlinx.coroutines.runBlocking
|
||||||
import mozilla.components.support.migration.FennecMigrator
|
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() {
|
||||||
override fun setupApplication() {
|
override fun setupInMainProcessOnly() {
|
||||||
super.setupApplication()
|
migrateGeckoBlocking()
|
||||||
|
|
||||||
// Same check as is present in super.setupApplication:
|
super.setupInMainProcessOnly()
|
||||||
if (!isMainProcess()) {
|
|
||||||
// If this is not the main process then do not continue with the migration here.
|
migrateDataAsynchronously()
|
||||||
// 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.
|
private fun migrateGeckoBlocking() {
|
||||||
return
|
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)
|
val migrator = FennecMigrator.Builder(this, this.components.analytics.crashReporter)
|
||||||
.migrateOpenTabs(this.components.core.sessionManager)
|
.migrateOpenTabs(this.components.core.sessionManager)
|
||||||
.migrateHistory(this.components.core.historyStorage)
|
.migrateHistory(this.components.core.historyStorage)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.app.Application
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Build.VERSION.SDK_INT
|
import android.os.Build.VERSION.SDK_INT
|
||||||
import android.os.StrictMode
|
import android.os.StrictMode
|
||||||
|
import androidx.annotation.CallSuper
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import io.reactivex.plugins.RxJavaPlugins
|
import io.reactivex.plugins.RxJavaPlugins
|
||||||
|
@ -51,17 +52,7 @@ open class FenixApplication : Application() {
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
setupApplication()
|
setupInAllProcesses()
|
||||||
}
|
|
||||||
|
|
||||||
open fun setupApplication() {
|
|
||||||
setupCrashReporting()
|
|
||||||
setDayNightTheme()
|
|
||||||
|
|
||||||
setupMegazord()
|
|
||||||
setupLogging()
|
|
||||||
registerRxExceptionHandling()
|
|
||||||
enableStrictMode()
|
|
||||||
|
|
||||||
if (!isMainProcess()) {
|
if (!isMainProcess()) {
|
||||||
// If this is not the main process then do not continue with the initialization here. Everything that
|
// 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
|
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.
|
// Make sure the engine is initialized and ready to use.
|
||||||
components.core.engine.warmUp()
|
components.core.engine.warmUp()
|
||||||
|
|
||||||
|
@ -138,14 +153,6 @@ open class FenixApplication : Application() {
|
||||||
// no-op, LeakCanary is disabled by default
|
// 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> {
|
private fun loadExperiments(): Deferred<Boolean> {
|
||||||
val experimentsFile = File(filesDir, EXPERIMENTS_JSON_FILENAME)
|
val experimentsFile = File(filesDir, EXPERIMENTS_JSON_FILENAME)
|
||||||
val experimentSource = KintoExperimentSource(
|
val experimentSource = KintoExperimentSource(
|
||||||
|
|
|
@ -10,6 +10,7 @@ class TestApplication : FenixApplication() {
|
||||||
|
|
||||||
override val components = TestComponents(this)
|
override val components = TestComponents(this)
|
||||||
|
|
||||||
override fun setupApplication() {
|
override fun setupInAllProcesses() = Unit
|
||||||
}
|
|
||||||
|
override fun setupInMainProcessOnly() = Unit
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue