diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index 068399fcec..22ab8a2cb0 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -5,9 +5,10 @@ package org.mozilla.fenix import android.annotation.SuppressLint +import android.app.ActivityManager import android.app.Application import android.content.Context -import com.squareup.leakcanary.LeakCanary +import android.os.Process import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -29,13 +30,19 @@ open class FenixApplication : Application() { override fun onCreate() { super.onCreate() - Log.addSink(AndroidLogSink()) - if (LeakCanary.isInAnalyzerProcess(this)) { - return // don't perform extra init in analyzer - } - setupLeakCanary() + Log.addSink(AndroidLogSink()) setupCrashReporting() + + if (!isMainProcess(this)) { + // If this is not the main process then do not continue with the initialization here. Everything that + // follows 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 + } + + setupLeakCanary() setupGlean(this) loadExperiments() } @@ -56,7 +63,10 @@ open class FenixApplication : Application() { private fun loadExperiments() { val experimentsFile = File(filesDir, EXPERIMENTS_JSON_FILENAME) val experimentSource = KintoExperimentSource( - EXPERIMENTS_BASE_URL, EXPERIMENTS_BUCKET_NAME, EXPERIMENTS_COLLECTION_NAME + EXPERIMENTS_BASE_URL, + EXPERIMENTS_BUCKET_NAME, + EXPERIMENTS_COLLECTION_NAME, + components.core.client ) // TODO add ValueProvider to keep clientID in sync with Glean when ready fretboard = Fretboard(experimentSource, FlatFileExperimentStorage(experimentsFile)) @@ -82,3 +92,24 @@ open class FenixApplication : Application() { .install(this) } } + +/** + * Are we running in the main process? + * + * Let's move this code to Android Components: + * https://github.com/mozilla-mobile/android-components/issues/2207 + */ +private fun isMainProcess(context: Context): Boolean { + val pid = Process.myPid() + + val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) + as ActivityManager + + activityManager.runningAppProcesses?.forEach { processInfo -> + if (processInfo.pid == pid) { + return processInfo.processName == context.packageName + } + } + + return false +} diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index d573490278..afdbbb042a 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -5,8 +5,7 @@ private object Versions { const val kotlin = "1.3.11" const val android_gradle_plugin = "3.2.1" - - const val geckoNightly = "67.0.20190213102848" + const val geckoNightly = "67.0.20190227104426" const val rxAndroid = "2.1.0" const val rxKotlin = "2.3.0" const val anko = "0.10.8" @@ -22,7 +21,7 @@ private object Versions { const val androidx_fragment = "1.1.0-alpha04" const val androidx_safeargs = "1.0.0-beta01" - const val mozilla_android_components = "0.43.0-SNAPSHOT" + const val mozilla_android_components = "0.45.0-SNAPSHOT" const val test_tools = "1.0.2" const val espresso_core = "2.2.2"