зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1106827 - Improve handling of Android memory pressure events r=rnewman
This commit is contained in:
Родитель
372bf4a34b
Коммит
2d6edbf230
|
@ -94,18 +94,33 @@ class MemoryMonitor extends BroadcastReceiver {
|
|||
return;
|
||||
}
|
||||
|
||||
if (level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
|
||||
increaseMemoryPressure(MEMORY_PRESSURE_HIGH);
|
||||
} else if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
|
||||
increaseMemoryPressure(MEMORY_PRESSURE_MEDIUM);
|
||||
} else if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
|
||||
// includes TRIM_MEMORY_BACKGROUND
|
||||
increaseMemoryPressure(MEMORY_PRESSURE_CLEANUP);
|
||||
} else {
|
||||
// levels down here mean gecko is the foreground process so we
|
||||
// should be less aggressive with wiping memory as it may impact
|
||||
// user experience.
|
||||
increaseMemoryPressure(MEMORY_PRESSURE_LOW);
|
||||
if (level == ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
|
||||
// We seem to get this just by entering the task switcher or hitting the home button.
|
||||
// Seems bogus, because we are the foreground app, or at least not at the end of the LRU list.
|
||||
// Just ignore it, and if there is a real memory pressure event (CRITICAL, MODERATE, etc),
|
||||
// we'll respond appropriately.
|
||||
return;
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
|
||||
case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
|
||||
// TRIM_MEMORY_MODERATE is the highest level we'll respond to while backgrounded
|
||||
increaseMemoryPressure(MEMORY_PRESSURE_HIGH);
|
||||
break;
|
||||
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
|
||||
increaseMemoryPressure(MEMORY_PRESSURE_MEDIUM);
|
||||
break;
|
||||
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
|
||||
increaseMemoryPressure(MEMORY_PRESSURE_LOW);
|
||||
break;
|
||||
case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
|
||||
case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
|
||||
increaseMemoryPressure(MEMORY_PRESSURE_CLEANUP);
|
||||
break;
|
||||
default:
|
||||
Log.d(LOGTAG, "Unhandled onTrimMemory() level " + level);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,6 +155,8 @@ class MemoryMonitor extends BroadcastReceiver {
|
|||
mMemoryPressure = level;
|
||||
}
|
||||
|
||||
Log.d(LOGTAG, "increasing memory pressure to " + level);
|
||||
|
||||
// since we don't get notifications for when memory pressure is off,
|
||||
// we schedule our own timer to slowly back off the memory pressure level.
|
||||
// note that this will reset the time to next decrement if the decrementer
|
||||
|
|
Загрузка…
Ссылка в новой задаче