am af9788a9: Merge change Ia53c6725 into eclair-mr2

Merge commit 'af9788a9d6c238dd97f40dc020e036739daf0811' into eclair-mr2-plus-aosp

* commit 'af9788a9d6c238dd97f40dc020e036739daf0811':
  Add bindService API to not bring ot foreground.
This commit is contained in:
Dianne Hackborn
2009-12-09 15:55:28 -08:00
committed by Android Git Automerger
4 changed files with 127 additions and 20 deletions

View File

@@ -32352,6 +32352,17 @@
visibility="public" visibility="public"
> >
</field> </field>
<field name="BIND_NOT_FOREGROUND"
type="int"
transient="false"
volatile="false"
value="4"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="CLIPBOARD_SERVICE" <field name="CLIPBOARD_SERVICE"
type="java.lang.String" type="java.lang.String"
transient="false" transient="false"

View File

@@ -104,6 +104,18 @@ public abstract class Context {
*/ */
public static final int BIND_DEBUG_UNBIND = 0x0002; public static final int BIND_DEBUG_UNBIND = 0x0002;
/**
* Flag for {@link #bindService}: don't allow this binding to raise
* the target service's process to the foreground scheduling priority.
* It will still be raised to the at least the same memory priority
* as the client (so that its process will not be killable in any
* situation where the client is not killable), but for CPU scheduling
* purposes it may be left in the background. This only has an impact
* in the situation where the binding client is a foreground process
* and the target service is in a background process.
*/
public static final int BIND_NOT_FOREGROUND = 0x0004;
/** Return an AssetManager instance for your application's package. */ /** Return an AssetManager instance for your application's package. */
public abstract AssetManager getAssets(); public abstract AssetManager getAssets();

View File

@@ -557,7 +557,7 @@ class SyncManager implements OnAccountsUpdateListener {
intent.setAction("android.content.SyncAdapter"); intent.setAction("android.content.SyncAdapter");
intent.setComponent(syncAdapterInfo.componentName); intent.setComponent(syncAdapterInfo.componentName);
mContext.bindService(intent, new InitializerServiceConnection(account, authority), mContext.bindService(intent, new InitializerServiceConnection(account, authority),
Context.BIND_AUTO_CREATE); Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND);
} }
private class InitializerServiceConnection implements ServiceConnection { private class InitializerServiceConnection implements ServiceConnection {
@@ -1145,7 +1145,8 @@ class SyncManager implements OnAccountsUpdateListener {
com.android.internal.R.string.sync_binding_label); com.android.internal.R.string.sync_binding_label);
intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
mContext, 0, new Intent(Settings.ACTION_SYNC_SETTINGS), 0)); mContext, 0, new Intent(Settings.ACTION_SYNC_SETTINGS), 0));
return mContext.bindService(intent, this, Context.BIND_AUTO_CREATE); return mContext.bindService(intent, this,
Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND);
} }
void unBindFromSyncAdapter() { void unBindFromSyncAdapter() {

View File

@@ -5258,7 +5258,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
app.thread = thread; app.thread = thread;
app.curAdj = app.setAdj = -100; app.curAdj = app.setAdj = -100;
app.curSchedGroup = app.setSchedGroup = Process.THREAD_GROUP_DEFAULT; app.curSchedGroup = Process.THREAD_GROUP_DEFAULT;
app.setSchedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
app.forcingToForeground = null; app.forcingToForeground = null;
app.foregroundServices = false; app.foregroundServices = false;
app.debugging = false; app.debugging = false;
@@ -9134,7 +9135,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
if (needSep) pw.println(" "); if (needSep) pw.println(" ");
needSep = true; needSep = true;
pw.println(" Running processes (most recent first):"); pw.println(" Running processes (most recent first):");
dumpProcessList(pw, mLRUProcesses, " ", dumpProcessList(pw, this, mLRUProcesses, " ",
"App ", "PERS", true); "App ", "PERS", true);
needSep = true; needSep = true;
} }
@@ -9165,7 +9166,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
if (needSep) pw.println(" "); if (needSep) pw.println(" ");
needSep = true; needSep = true;
pw.println(" Persisent processes that are starting:"); pw.println(" Persisent processes that are starting:");
dumpProcessList(pw, mPersistentStartingProcesses, " ", dumpProcessList(pw, this, mPersistentStartingProcesses, " ",
"Starting Norm", "Restarting PERS", false); "Starting Norm", "Restarting PERS", false);
} }
@@ -9173,7 +9174,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
if (needSep) pw.println(" "); if (needSep) pw.println(" ");
needSep = true; needSep = true;
pw.println(" Processes that are starting:"); pw.println(" Processes that are starting:");
dumpProcessList(pw, mStartingProcesses, " ", dumpProcessList(pw, this, mStartingProcesses, " ",
"Starting Norm", "Starting PERS", false); "Starting Norm", "Starting PERS", false);
} }
@@ -9181,7 +9182,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
if (needSep) pw.println(" "); if (needSep) pw.println(" ");
needSep = true; needSep = true;
pw.println(" Processes that are being removed:"); pw.println(" Processes that are being removed:");
dumpProcessList(pw, mRemovedProcesses, " ", dumpProcessList(pw, this, mRemovedProcesses, " ",
"Removed Norm", "Removed PERS", false); "Removed Norm", "Removed PERS", false);
} }
@@ -9189,7 +9190,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
if (needSep) pw.println(" "); if (needSep) pw.println(" ");
needSep = true; needSep = true;
pw.println(" Processes that are on old until the system is ready:"); pw.println(" Processes that are on old until the system is ready:");
dumpProcessList(pw, mProcessesOnHold, " ", dumpProcessList(pw, this, mProcessesOnHold, " ",
"OnHold Norm", "OnHold PERS", false); "OnHold Norm", "OnHold PERS", false);
} }
@@ -9618,7 +9619,16 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
} }
} }
private static final int dumpProcessList(PrintWriter pw, List list, private static String buildOomTag(String prefix, String space, int val, int base) {
if (val == base) {
if (space == null) return prefix;
return prefix + " ";
}
return prefix + "+" + Integer.toString(val-base);
}
private static final int dumpProcessList(PrintWriter pw,
ActivityManagerService service, List list,
String prefix, String normalLabel, String persistentLabel, String prefix, String normalLabel, String persistentLabel,
boolean inclOomAdj) { boolean inclOomAdj) {
int numPers = 0; int numPers = 0;
@@ -9629,9 +9639,55 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
+ " #" + i + ":"); + " #" + i + ":");
r.dump(pw, prefix + " "); r.dump(pw, prefix + " ");
} else if (inclOomAdj) { } else if (inclOomAdj) {
pw.println(String.format("%s%s #%2d: adj=%4d/%d %s (%s)", String oomAdj;
if (r.setAdj >= EMPTY_APP_ADJ) {
oomAdj = buildOomTag("empty", null, r.setAdj,
EMPTY_APP_ADJ);
} else if (r.setAdj >= CONTENT_PROVIDER_ADJ) {
oomAdj = buildOomTag("cprov", null, r.setAdj,
CONTENT_PROVIDER_ADJ);
} else if (r.setAdj >= HIDDEN_APP_MIN_ADJ) {
oomAdj = buildOomTag("hid", " ", r.setAdj,
HIDDEN_APP_MIN_ADJ);
} else if (r.setAdj >= service.HOME_APP_ADJ) {
oomAdj = buildOomTag("home ", null, r.setAdj,
service.HOME_APP_ADJ);
} else if (r.setAdj >= service.SECONDARY_SERVER_ADJ) {
oomAdj = buildOomTag("svc", " ", r.setAdj,
service.SECONDARY_SERVER_ADJ);
} else if (r.setAdj >= service.BACKUP_APP_ADJ) {
oomAdj = buildOomTag("bckup", null, r.setAdj,
service.BACKUP_APP_ADJ);
} else if (r.setAdj >= service.VISIBLE_APP_ADJ) {
oomAdj = buildOomTag("vis ", null, r.setAdj,
service.VISIBLE_APP_ADJ);
} else if (r.setAdj >= service.FOREGROUND_APP_ADJ) {
oomAdj = buildOomTag("fore ", null, r.setAdj,
service.FOREGROUND_APP_ADJ);
} else if (r.setAdj >= CORE_SERVER_ADJ) {
oomAdj = buildOomTag("core ", null, r.setAdj,
CORE_SERVER_ADJ);
} else if (r.setAdj >= SYSTEM_ADJ) {
oomAdj = buildOomTag("sys ", null, r.setAdj,
SYSTEM_ADJ);
} else {
oomAdj = Integer.toString(r.setAdj);
}
String schedGroup;
switch (r.setSchedGroup) {
case Process.THREAD_GROUP_BG_NONINTERACTIVE:
schedGroup = "B";
break;
case Process.THREAD_GROUP_DEFAULT:
schedGroup = "F";
break;
default:
schedGroup = Integer.toString(r.setSchedGroup);
break;
}
pw.println(String.format("%s%s #%2d: adj=%s/%s %s (%s)",
prefix, (r.persistent ? persistentLabel : normalLabel), prefix, (r.persistent ? persistentLabel : normalLabel),
i, r.setAdj, r.setSchedGroup, r.toString(), r.adjType)); i, oomAdj, schedGroup, r.toString(), r.adjType));
if (r.adjSource != null || r.adjTarget != null) { if (r.adjSource != null || r.adjTarget != null) {
pw.println(prefix + " " + r.adjTarget pw.println(prefix + " " + r.adjTarget
+ " used by " + r.adjSource); + " used by " + r.adjSource);
@@ -13039,6 +13095,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
if (app.thread == null) { if (app.thread == null) {
app.adjSeq = mAdjSeq; app.adjSeq = mAdjSeq;
app.curSchedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
return (app.curAdj=EMPTY_APP_ADJ); return (app.curAdj=EMPTY_APP_ADJ);
} }
@@ -13059,52 +13116,63 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
// Determine the importance of the process, starting with most // Determine the importance of the process, starting with most
// important to least, and assign an appropriate OOM adjustment. // important to least, and assign an appropriate OOM adjustment.
int adj; int adj;
int schedGroup;
int N; int N;
if (app == TOP_APP) { if (app == TOP_APP) {
// The last app on the list is the foreground app. // The last app on the list is the foreground app.
adj = FOREGROUND_APP_ADJ; adj = FOREGROUND_APP_ADJ;
schedGroup = Process.THREAD_GROUP_DEFAULT;
app.adjType = "top-activity"; app.adjType = "top-activity";
} else if (app.instrumentationClass != null) { } else if (app.instrumentationClass != null) {
// Don't want to kill running instrumentation. // Don't want to kill running instrumentation.
adj = FOREGROUND_APP_ADJ; adj = FOREGROUND_APP_ADJ;
schedGroup = Process.THREAD_GROUP_DEFAULT;
app.adjType = "instrumentation"; app.adjType = "instrumentation";
} else if (app.persistentActivities > 0) { } else if (app.persistentActivities > 0) {
// Special persistent activities... shouldn't be used these days. // Special persistent activities... shouldn't be used these days.
adj = FOREGROUND_APP_ADJ; adj = FOREGROUND_APP_ADJ;
schedGroup = Process.THREAD_GROUP_DEFAULT;
app.adjType = "persistent"; app.adjType = "persistent";
} else if (app.curReceiver != null || } else if (app.curReceiver != null ||
(mPendingBroadcast != null && mPendingBroadcast.curApp == app)) { (mPendingBroadcast != null && mPendingBroadcast.curApp == app)) {
// An app that is currently receiving a broadcast also // An app that is currently receiving a broadcast also
// counts as being in the foreground. // counts as being in the foreground.
adj = FOREGROUND_APP_ADJ; adj = FOREGROUND_APP_ADJ;
schedGroup = Process.THREAD_GROUP_DEFAULT;
app.adjType = "broadcast"; app.adjType = "broadcast";
} else if (app.executingServices.size() > 0) { } else if (app.executingServices.size() > 0) {
// An app that is currently executing a service callback also // An app that is currently executing a service callback also
// counts as being in the foreground. // counts as being in the foreground.
adj = FOREGROUND_APP_ADJ; adj = FOREGROUND_APP_ADJ;
schedGroup = Process.THREAD_GROUP_DEFAULT;
app.adjType = "exec-service"; app.adjType = "exec-service";
} else if (app.foregroundServices) { } else if (app.foregroundServices) {
// The user is aware of this app, so make it visible. // The user is aware of this app, so make it visible.
adj = VISIBLE_APP_ADJ; adj = VISIBLE_APP_ADJ;
schedGroup = Process.THREAD_GROUP_DEFAULT;
app.adjType = "foreground-service"; app.adjType = "foreground-service";
} else if (app.forcingToForeground != null) { } else if (app.forcingToForeground != null) {
// The user is aware of this app, so make it visible. // The user is aware of this app, so make it visible.
adj = VISIBLE_APP_ADJ; adj = VISIBLE_APP_ADJ;
schedGroup = Process.THREAD_GROUP_DEFAULT;
app.adjType = "force-foreground"; app.adjType = "force-foreground";
app.adjSource = app.forcingToForeground; app.adjSource = app.forcingToForeground;
} else if (app == mHomeProcess) { } else if (app == mHomeProcess) {
// This process is hosting what we currently consider to be the // This process is hosting what we currently consider to be the
// home app, so we don't want to let it go into the background. // home app, so we don't want to let it go into the background.
adj = HOME_APP_ADJ; adj = HOME_APP_ADJ;
schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
app.adjType = "home"; app.adjType = "home";
} else if ((N=app.activities.size()) != 0) { } else if ((N=app.activities.size()) != 0) {
// This app is in the background with paused activities. // This app is in the background with paused activities.
adj = hiddenAdj; adj = hiddenAdj;
schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
app.adjType = "bg-activities"; app.adjType = "bg-activities";
for (int j=0; j<N; j++) { for (int j=0; j<N; j++) {
if (((HistoryRecord)app.activities.get(j)).visible) { if (((HistoryRecord)app.activities.get(j)).visible) {
// This app has a visible activity! // This app has a visible activity!
adj = VISIBLE_APP_ADJ; adj = VISIBLE_APP_ADJ;
schedGroup = Process.THREAD_GROUP_DEFAULT;
app.adjType = "visible"; app.adjType = "visible";
break; break;
} }
@@ -13112,6 +13180,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
} else { } else {
// A very not-needed process. // A very not-needed process.
adj = EMPTY_APP_ADJ; adj = EMPTY_APP_ADJ;
schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
app.adjType = "empty"; app.adjType = "empty";
} }
@@ -13121,7 +13190,6 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
// infinite recursion. // infinite recursion.
app.adjSeq = mAdjSeq; app.adjSeq = mAdjSeq;
app.curRawAdj = adj; app.curRawAdj = adj;
app.curAdj = adj <= app.maxAdj ? adj : app.maxAdj;
if (mBackupTarget != null && app == mBackupTarget.app) { if (mBackupTarget != null && app == mBackupTarget.app) {
// If possible we want to avoid killing apps while they're being backed up // If possible we want to avoid killing apps while they're being backed up
@@ -13132,7 +13200,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
} }
} }
if (app.services.size() != 0 && adj > FOREGROUND_APP_ADJ) { if (app.services.size() != 0 && (adj > FOREGROUND_APP_ADJ
|| schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
final long now = SystemClock.uptimeMillis(); final long now = SystemClock.uptimeMillis();
// This process is more important if the top activity is // This process is more important if the top activity is
// bound to the service. // bound to the service.
@@ -13150,7 +13219,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
} }
} }
} }
if (s.connections.size() > 0 && adj > FOREGROUND_APP_ADJ) { if (s.connections.size() > 0 && (adj > FOREGROUND_APP_ADJ
|| schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
Iterator<ConnectionRecord> kt Iterator<ConnectionRecord> kt
= s.connections.values().iterator(); = s.connections.values().iterator();
while (kt.hasNext() && adj > FOREGROUND_APP_ADJ) { while (kt.hasNext() && adj > FOREGROUND_APP_ADJ) {
@@ -13182,6 +13252,11 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
app.adjSource = cr.binding.client; app.adjSource = cr.binding.client;
app.adjTarget = s.serviceInfo.name; app.adjTarget = s.serviceInfo.name;
} }
if ((cr.flags&Context.BIND_NOT_FOREGROUND) == 0) {
if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
schedGroup = Process.THREAD_GROUP_DEFAULT;
}
}
} }
HistoryRecord a = cr.activity; HistoryRecord a = cr.activity;
//if (a != null) { //if (a != null) {
@@ -13191,6 +13266,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
(a.state == ActivityState.RESUMED (a.state == ActivityState.RESUMED
|| a.state == ActivityState.PAUSING)) { || a.state == ActivityState.PAUSING)) {
adj = FOREGROUND_APP_ADJ; adj = FOREGROUND_APP_ADJ;
schedGroup = Process.THREAD_GROUP_DEFAULT;
app.adjType = "service"; app.adjType = "service";
app.adjTypeCode = ActivityManager.RunningAppProcessInfo app.adjTypeCode = ActivityManager.RunningAppProcessInfo
.REASON_SERVICE_IN_USE; .REASON_SERVICE_IN_USE;
@@ -13212,9 +13288,11 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
} }
} }
if (app.pubProviders.size() != 0 && adj > FOREGROUND_APP_ADJ) { if (app.pubProviders.size() != 0 && (adj > FOREGROUND_APP_ADJ
|| schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
Iterator jt = app.pubProviders.values().iterator(); Iterator jt = app.pubProviders.values().iterator();
while (jt.hasNext() && adj > FOREGROUND_APP_ADJ) { while (jt.hasNext() && (adj > FOREGROUND_APP_ADJ
|| schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
ContentProviderRecord cpr = (ContentProviderRecord)jt.next(); ContentProviderRecord cpr = (ContentProviderRecord)jt.next();
if (cpr.clients.size() != 0) { if (cpr.clients.size() != 0) {
Iterator<ProcessRecord> kt = cpr.clients.iterator(); Iterator<ProcessRecord> kt = cpr.clients.iterator();
@@ -13243,6 +13321,9 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
app.adjSource = client; app.adjSource = client;
app.adjTarget = cpr.info.name; app.adjTarget = cpr.info.name;
} }
if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
schedGroup = Process.THREAD_GROUP_DEFAULT;
}
} }
} }
// If the provider has external (non-framework) process // If the provider has external (non-framework) process
@@ -13251,6 +13332,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
if (cpr.externals != 0) { if (cpr.externals != 0) {
if (adj > FOREGROUND_APP_ADJ) { if (adj > FOREGROUND_APP_ADJ) {
adj = FOREGROUND_APP_ADJ; adj = FOREGROUND_APP_ADJ;
schedGroup = Process.THREAD_GROUP_DEFAULT;
app.adjType = "provider"; app.adjType = "provider";
app.adjTarget = cpr.info.name; app.adjTarget = cpr.info.name;
} }
@@ -13273,12 +13355,13 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
// " adj=" + adj + " curAdj=" + app.curAdj + " maxAdj=" + app.maxAdj); // " adj=" + adj + " curAdj=" + app.curAdj + " maxAdj=" + app.maxAdj);
if (adj > app.maxAdj) { if (adj > app.maxAdj) {
adj = app.maxAdj; adj = app.maxAdj;
if (app.maxAdj <= VISIBLE_APP_ADJ) {
schedGroup = Process.THREAD_GROUP_DEFAULT;
}
} }
app.curAdj = adj; app.curAdj = adj;
app.curSchedGroup = adj > VISIBLE_APP_ADJ app.curSchedGroup = schedGroup;
? Process.THREAD_GROUP_BG_NONINTERACTIVE
: Process.THREAD_GROUP_DEFAULT;
return adj; return adj;
} }
@@ -13423,7 +13506,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
int adj = computeOomAdjLocked(app, hiddenAdj, TOP_APP); int adj = computeOomAdjLocked(app, hiddenAdj, TOP_APP);
if (app.pid != 0 && app.pid != MY_PID) { if ((app.pid != 0 && app.pid != MY_PID) || Process.supportsProcesses()) {
if (app.curRawAdj != app.setRawAdj) { if (app.curRawAdj != app.setRawAdj) {
if (app.curRawAdj > FOREGROUND_APP_ADJ if (app.curRawAdj > FOREGROUND_APP_ADJ
&& app.setRawAdj <= FOREGROUND_APP_ADJ) { && app.setRawAdj <= FOREGROUND_APP_ADJ) {