|
|
@ -5,10 +5,7 @@
|
|
|
|
package org.mozilla.fenix
|
|
|
|
package org.mozilla.fenix
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.app.ActivityManager
|
|
|
|
|
|
|
|
import android.app.Application
|
|
|
|
import android.app.Application
|
|
|
|
import android.content.Context
|
|
|
|
|
|
|
|
import android.os.Process
|
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
@ -18,6 +15,8 @@ import mozilla.components.service.fretboard.storage.flatfile.FlatFileExperimentS
|
|
|
|
import mozilla.components.support.base.log.Log
|
|
|
|
import mozilla.components.support.base.log.Log
|
|
|
|
import mozilla.components.support.base.log.logger.Logger
|
|
|
|
import mozilla.components.support.base.log.logger.Logger
|
|
|
|
import mozilla.components.support.base.log.sink.AndroidLogSink
|
|
|
|
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.rustlog.RustLog
|
|
|
|
import mozilla.components.support.rustlog.RustLog
|
|
|
|
import org.mozilla.fenix.components.Components
|
|
|
|
import org.mozilla.fenix.components.Components
|
|
|
|
import java.io.File
|
|
|
|
import java.io.File
|
|
|
@ -34,7 +33,7 @@ open class FenixApplication : Application() {
|
|
|
|
setupLogging(megazordEnabled)
|
|
|
|
setupLogging(megazordEnabled)
|
|
|
|
setupCrashReporting()
|
|
|
|
setupCrashReporting()
|
|
|
|
|
|
|
|
|
|
|
|
if (!isMainProcess(this)) {
|
|
|
|
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
|
|
|
|
// follows only needs to be done in our app's main process and should not be done in other processes like
|
|
|
|
// 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
|
|
|
|
// a GeckoView child process or the crash handling process. Most importantly we never want to end up in a
|
|
|
@ -130,25 +129,11 @@ open class FenixApplication : Application() {
|
|
|
|
false
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 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 ->
|
|
|
|
override fun onTrimMemory(level: Int) {
|
|
|
|
if (processInfo.pid == pid) {
|
|
|
|
super.onTrimMemory(level)
|
|
|
|
return processInfo.processName == context.packageName
|
|
|
|
runOnlyInMainProcess {
|
|
|
|
|
|
|
|
components.core.sessionManager.onLowMemory()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|