|
|
|
@ -16,7 +16,7 @@ import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
|
import kotlinx.coroutines.async
|
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
|
import mozilla.components.concept.fetch.Client
|
|
|
|
|
import mozilla.appservices.Megazord
|
|
|
|
|
import mozilla.components.concept.push.PushProcessor
|
|
|
|
|
import mozilla.components.service.fretboard.Fretboard
|
|
|
|
|
import mozilla.components.service.fretboard.source.kinto.KintoExperimentSource
|
|
|
|
@ -26,6 +26,7 @@ import mozilla.components.support.base.log.logger.Logger
|
|
|
|
|
import mozilla.components.support.base.log.sink.AndroidLogSink
|
|
|
|
|
import mozilla.components.support.ktx.android.content.isMainProcess
|
|
|
|
|
import mozilla.components.support.ktx.android.content.runOnlyInMainProcess
|
|
|
|
|
import mozilla.components.support.rusthttp.RustHttpConfig
|
|
|
|
|
import mozilla.components.support.rustlog.RustLog
|
|
|
|
|
import org.mozilla.fenix.components.Components
|
|
|
|
|
import org.mozilla.fenix.utils.Settings
|
|
|
|
@ -49,8 +50,9 @@ open class FenixApplication : Application() {
|
|
|
|
|
open fun setupApplication() {
|
|
|
|
|
setupCrashReporting()
|
|
|
|
|
setDayNightTheme()
|
|
|
|
|
val megazordEnabled = setupMegazord()
|
|
|
|
|
setupLogging(megazordEnabled)
|
|
|
|
|
|
|
|
|
|
setupMegazord()
|
|
|
|
|
setupLogging()
|
|
|
|
|
registerRxExceptionHandling()
|
|
|
|
|
enableStrictMode()
|
|
|
|
|
|
|
|
|
@ -129,17 +131,13 @@ open class FenixApplication : Application() {
|
|
|
|
|
// no-op, LeakCanary is disabled by default
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun setupLogging(megazordEnabled: Boolean) {
|
|
|
|
|
private fun setupLogging() {
|
|
|
|
|
// We want the log messages of all builds to go to Android logcat
|
|
|
|
|
Log.addSink(AndroidLogSink())
|
|
|
|
|
|
|
|
|
|
if (megazordEnabled) {
|
|
|
|
|
// We want rust logging to go through the log sinks.
|
|
|
|
|
// This has to happen after initializing the megazord, and
|
|
|
|
|
// it's only worth doing in the case that we are a megazord.
|
|
|
|
|
// This has to happen after initializing the megazord.
|
|
|
|
|
RustLog.enable()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun loadExperiments(): Deferred<Boolean> {
|
|
|
|
|
val experimentsFile = File(filesDir, EXPERIMENTS_JSON_FILENAME)
|
|
|
|
@ -171,34 +169,18 @@ open class FenixApplication : Application() {
|
|
|
|
|
/**
|
|
|
|
|
* Initiate Megazord sequence! Megazord Battle Mode!
|
|
|
|
|
*
|
|
|
|
|
* Mozilla Application Services publishes many native (Rust) code libraries that stand alone: each published Android
|
|
|
|
|
* ARchive (AAR) contains managed code (classes.jar) and multiple .so library files (one for each supported
|
|
|
|
|
* architecture). That means consuming multiple such libraries entails at least two .so libraries, and each of those
|
|
|
|
|
* libraries includes the entire Rust standard library as well as (potentially many) duplicated dependencies. To
|
|
|
|
|
* save space and allow cross-component native-code Link Time Optimization (LTO, i.e., inlining, dead code
|
|
|
|
|
* elimination, etc).
|
|
|
|
|
* Application Services also publishes composite libraries -- so called megazord libraries or just megazords -- that
|
|
|
|
|
* compose multiple Rust components into a single optimized .so library file.
|
|
|
|
|
*
|
|
|
|
|
* @return Boolean indicating if we're in a megazord.
|
|
|
|
|
* The application-services combined libraries are known as the "megazord". The default megazord
|
|
|
|
|
* contains several features that fenix doesn't need, and so we swap out with a customized fenix-specific
|
|
|
|
|
* version of the megazord. The best explanation for what this is, and why it's done is the a-s
|
|
|
|
|
* documentation on the topic:
|
|
|
|
|
* - https://github.com/mozilla/application-services/blob/master/docs/design/megazords.md
|
|
|
|
|
* - https://mozilla.github.io/application-services/docs/applications/consuming-megazord-libraries.html
|
|
|
|
|
*/
|
|
|
|
|
private fun setupMegazord(): Boolean {
|
|
|
|
|
// mozilla.appservices.FenixMegazord will be missing if we're doing an application-services
|
|
|
|
|
// dependency substitution locally. That class is supplied dynamically by the org.mozilla.appservices
|
|
|
|
|
// gradle plugin, and that won't happen if we're not megazording. We won't megazord if we're
|
|
|
|
|
// locally substituting every module that's part of the megazord's definition, which is what
|
|
|
|
|
// happens during a local substitution of application-services.
|
|
|
|
|
// As a workaround, use reflections to conditionally initialize the megazord in case it's present.
|
|
|
|
|
return try {
|
|
|
|
|
val megazordClass = Class.forName("mozilla.appservices.FenixMegazord")
|
|
|
|
|
val megazordInitMethod = megazordClass.getDeclaredMethod("init", Lazy::class.java)
|
|
|
|
|
val client: Lazy<Client> = lazy { components.core.client }
|
|
|
|
|
megazordInitMethod.invoke(megazordClass, client)
|
|
|
|
|
true
|
|
|
|
|
} catch (e: ClassNotFoundException) {
|
|
|
|
|
Logger.info("mozilla.appservices.FenixMegazord not found; skipping megazord init.")
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
private fun setupMegazord() {
|
|
|
|
|
// Note: This must be called as soon as possible
|
|
|
|
|
Megazord.init()
|
|
|
|
|
// This (and enabling RustLog) may be delayed if needed for performance reasons
|
|
|
|
|
RustHttpConfig.setClient(lazy { components.core.client })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onTrimMemory(level: Int) {
|
|
|
|
|