diff options
author | Dianne Hackborn <hackbod@google.com> | 2011-07-13 19:33:41 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2011-07-14 10:39:39 -0700 |
commit | ce86ba86df61de8b34b226a4eb6c23ec33e866e0 (patch) | |
tree | bd6a8d599da38dd78c28f82cf0575b4294ff7199 /core | |
parent | f7537bccb2b2ca2fa6c0205c4b24acd0836c0006 (diff) | |
download | frameworks_base-ce86ba86df61de8b34b226a4eb6c23ec33e866e0.zip frameworks_base-ce86ba86df61de8b34b226a4eb6c23ec33e866e0.tar.gz frameworks_base-ce86ba86df61de8b34b226a4eb6c23ec33e866e0.tar.bz2 |
Improve handling of low memory.
Now classify background processes into a set of bins of how much
memory they should try to clear. The last bin also involves
destroying all activities in that process.
Removed the old code for the simulator that is no longer needed
(yay). The debugging features it had are now integrated into the
regular oom adj code.
Small fixes to load average service.
Change-Id: Ic8df401714b188c73b50dbc8f8e6345b58f1f3a0
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/app/ActivityThread.java | 11 | ||||
-rw-r--r-- | core/java/android/app/ApplicationThreadNative.java | 15 | ||||
-rw-r--r-- | core/java/android/app/IApplicationThread.java | 2 | ||||
-rw-r--r-- | core/java/android/content/ComponentCallbacks.java | 12 |
4 files changed, 40 insertions, 0 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index ee04729..8994b17 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -932,6 +932,10 @@ public final class ActivityThread { ucd.info = info; queueOrSendMessage(H.UPDATE_PACKAGE_COMPATIBILITY_INFO, ucd); } + + public void scheduleTrimMemory(int level) { + queueOrSendMessage(H.TRIM_MEMORY, level); + } } private final class H extends Handler { @@ -975,6 +979,7 @@ public final class ActivityThread { public static final int SLEEPING = 137; public static final int SET_CORE_SETTINGS = 138; public static final int UPDATE_PACKAGE_COMPATIBILITY_INFO = 139; + public static final int TRIM_MEMORY = 140; String codeToString(int code) { if (DEBUG_MESSAGES) { switch (code) { @@ -1018,6 +1023,7 @@ public final class ActivityThread { case SLEEPING: return "SLEEPING"; case SET_CORE_SETTINGS: return "SET_CORE_SETTINGS"; case UPDATE_PACKAGE_COMPATIBILITY_INFO: return "UPDATE_PACKAGE_COMPATIBILITY_INFO"; + case TRIM_MEMORY: return "TRIM_MEMORY"; } } return "(unknown)"; @@ -1158,6 +1164,8 @@ public final class ActivityThread { break; case UPDATE_PACKAGE_COMPATIBILITY_INFO: handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj); + case TRIM_MEMORY: + handleTrimMemory(msg.arg1); } if (DEBUG_MESSAGES) Slog.v(TAG, "<<< done: " + msg.what); } @@ -3529,6 +3537,9 @@ public final class ActivityThread { BinderInternal.forceGc("mem"); } + final void handleTrimMemory(int level) { + } + private final void handleBindApplication(AppBindData data) { mBoundApplication = data; mConfiguration = new Configuration(data.config); diff --git a/core/java/android/app/ApplicationThreadNative.java b/core/java/android/app/ApplicationThreadNative.java index dc0f529..16181e0 100644 --- a/core/java/android/app/ApplicationThreadNative.java +++ b/core/java/android/app/ApplicationThreadNative.java @@ -478,6 +478,13 @@ public abstract class ApplicationThreadNative extends Binder updatePackageCompatibilityInfo(pkg, compat); return true; } + + case SCHEDULE_TRIM_MEMORY_TRANSACTION: { + data.enforceInterface(IApplicationThread.descriptor); + int level = data.readInt(); + scheduleTrimMemory(level); + return true; + } } return super.onTransact(code, data, reply, flags); @@ -989,4 +996,12 @@ class ApplicationThreadProxy implements IApplicationThread { mRemote.transact(UPDATE_PACKAGE_COMPATIBILITY_INFO_TRANSACTION, data, null, IBinder.FLAG_ONEWAY); } + + public void scheduleTrimMemory(int level) throws RemoteException { + Parcel data = Parcel.obtain(); + data.writeInterfaceToken(IApplicationThread.descriptor); + data.writeInt(level); + mRemote.transact(SCHEDULE_TRIM_MEMORY_TRANSACTION, data, null, + IBinder.FLAG_ONEWAY); + } } diff --git a/core/java/android/app/IApplicationThread.java b/core/java/android/app/IApplicationThread.java index 05a68a8..94c2c86 100644 --- a/core/java/android/app/IApplicationThread.java +++ b/core/java/android/app/IApplicationThread.java @@ -119,6 +119,7 @@ public interface IApplicationThread extends IInterface { throws RemoteException; void setCoreSettings(Bundle coreSettings) throws RemoteException; void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) throws RemoteException; + void scheduleTrimMemory(int level) throws RemoteException; String descriptor = "android.app.IApplicationThread"; @@ -162,4 +163,5 @@ public interface IApplicationThread extends IInterface { int SET_HTTP_PROXY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+38; int SET_CORE_SETTINGS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+39; int UPDATE_PACKAGE_COMPATIBILITY_INFO_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+40; + int SCHEDULE_TRIM_MEMORY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+41; } diff --git a/core/java/android/content/ComponentCallbacks.java b/core/java/android/content/ComponentCallbacks.java index dad60b0..92b98fd 100644 --- a/core/java/android/content/ComponentCallbacks.java +++ b/core/java/android/content/ComponentCallbacks.java @@ -51,4 +51,16 @@ public interface ComponentCallbacks { * The system will perform a gc for you after returning from this method. */ void onLowMemory(); + + /** @hide */ + static final int TRIM_MEMORY_COMPLETE = 80; + + /** @hide */ + static final int TRIM_MEMORY_MODERATE = 60; + + /** @hide */ + static final int TRIM_MEMORY_BACKGROUND = 40; + + /** @hide */ + static final int TRIM_MEMORY_INVISIBLE = 20; } |