Various work on out of memory managment.
- Improve how we handle processes that have shown UI, to take care
of more cases where we want to push them into the background LRU
list.
- New trim memory level for when an application that has done UI
is no longer visible to the user.
- Add APIs to get new trim memory callback.
- Add a host of new bind flags to tweak how the system will adjust
the OOM level of the target process.
Change-Id: I23ba354112f411a9f8773a67426b4dff85fa2439
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 1e93f88..8931675 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -18,7 +18,7 @@
import android.app.backup.BackupAgent;
import android.content.BroadcastReceiver;
-import android.content.ComponentCallbacks;
+import android.content.ComponentCallbacks2;
import android.content.ComponentName;
import android.content.ContentProvider;
import android.content.Context;
@@ -3258,10 +3258,10 @@
}
}
- ArrayList<ComponentCallbacks> collectComponentCallbacksLocked(
+ ArrayList<ComponentCallbacks2> collectComponentCallbacksLocked(
boolean allActivities, Configuration newConfig) {
- ArrayList<ComponentCallbacks> callbacks
- = new ArrayList<ComponentCallbacks>();
+ ArrayList<ComponentCallbacks2> callbacks
+ = new ArrayList<ComponentCallbacks2>();
if (mActivities.size() > 0) {
Iterator<ActivityClientRecord> it = mActivities.values().iterator();
@@ -3311,10 +3311,10 @@
return callbacks;
}
- private void performConfigurationChanged(
- ComponentCallbacks cb, Configuration config) {
+ private final void performConfigurationChanged(
+ ComponentCallbacks2 cb, Configuration config) {
// Only for Activity objects, check that they actually call up to their
- // superclass implementation. ComponentCallbacks is an interface, so
+ // superclass implementation. ComponentCallbacks2 is an interface, so
// we check the runtime type and act accordingly.
Activity activity = (cb instanceof Activity) ? (Activity) cb : null;
if (activity != null) {
@@ -3418,7 +3418,7 @@
final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) {
- ArrayList<ComponentCallbacks> callbacks = null;
+ ArrayList<ComponentCallbacks2> callbacks = null;
synchronized (mPackages) {
if (mPendingConfiguration != null) {
@@ -3558,7 +3558,7 @@
}
final void handleLowMemory() {
- ArrayList<ComponentCallbacks> callbacks;
+ ArrayList<ComponentCallbacks2> callbacks;
synchronized (mPackages) {
callbacks = collectComponentCallbacksLocked(true, null);
@@ -3583,6 +3583,16 @@
final void handleTrimMemory(int level) {
WindowManagerImpl.getDefault().trimMemory(level);
+ ArrayList<ComponentCallbacks2> callbacks;
+
+ synchronized (mPackages) {
+ callbacks = collectComponentCallbacksLocked(true, null);
+ }
+
+ final int N = callbacks.size();
+ for (int i=0; i<N; i++) {
+ callbacks.get(i).onTrimMemory(level);
+ }
}
private void handleBindApplication(AppBindData data) {
@@ -4128,7 +4138,7 @@
}
}
- ViewRootImpl.addConfigCallback(new ComponentCallbacks() {
+ ViewRootImpl.addConfigCallback(new ComponentCallbacks2() {
public void onConfigurationChanged(Configuration newConfig) {
synchronized (mPackages) {
// We need to apply this change to the resources
@@ -4148,6 +4158,8 @@
}
public void onLowMemory() {
}
+ public void onTrimMemory(int level) {
+ }
});
}