Moving onTrimMemory to application level.
parent
7cbf73fa8c
commit
32478edf00
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
override fun onTrimMemory(level: Int) {
|
||||||
* Are we running in the main process?
|
super.onTrimMemory(level)
|
||||||
*
|
runOnlyInMainProcess {
|
||||||
* Let's move this code to Android Components:
|
components.core.sessionManager.onLowMemory()
|
||||||
* 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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.browser
|
package org.mozilla.fenix.browser
|
||||||
|
|
||||||
import android.content.ComponentCallbacks2
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
@ -56,7 +55,7 @@ import org.mozilla.fenix.ext.share
|
||||||
import org.mozilla.fenix.mvi.ActionBusFactory
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||||
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
||||||
|
|
||||||
class BrowserFragment : Fragment(), BackHandler, ComponentCallbacks2 {
|
class BrowserFragment : Fragment(), BackHandler {
|
||||||
private lateinit var toolbarComponent: ToolbarComponent
|
private lateinit var toolbarComponent: ToolbarComponent
|
||||||
|
|
||||||
private val sessionFeature = ViewBoundFeatureWrapper<SessionFeature>()
|
private val sessionFeature = ViewBoundFeatureWrapper<SessionFeature>()
|
||||||
|
@ -284,10 +283,6 @@ class BrowserFragment : Fragment(), BackHandler, ComponentCallbacks2 {
|
||||||
promptsFeature.withFeature { it.onActivityResult(requestCode, resultCode, data) }
|
promptsFeature.withFeature { it.onActivityResult(requestCode, resultCode, data) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTrimMemory(level: Int) {
|
|
||||||
requireComponents.core.sessionManager.onLowMemory()
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method triggers the complexity warning. However it's actually not that hard to understand.
|
// This method triggers the complexity warning. However it's actually not that hard to understand.
|
||||||
@SuppressWarnings("ComplexMethod")
|
@SuppressWarnings("ComplexMethod")
|
||||||
private fun handleToolbarItemInteraction(action: SearchAction.ToolbarMenuItemTapped) {
|
private fun handleToolbarItemInteraction(action: SearchAction.ToolbarMenuItemTapped) {
|
||||||
|
|
Loading…
Reference in New Issue