summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2011-07-29 01:25:18 -0700
committerDianne Hackborn <hackbod@google.com>2011-07-29 02:06:46 -0700
commitc68c913d357e2955d4bd7ca52829071e531c7825 (patch)
tree764dddf699a1db5e44d74e94e3f354b9ed61ff71 /core/java
parent3970f6833d3c19f96cc7b6831327c8488932fa57 (diff)
downloadframeworks_base-c68c913d357e2955d4bd7ca52829071e531c7825.zip
frameworks_base-c68c913d357e2955d4bd7ca52829071e531c7825.tar.gz
frameworks_base-c68c913d357e2955d4bd7ca52829071e531c7825.tar.bz2
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
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/Activity.java22
-rw-r--r--core/java/android/app/ActivityThread.java32
-rw-r--r--core/java/android/app/Application.java160
-rw-r--r--core/java/android/app/ContextImpl.java6
-rw-r--r--core/java/android/app/Fragment.java8
-rw-r--r--core/java/android/app/FragmentManager.java11
-rw-r--r--core/java/android/app/Service.java9
-rw-r--r--core/java/android/content/ComponentCallbacks.java9
-rw-r--r--core/java/android/content/ComponentCallbacks2.java66
-rw-r--r--core/java/android/content/ContentProvider.java5
-rw-r--r--core/java/android/content/Context.java82
-rw-r--r--core/java/android/view/HardwareRenderer.java6
-rw-r--r--core/java/android/view/ViewRootImpl.java3
13 files changed, 371 insertions, 48 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index fb1570e..d5b669e 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -19,7 +19,7 @@ package android.app;
import com.android.internal.app.ActionBarImpl;
import com.android.internal.policy.PolicyManager;
-import android.content.ComponentCallbacks;
+import android.content.ComponentCallbacks2;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -626,7 +626,7 @@ import java.util.HashMap;
public class Activity extends ContextThemeWrapper
implements LayoutInflater.Factory2,
Window.Callback, KeyEvent.Callback,
- OnCreateContextMenuListener, ComponentCallbacks {
+ OnCreateContextMenuListener, ComponentCallbacks2 {
private static final String TAG = "Activity";
/** Standard activity result: operation canceled. */
@@ -859,6 +859,7 @@ public class Activity extends ContextThemeWrapper
? mLastNonConfigurationInstances.fragments : null);
}
mFragments.dispatchCreate();
+ getApplication().dispatchActivityCreated(this, savedInstanceState);
mCalled = true;
}
@@ -1001,6 +1002,8 @@ public class Activity extends ContextThemeWrapper
}
mCheckedForLoaderManager = true;
}
+
+ getApplication().dispatchActivityStarted(this);
}
/**
@@ -1048,6 +1051,7 @@ public class Activity extends ContextThemeWrapper
* @see #onPause
*/
protected void onResume() {
+ getApplication().dispatchActivityResumed(this);
mCalled = true;
}
@@ -1158,6 +1162,7 @@ public class Activity extends ContextThemeWrapper
if (p != null) {
outState.putParcelable(FRAGMENTS_TAG, p);
}
+ getApplication().dispatchActivitySaveInstanceState(this, outState);
}
/**
@@ -1234,6 +1239,7 @@ public class Activity extends ContextThemeWrapper
* @see #onStop
*/
protected void onPause() {
+ getApplication().dispatchActivityPaused(this);
mCalled = true;
}
@@ -1320,6 +1326,7 @@ public class Activity extends ContextThemeWrapper
*/
protected void onStop() {
if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false);
+ getApplication().dispatchActivityStopped(this);
mCalled = true;
}
@@ -1382,6 +1389,8 @@ public class Activity extends ContextThemeWrapper
if (mSearchManager != null) {
mSearchManager.stopSearch();
}
+
+ getApplication().dispatchActivityDestroyed(this);
}
/**
@@ -1580,12 +1589,17 @@ public class Activity extends ContextThemeWrapper
nci.loaders = mAllLoaderManagers;
return nci;
}
-
+
public void onLowMemory() {
mCalled = true;
mFragments.dispatchLowMemory();
}
-
+
+ public void onTrimMemory(int level) {
+ mCalled = true;
+ mFragments.dispatchTrimMemory(level);
+ }
+
/**
* Return the FragmentManager for interacting with fragments associated
* with this activity.
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 @@ package android.app;
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 @@ public final class ActivityThread {
}
}
- 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 @@ public final class ActivityThread {
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 @@ public final class ActivityThread {
final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) {
- ArrayList<ComponentCallbacks> callbacks = null;
+ ArrayList<ComponentCallbacks2> callbacks = null;
synchronized (mPackages) {
if (mPendingConfiguration != null) {
@@ -3558,7 +3558,7 @@ public final class ActivityThread {
}
final void handleLowMemory() {
- ArrayList<ComponentCallbacks> callbacks;
+ ArrayList<ComponentCallbacks2> callbacks;
synchronized (mPackages) {
callbacks = collectComponentCallbacksLocked(true, null);
@@ -3583,6 +3583,16 @@ public final class ActivityThread {
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 @@ public final class ActivityThread {
}
}
- 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 final class ActivityThread {
}
public void onLowMemory() {
}
+ public void onTrimMemory(int level) {
+ }
});
}
diff --git a/core/java/android/app/Application.java b/core/java/android/app/Application.java
index 10cc9f8..dd9ea26 100644
--- a/core/java/android/app/Application.java
+++ b/core/java/android/app/Application.java
@@ -16,10 +16,14 @@
package android.app;
+import java.util.ArrayList;
+
import android.content.ComponentCallbacks;
+import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Configuration;
+import android.os.Bundle;
/**
* Base class for those who need to maintain global application state. You can
@@ -36,10 +40,25 @@ import android.content.res.Configuration;
* {@link android.content.Context#getApplicationContext() Context.getApplicationContext()}
* when first constructing the singleton.</p>
*/
-public class Application extends ContextWrapper implements ComponentCallbacks {
+public class Application extends ContextWrapper implements ComponentCallbacks2 {
+ private ArrayList<ComponentCallbacks> mComponentCallbacks =
+ new ArrayList<ComponentCallbacks>();
+ private ArrayList<ActivityLifecycleCallbacks> mActivityLifecycleCallbacks =
+ new ArrayList<ActivityLifecycleCallbacks>();
+
/** @hide */
public LoadedApk mLoadedApk;
-
+
+ public interface ActivityLifecycleCallbacks {
+ void onActivityCreated(Activity activity, Bundle savedInstanceState);
+ void onActivityStarted(Activity activity);
+ void onActivityResumed(Activity activity);
+ void onActivityPaused(Activity activity);
+ void onActivityStopped(Activity activity);
+ void onActivitySaveInstanceState(Activity activity, Bundle outState);
+ void onActivityDestroyed(Activity activity);
+ }
+
public Application() {
super(null);
}
@@ -63,11 +82,59 @@ public class Application extends ContextWrapper implements ComponentCallbacks {
*/
public void onTerminate() {
}
-
+
public void onConfigurationChanged(Configuration newConfig) {
+ Object[] callbacks = collectComponentCallbacks();
+ if (callbacks != null) {
+ for (int i=0; i<callbacks.length; i++) {
+ ((ComponentCallbacks)callbacks[i]).onConfigurationChanged(newConfig);
+ }
+ }
}
-
+
public void onLowMemory() {
+ Object[] callbacks = collectComponentCallbacks();
+ if (callbacks != null) {
+ for (int i=0; i<callbacks.length; i++) {
+ ((ComponentCallbacks)callbacks[i]).onLowMemory();
+ }
+ }
+ }
+
+ public void onTrimMemory(int level) {
+ Object[] callbacks = collectComponentCallbacks();
+ if (callbacks != null) {
+ for (int i=0; i<callbacks.length; i++) {
+ Object c = callbacks[i];
+ if (c instanceof ComponentCallbacks2) {
+ ((ComponentCallbacks2)c).onTrimMemory(level);
+ }
+ }
+ }
+ }
+
+ public void registerComponentCallbacks(ComponentCallbacks callback) {
+ synchronized (mComponentCallbacks) {
+ mComponentCallbacks.add(callback);
+ }
+ }
+
+ public void unregisterComponentCallbacks(ComponentCallbacks callback) {
+ synchronized (mComponentCallbacks) {
+ mComponentCallbacks.remove(callback);
+ }
+ }
+
+ public void registerActivityLifecycleCallbacks(ActivityLifecycleCallbacks callback) {
+ synchronized (mActivityLifecycleCallbacks) {
+ mActivityLifecycleCallbacks.add(callback);
+ }
+ }
+
+ public void unregisterActivityLifecycleCallbacks(ActivityLifecycleCallbacks callback) {
+ synchronized (mActivityLifecycleCallbacks) {
+ mActivityLifecycleCallbacks.remove(callback);
+ }
}
// ------------------ Internal API ------------------
@@ -79,4 +146,89 @@ public class Application extends ContextWrapper implements ComponentCallbacks {
attachBaseContext(context);
mLoadedApk = ContextImpl.getImpl(context).mPackageInfo;
}
+
+ /* package */ void dispatchActivityCreated(Activity activity, Bundle savedInstanceState) {
+ Object[] callbacks = collectActivityLifecycleCallbacks();
+ if (callbacks != null) {
+ for (int i=0; i<callbacks.length; i++) {
+ ((ActivityLifecycleCallbacks)callbacks[i]).onActivityCreated(activity,
+ savedInstanceState);
+ }
+ }
+ }
+
+ /* package */ void dispatchActivityStarted(Activity activity) {
+ Object[] callbacks = collectActivityLifecycleCallbacks();
+ if (callbacks != null) {
+ for (int i=0; i<callbacks.length; i++) {
+ ((ActivityLifecycleCallbacks)callbacks[i]).onActivityStarted(activity);
+ }
+ }
+ }
+
+ /* package */ void dispatchActivityResumed(Activity activity) {
+ Object[] callbacks = collectActivityLifecycleCallbacks();
+ if (callbacks != null) {
+ for (int i=0; i<callbacks.length; i++) {
+ ((ActivityLifecycleCallbacks)callbacks[i]).onActivityResumed(activity);
+ }
+ }
+ }
+
+ /* package */ void dispatchActivityPaused(Activity activity) {
+ Object[] callbacks = collectActivityLifecycleCallbacks();
+ if (callbacks != null) {
+ for (int i=0; i<callbacks.length; i++) {
+ ((ActivityLifecycleCallbacks)callbacks[i]).onActivityPaused(activity);
+ }
+ }
+ }
+
+ /* package */ void dispatchActivityStopped(Activity activity) {
+ Object[] callbacks = collectActivityLifecycleCallbacks();
+ if (callbacks != null) {
+ for (int i=0; i<callbacks.length; i++) {
+ ((ActivityLifecycleCallbacks)callbacks[i]).onActivityStopped(activity);
+ }
+ }
+ }
+
+ /* package */ void dispatchActivitySaveInstanceState(Activity activity, Bundle outState) {
+ Object[] callbacks = collectActivityLifecycleCallbacks();
+ if (callbacks != null) {
+ for (int i=0; i<callbacks.length; i++) {
+ ((ActivityLifecycleCallbacks)callbacks[i]).onActivitySaveInstanceState(activity,
+ outState);
+ }
+ }
+ }
+
+ /* package */ void dispatchActivityDestroyed(Activity activity) {
+ Object[] callbacks = collectActivityLifecycleCallbacks();
+ if (callbacks != null) {
+ for (int i=0; i<callbacks.length; i++) {
+ ((ActivityLifecycleCallbacks)callbacks[i]).onActivityDestroyed(activity);
+ }
+ }
+ }
+
+ private Object[] collectComponentCallbacks() {
+ Object[] callbacks = null;
+ synchronized (mComponentCallbacks) {
+ if (mComponentCallbacks.size() > 0) {
+ callbacks = mComponentCallbacks.toArray();
+ }
+ }
+ return callbacks;
+ }
+
+ private Object[] collectActivityLifecycleCallbacks() {
+ Object[] callbacks = null;
+ synchronized (mActivityLifecycleCallbacks) {
+ if (mActivityLifecycleCallbacks.size() > 0) {
+ callbacks = mActivityLifecycleCallbacks.toArray();
+ }
+ }
+ return callbacks;
+ }
}
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index a99cec2..b4bdb2f 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -1109,6 +1109,12 @@ class ContextImpl extends Context {
throw new RuntimeException("Not supported in system context");
}
try {
+ IBinder token = getActivityToken();
+ if (token == null && (flags&BIND_AUTO_CREATE) == 0 && mPackageInfo != null
+ && mPackageInfo.getApplicationInfo().targetSdkVersion
+ < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ flags |= BIND_WAIVE_PRIORITY;
+ }
int res = ActivityManagerNative.getDefault().bindService(
mMainThread.getApplicationThread(), getActivityToken(),
service, service.resolveTypeIfNeeded(getContentResolver()),
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java
index e2746d4..371e7ad 100644
--- a/core/java/android/app/Fragment.java
+++ b/core/java/android/app/Fragment.java
@@ -17,7 +17,7 @@
package android.app;
import android.animation.Animator;
-import android.content.ComponentCallbacks;
+import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
@@ -332,7 +332,7 @@ final class FragmentState implements Parcelable {
* pressing back will pop it to return the user to whatever previous state
* the activity UI was in.
*/
-public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener {
+public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListener {
private static final HashMap<String, Class<?>> sClassMap =
new HashMap<String, Class<?>>();
@@ -1182,6 +1182,10 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener
mCalled = true;
}
+ public void onTrimMemory(int level) {
+ mCalled = true;
+ }
+
/**
* Called when the view previously created by {@link #onCreateView} has
* been detached from the fragment. The next time the fragment needs
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index 24550c5..c33ab2c 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -1722,6 +1722,17 @@ final class FragmentManagerImpl extends FragmentManager {
}
}
+ public void dispatchTrimMemory(int level) {
+ if (mActive != null) {
+ for (int i=0; i<mAdded.size(); i++) {
+ Fragment f = mAdded.get(i);
+ if (f != null) {
+ f.onTrimMemory(level);
+ }
+ }
+ }
+ }
+
public boolean dispatchCreateOptionsMenu(Menu menu, MenuInflater inflater) {
boolean show = false;
ArrayList<Fragment> newMenus = null;
diff --git a/core/java/android/app/Service.java b/core/java/android/app/Service.java
index 4c21d04..ebde6e0 100644
--- a/core/java/android/app/Service.java
+++ b/core/java/android/app/Service.java
@@ -16,7 +16,7 @@
package android.app;
-import android.content.ComponentCallbacks;
+import android.content.ComponentCallbacks2;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ContextWrapper;
@@ -274,7 +274,7 @@ import java.io.PrintWriter;
* {@sample development/samples/ApiDemos/src/com/example/android/apis/app/MessengerServiceActivities.java
* bind}
*/
-public abstract class Service extends ContextWrapper implements ComponentCallbacks {
+public abstract class Service extends ContextWrapper implements ComponentCallbacks2 {
private static final String TAG = "Service";
public Service() {
@@ -451,7 +451,10 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac
public void onLowMemory() {
}
-
+
+ public void onTrimMemory(int level) {
+ }
+
/**
* Return the communication channel to the service. May return null if
* clients can not bind to the service. The returned
diff --git a/core/java/android/content/ComponentCallbacks.java b/core/java/android/content/ComponentCallbacks.java
index 37cc141..dad60b0 100644
--- a/core/java/android/content/ComponentCallbacks.java
+++ b/core/java/android/content/ComponentCallbacks.java
@@ -51,13 +51,4 @@ 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 = 50;
-
- /** @hide */
- static final int TRIM_MEMORY_BACKGROUND = 20;
}
diff --git a/core/java/android/content/ComponentCallbacks2.java b/core/java/android/content/ComponentCallbacks2.java
new file mode 100644
index 0000000..8b9f97c
--- /dev/null
+++ b/core/java/android/content/ComponentCallbacks2.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.content;
+
+/**
+ * Extended {@link ComponentCallbacks} interface with a new callback for
+ * finer-grained memory management.
+ */
+public interface ComponentCallbacks2 extends ComponentCallbacks {
+
+ /**
+ * Level for {@link #onTrimMemory(int)}: the process is nearing the end
+ * of the background LRU list, and if more memory isn't found soon it will
+ * be killed.
+ */
+ static final int TRIM_MEMORY_COMPLETE = 80;
+
+ /**
+ * Level for {@link #onTrimMemory(int)}: the process is around the middle
+ * of the background LRU list; freeing memory can help the system keep
+ * other processes running later in the list for better overall performance.
+ */
+ static final int TRIM_MEMORY_MODERATE = 60;
+
+ /**
+ * Level for {@link #onTrimMemory(int)}: the process has gone on to the
+ * LRU list. This is a good opportunity to clean up resources that can
+ * efficiently and quickly be re-built if the user returns to the app.
+ */
+ static final int TRIM_MEMORY_BACKGROUND = 40;
+
+ /**
+ * Level for {@link #onTrimMemory(int)}: the process had been showing
+ * a user interface, and is no longer doing so. Large allocations with
+ * the UI should be released at this point to allow memory to be better
+ * managed.
+ */
+ static final int TRIM_MEMORY_UI_HIDDEN = 20;
+
+ /**
+ * Called when the operating system has determined that it is a good
+ * time for a process to trim unneeded memory from its process. This will
+ * happen for example when it goes in the background and there is not enough
+ * memory to keep as many background processes running as desired.
+ *
+ * @param level The context of the trim, giving a hint of the amount of
+ * trimming the application may like to perform. May be
+ * {@link #TRIM_MEMORY_COMPLETE}, {@link #TRIM_MEMORY_MODERATE},
+ * {@link #TRIM_MEMORY_BACKGROUND}, or {@link #TRIM_MEMORY_UI_HIDDEN}.
+ */
+ void onTrimMemory(int level);
+}
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index 1a5c675..8057d4b 100644
--- a/core/java/android/content/ContentProvider.java
+++ b/core/java/android/content/ContentProvider.java
@@ -78,7 +78,7 @@ import java.util.ArrayList;
* ContentProvider instance, so subclasses don't have to worry about the details of
* cross-process calls.</p>
*/
-public abstract class ContentProvider implements ComponentCallbacks {
+public abstract class ContentProvider implements ComponentCallbacks2 {
private static final String TAG = "ContentProvider";
/*
@@ -491,6 +491,9 @@ public abstract class ContentProvider implements ComponentCallbacks {
public void onLowMemory() {
}
+ public void onTrimMemory(int level) {
+ }
+
/**
* Implement this to handle query requests from clients.
* This method can be called from multiple threads, as described in
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 2a02446..46712a9 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -107,12 +107,17 @@ public abstract class Context {
* this still provides you with access to the service object while the
* service is created.
*
- * <p>Specifying this flag also tells the system to treat the service
- * as being as important as your own process -- that is, when deciding
- * which process should be killed to free memory, the service will only
- * be considered a candidate as long as the processes of any such bindings
- * is also a candidate to be killed. This is to avoid situations where
- * the service is being continually created and killed due to low memory.
+ * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
+ * not supplying this flag would also impact how important the system
+ * consider's the target service's process to be. When set, the only way
+ * for it to be raised was by binding from a service in which case it will
+ * only be important when that activity is in the foreground. Now to
+ * achieve this behavior you must explicitly supply the new flag
+ * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
+ * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
+ * the flags {@link #BIND_WAIVE_PRIORITY} and
+ * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
+ * the same result.
*/
public static final int BIND_AUTO_CREATE = 0x0001;
@@ -139,14 +144,48 @@ public abstract class Context {
public static final int BIND_NOT_FOREGROUND = 0x0004;
/**
+ * Flag for {@link #bindService}: indicates that the client application
+ * binding to this service considers the service to be more important than
+ * the app itself. When set, the platform will try to have the out of
+ * memory kill the app before it kills the service it is bound to, though
+ * this is not guaranteed to be the case.
+ */
+ public static final int BIND_ABOVE_CLIENT = 0x0008;
+
+ /**
* Flag for {@link #bindService}: allow the process hosting the bound
* service to go through its normal memory management. It will be
* treated more like a running service, allowing the system to
* (temporarily) expunge the process if low on memory or for some other
- * whim it may have.
- * @hide
+ * whim it may have, and being more aggressive about making it a candidate
+ * to be killed (and restarted) if running for a long time.
*/
- public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0008;
+ public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
+
+ /**
+ * Flag for {@link #bindService}: don't impact the scheduling or
+ * memory management priority of the target service's hosting process.
+ * Allows the service's process to be managed on the background LRU list
+ * just like a regular application process in the background.
+ */
+ public static final int BIND_WAIVE_PRIORITY = 0x0020;
+
+ /**
+ * Flag for {@link #bindService}: this service is very important to
+ * the client, so should be brought to the foreground process level
+ * when the client is. Normally a process can only be raised to the
+ * visibility level by a client, even if that client is in the foreground.
+ */
+ public static final int BIND_IMPORTANT = 0x0040;
+
+ /**
+ * Flag for {@link #bindService}: If binding from an activity, allow the
+ * target service's process importance to be raised based on whether the
+ * activity is visible to the user, regardless whether another flag is
+ * used to reduce the amount that the client process's overall importance
+ * is used to impact it.
+ */
+ public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0040;
/** Return an AssetManager instance for your application's package. */
public abstract AssetManager getAssets();
@@ -195,6 +234,25 @@ public abstract class Context {
public abstract Context getApplicationContext();
/**
+ * Add a new {@link ComponentCallbacks} to the base application of the
+ * Context, which will be called at the same times as the ComponentCallbacks
+ * methods of activities and other components are called. Note that you
+ * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
+ * appropriate in the future; this will not be removed for you.
+ */
+ public void registerComponentCallbacks(ComponentCallbacks callback) {
+ getApplicationContext().registerComponentCallbacks(callback);
+ }
+
+ /**
+ * Remove a {@link ComponentCallbacks} objec that was previously registered
+ * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
+ */
+ public void unregisterComponentCallbacks(ComponentCallbacks callback) {
+ getApplicationContext().unregisterComponentCallbacks(callback);
+ }
+
+ /**
* Return a localized, styled CharSequence from the application's package's
* default string table.
*
@@ -1219,8 +1277,10 @@ public abstract class Context {
* {@link IntentFilter} published by a service.
* @param conn Receives information as the service is started and stopped.
* @param flags Operation options for the binding. May be 0,
- * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND}, or
- * {@link #BIND_NOT_FOREGROUND}.
+ * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
+ * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
+ * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
+ * {@link #BIND_WAIVE_PRIORITY}.
* @return If you have successfully bound to the service, true is returned;
* false is returned if the connection is not made so you will not
* receive the service object.
diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java
index 4e4923b..4e20358 100644
--- a/core/java/android/view/HardwareRenderer.java
+++ b/core/java/android/view/HardwareRenderer.java
@@ -17,7 +17,7 @@
package android.view;
-import android.content.ComponentCallbacks;
+import android.content.ComponentCallbacks2;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
@@ -975,10 +975,10 @@ public abstract class HardwareRenderer {
}
switch (level) {
- case ComponentCallbacks.TRIM_MEMORY_MODERATE:
+ case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_MODERATE);
break;
- case ComponentCallbacks.TRIM_MEMORY_COMPLETE:
+ case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_FULL);
break;
}
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 0bd5a2a..b22ab7e 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -21,6 +21,7 @@ import android.animation.LayoutTransition;
import android.app.ActivityManagerNative;
import android.content.ClipDescription;
import android.content.ComponentCallbacks;
+import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.CompatibilityInfo;
@@ -554,7 +555,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,
if (mThread != Thread.currentThread()) {
if (mAttachInfo.mHardwareRenderer != null &&
mAttachInfo.mHardwareRenderer.isEnabled()) {
- HardwareRenderer.trimMemory(ComponentCallbacks.TRIM_MEMORY_MODERATE);
+ HardwareRenderer.trimMemory(ComponentCallbacks2.TRIM_MEMORY_MODERATE);
}
} else {
if (mAttachInfo.mHardwareRenderer != null &&