Skip to content

Commit 4ee3666

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Fix issue #5263361: Browser instance not created in application picker"
2 parents 703bde8 + 905577f commit 4ee3666

File tree

8 files changed

+126
-89
lines changed

8 files changed

+126
-89
lines changed

core/java/android/app/ActivityManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,12 @@ public static class RunningAppProcessInfo implements Parcelable {
12541254
*/
12551255
public ComponentName importanceReasonComponent;
12561256

1257+
/**
1258+
* When {@link importanceReasonPid} is non-0, this is the importance
1259+
* of the other pid. @hide
1260+
*/
1261+
public int importanceReasonImportance;
1262+
12571263
public RunningAppProcessInfo() {
12581264
importance = IMPORTANCE_FOREGROUND;
12591265
importanceReasonCode = REASON_UNKNOWN;
@@ -1280,6 +1286,7 @@ public void writeToParcel(Parcel dest, int flags) {
12801286
dest.writeInt(importanceReasonCode);
12811287
dest.writeInt(importanceReasonPid);
12821288
ComponentName.writeToParcel(importanceReasonComponent, dest);
1289+
dest.writeInt(importanceReasonImportance);
12831290
}
12841291

12851292
public void readFromParcel(Parcel source) {
@@ -1293,6 +1300,7 @@ public void readFromParcel(Parcel source) {
12931300
importanceReasonCode = source.readInt();
12941301
importanceReasonPid = source.readInt();
12951302
importanceReasonComponent = ComponentName.readFromParcel(source);
1303+
importanceReasonImportance = source.readInt();
12961304
}
12971305

12981306
public static final Creator<RunningAppProcessInfo> CREATOR =

core/java/android/content/Context.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ public abstract class Context {
239239
* methods of activities and other components are called. Note that you
240240
* <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
241241
* appropriate in the future; this will not be removed for you.
242+
*
243+
* @param callback The interface to call. This can be either a
244+
* {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
242245
*/
243246
public void registerComponentCallbacks(ComponentCallbacks callback) {
244247
getApplicationContext().registerComponentCallbacks(callback);

core/java/com/android/internal/app/ResolverActivity.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,20 @@ public class ResolverActivity extends AlertActivity implements
5858
private TextView mClearDefaultHint;
5959
private PackageManager mPm;
6060

61+
private Intent makeMyIntent() {
62+
Intent intent = new Intent(getIntent());
63+
// The resolver activity is set to be hidden from recent tasks.
64+
// we don't want this attribute to be propagated to the next activity
65+
// being launched. Note that if the original Intent also had this
66+
// flag set, we are now losing it. That should be a very rare case
67+
// and we can live with this.
68+
intent.setFlags(intent.getFlags()&~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
69+
return intent;
70+
}
71+
6172
@Override
6273
protected void onCreate(Bundle savedInstanceState) {
63-
onCreate(savedInstanceState, new Intent(getIntent()),
74+
onCreate(savedInstanceState, makeMyIntent(),
6475
getResources().getText(com.android.internal.R.string.whichApplication),
6576
null, null, true);
6677
}

core/res/AndroidManifest.xml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,19 +1499,23 @@
14991499
android:theme="@style/Theme.Holo.Dialog"
15001500
android:label="@string/heavy_weight_switcher_title"
15011501
android:finishOnCloseSystemDialogs="true"
1502-
android:excludeFromRecents="true">
1502+
android:excludeFromRecents="true"
1503+
android:process=":ui">
15031504
</activity>
15041505
<activity android:name="com.android.internal.app.PlatLogoActivity"
1505-
android:theme="@style/Theme.Wallpaper.NoTitleBar.Fullscreen">
1506+
android:theme="@style/Theme.Wallpaper.NoTitleBar.Fullscreen"
1507+
android:process=":ui">
15061508
</activity>
15071509
<activity android:name="com.android.internal.app.DisableCarModeActivity"
15081510
android:theme="@style/Theme.NoDisplay"
1509-
android:excludeFromRecents="true">
1511+
android:excludeFromRecents="true"
1512+
android:process=":ui">
15101513
</activity>
15111514
<activity android:name="com.android.internal.app.RingtonePickerActivity"
15121515
android:theme="@style/Theme.Holo.Dialog.Alert"
15131516
android:excludeFromRecents="true"
1514-
android:multiprocess="true">
1517+
android:multiprocess="true"
1518+
android:process=":ui">
15151519
<intent-filter>
15161520
<action android:name="android.intent.action.RINGTONE_PICKER" />
15171521
<category android:name="android.intent.category.DEFAULT" />
@@ -1522,18 +1526,21 @@
15221526
android:excludeFromRecents="true"
15231527
android:exported="true"
15241528
android:theme="@android:style/Theme.Holo.Dialog"
1525-
android:label="@string/choose_account_label">
1529+
android:label="@string/choose_account_label"
1530+
android:process=":ui">
15261531
</activity>
15271532

15281533
<activity android:name="android.accounts.GrantCredentialsPermissionActivity"
15291534
android:excludeFromRecents="true"
15301535
android:exported="true"
1531-
android:theme="@android:style/Theme.Holo.DialogWhenLarge">
1536+
android:theme="@android:style/Theme.Holo.DialogWhenLarge"
1537+
android:process=":ui">
15321538
</activity>
15331539

15341540
<activity android:name="android.content.SyncActivityTooManyDeletes"
15351541
android:theme="@android:style/Theme.Holo.Dialog"
1536-
android:label="@string/sync_too_many_deletes">
1542+
android:label="@string/sync_too_many_deletes"
1543+
android:process=":ui">
15371544
</activity>
15381545

15391546
<activity android:name="com.android.server.ShutdownActivity"
@@ -1551,7 +1558,8 @@
15511558

15521559
<activity android:name="com.android.internal.app.NetInitiatedActivity"
15531560
android:theme="@style/Theme.Holo.Dialog.Alert"
1554-
android:excludeFromRecents="true">
1561+
android:excludeFromRecents="true"
1562+
android:process=":ui">
15551563
</activity>
15561564

15571565
<receiver android:name="com.android.server.BootReceiver" >

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 84 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
import android.os.SystemProperties;
107107
import android.provider.Settings;
108108
import android.util.EventLog;
109+
import android.util.Pair;
109110
import android.util.Slog;
110111
import android.util.Log;
111112
import android.util.PrintWriterPrinter;
@@ -5004,7 +5005,13 @@ public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum,
50045005
maxNum < N ? maxNum : N);
50055006
for (int i=0; i<N && maxNum > 0; i++) {
50065007
TaskRecord tr = mRecentTasks.get(i);
5007-
if (((flags&ActivityManager.RECENT_WITH_EXCLUDED) != 0)
5008+
// Return the entry if desired by the caller. We always return
5009+
// the first entry, because callers always expect this to be the
5010+
// forground app. We may filter others if the caller has
5011+
// not supplied RECENT_WITH_EXCLUDED and there is some reason
5012+
// we should exclude the entry.
5013+
if (i == 0
5014+
|| ((flags&ActivityManager.RECENT_WITH_EXCLUDED) != 0)
50085015
|| (tr.intent == null)
50095016
|| ((tr.intent.getFlags()
50105017
&Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0)) {
@@ -7546,7 +7553,33 @@ public List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState() {
75467553

75477554
return errList;
75487555
}
7549-
7556+
7557+
static int oomAdjToImportance(int adj, ActivityManager.RunningAppProcessInfo currApp) {
7558+
if (adj >= ProcessList.EMPTY_APP_ADJ) {
7559+
return ActivityManager.RunningAppProcessInfo.IMPORTANCE_EMPTY;
7560+
} else if (adj >= ProcessList.HIDDEN_APP_MIN_ADJ) {
7561+
if (currApp != null) {
7562+
currApp.lru = adj - ProcessList.HIDDEN_APP_MIN_ADJ + 1;
7563+
}
7564+
return ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
7565+
} else if (adj >= ProcessList.HOME_APP_ADJ) {
7566+
if (currApp != null) {
7567+
currApp.lru = 0;
7568+
}
7569+
return ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
7570+
} else if (adj >= ProcessList.SECONDARY_SERVER_ADJ) {
7571+
return ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
7572+
} else if (adj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
7573+
return ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE;
7574+
} else if (adj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
7575+
return ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE;
7576+
} else if (adj >= ProcessList.VISIBLE_APP_ADJ) {
7577+
return ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;
7578+
} else {
7579+
return ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
7580+
}
7581+
}
7582+
75507583
public List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses() {
75517584
// Lazy instantiation of list
75527585
List<ActivityManager.RunningAppProcessInfo> runList = null;
@@ -7567,28 +7600,12 @@ public List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses() {
75677600
currApp.flags |= ActivityManager.RunningAppProcessInfo.FLAG_PERSISTENT;
75687601
}
75697602
int adj = app.curAdj;
7570-
if (adj >= ProcessList.EMPTY_APP_ADJ) {
7571-
currApp.importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_EMPTY;
7572-
} else if (adj >= ProcessList.HIDDEN_APP_MIN_ADJ) {
7573-
currApp.importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
7574-
currApp.lru = adj - ProcessList.HIDDEN_APP_MIN_ADJ + 1;
7575-
} else if (adj >= ProcessList.HOME_APP_ADJ) {
7576-
currApp.importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
7577-
currApp.lru = 0;
7578-
} else if (adj >= ProcessList.SECONDARY_SERVER_ADJ) {
7579-
currApp.importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
7580-
} else if (adj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
7581-
currApp.importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE;
7582-
} else if (adj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
7583-
currApp.importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE;
7584-
} else if (adj >= ProcessList.VISIBLE_APP_ADJ) {
7585-
currApp.importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;
7586-
} else {
7587-
currApp.importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
7588-
}
7603+
currApp.importance = oomAdjToImportance(adj, currApp);
75897604
currApp.importanceReasonCode = app.adjTypeCode;
75907605
if (app.adjSource instanceof ProcessRecord) {
75917606
currApp.importanceReasonPid = ((ProcessRecord)app.adjSource).pid;
7607+
currApp.importanceReasonImportance = oomAdjToImportance(
7608+
app.adjSourceOom, null);
75927609
} else if (app.adjSource instanceof ActivityRecord) {
75937610
ActivityRecord r = (ActivityRecord)app.adjSource;
75947611
if (r.app != null) currApp.importanceReasonPid = r.app.pid;
@@ -7891,7 +7908,7 @@ boolean dumpProcessesLocked(FileDescriptor fd, PrintWriter pw, String[] args,
78917908
if (mLruProcesses.size() > 0) {
78927909
if (needSep) pw.println(" ");
78937910
needSep = true;
7894-
pw.println(" Process LRU list (most recent first):");
7911+
pw.println(" Process LRU list (sorted by oom_adj):");
78957912
dumpProcessOomList(pw, this, mLruProcesses, " ",
78967913
"Proc", "PERS", false);
78977914
needSep = true;
@@ -8069,29 +8086,6 @@ boolean dumpOomLocked(FileDescriptor fd, PrintWriter pw, String[] args,
80698086
boolean needSep = false;
80708087

80718088
if (mLruProcesses.size() > 0) {
8072-
ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>(mLruProcesses);
8073-
8074-
Comparator<ProcessRecord> comparator = new Comparator<ProcessRecord>() {
8075-
@Override
8076-
public int compare(ProcessRecord object1, ProcessRecord object2) {
8077-
if (object1.setAdj != object2.setAdj) {
8078-
return object1.setAdj > object2.setAdj ? -1 : 1;
8079-
}
8080-
if (object1.setSchedGroup != object2.setSchedGroup) {
8081-
return object1.setSchedGroup > object2.setSchedGroup ? -1 : 1;
8082-
}
8083-
if (object1.keeping != object2.keeping) {
8084-
return object1.keeping ? -1 : 1;
8085-
}
8086-
if (object1.pid != object2.pid) {
8087-
return object1.pid > object2.pid ? -1 : 1;
8088-
}
8089-
return 0;
8090-
}
8091-
};
8092-
8093-
Collections.sort(procs, comparator);
8094-
80958089
if (needSep) pw.println(" ");
80968090
needSep = true;
80978091
pw.println(" OOM levels:");
@@ -8110,7 +8104,7 @@ public int compare(ProcessRecord object1, ProcessRecord object2) {
81108104
if (needSep) pw.println(" ");
81118105
needSep = true;
81128106
pw.println(" Process OOM control:");
8113-
dumpProcessOomList(pw, this, procs, " ",
8107+
dumpProcessOomList(pw, this, mLruProcesses, " ",
81148108
"Proc", "PERS", true);
81158109
needSep = true;
81168110
}
@@ -8859,18 +8853,41 @@ private static final int dumpProcessList(PrintWriter pw,
88598853
}
88608854

88618855
private static final void dumpProcessOomList(PrintWriter pw,
8862-
ActivityManagerService service, List<ProcessRecord> list,
8856+
ActivityManagerService service, List<ProcessRecord> origList,
88638857
String prefix, String normalLabel, String persistentLabel,
88648858
boolean inclDetails) {
88658859

8860+
ArrayList<Pair<ProcessRecord, Integer>> list
8861+
= new ArrayList<Pair<ProcessRecord, Integer>>(origList.size());
8862+
for (int i=0; i<origList.size(); i++) {
8863+
list.add(new Pair<ProcessRecord, Integer>(origList.get(i), i));
8864+
}
8865+
8866+
Comparator<Pair<ProcessRecord, Integer>> comparator
8867+
= new Comparator<Pair<ProcessRecord, Integer>>() {
8868+
@Override
8869+
public int compare(Pair<ProcessRecord, Integer> object1,
8870+
Pair<ProcessRecord, Integer> object2) {
8871+
if (object1.first.setAdj != object2.first.setAdj) {
8872+
return object1.first.setAdj > object2.first.setAdj ? -1 : 1;
8873+
}
8874+
if (object1.second.intValue() != object2.second.intValue()) {
8875+
return object1.second.intValue() > object2.second.intValue() ? -1 : 1;
8876+
}
8877+
return 0;
8878+
}
8879+
};
8880+
8881+
Collections.sort(list, comparator);
8882+
88668883
final long curRealtime = SystemClock.elapsedRealtime();
88678884
final long realtimeSince = curRealtime - service.mLastPowerCheckRealtime;
88688885
final long curUptime = SystemClock.uptimeMillis();
88698886
final long uptimeSince = curUptime - service.mLastPowerCheckUptime;
88708887

88718888
final int N = list.size()-1;
88728889
for (int i=N; i>=0; i--) {
8873-
ProcessRecord r = list.get(i);
8890+
ProcessRecord r = list.get(i).first;
88748891
String oomAdj;
88758892
if (r.setAdj >= ProcessList.EMPTY_APP_ADJ) {
88768893
oomAdj = buildOomTag("empty", null, r.setAdj, ProcessList.EMPTY_APP_ADJ);
@@ -8919,7 +8936,7 @@ private static final void dumpProcessOomList(PrintWriter pw,
89198936
}
89208937
pw.println(String.format("%s%s #%2d: adj=%s/%s%s trm=%2d %s (%s)",
89218938
prefix, (r.persistent ? persistentLabel : normalLabel),
8922-
N-i, oomAdj, schedGroup, foreground, r.trimMemoryLevel,
8939+
N-list.get(i).second, oomAdj, schedGroup, foreground, r.trimMemoryLevel,
89238940
r.toShortString(), r.adjType));
89248941
if (r.adjSource != null || r.adjTarget != null) {
89258942
pw.print(prefix);
@@ -13118,6 +13135,7 @@ private final int computeOomAdjLocked(ProcessRecord app, int hiddenAdj,
1311813135
app.adjTypeCode = ActivityManager.RunningAppProcessInfo
1311913136
.REASON_SERVICE_IN_USE;
1312013137
app.adjSource = cr.binding.client;
13138+
app.adjSourceOom = clientAdj;
1312113139
app.adjTarget = s.name;
1312213140
}
1312313141
if ((cr.flags&Context.BIND_NOT_FOREGROUND) == 0) {
@@ -13140,6 +13158,7 @@ private final int computeOomAdjLocked(ProcessRecord app, int hiddenAdj,
1314013158
app.adjTypeCode = ActivityManager.RunningAppProcessInfo
1314113159
.REASON_SERVICE_IN_USE;
1314213160
app.adjSource = a;
13161+
app.adjSourceOom = adj;
1314313162
app.adjTarget = s.name;
1314413163
}
1314513164
}
@@ -13201,6 +13220,7 @@ private final int computeOomAdjLocked(ProcessRecord app, int hiddenAdj,
1320113220
app.adjTypeCode = ActivityManager.RunningAppProcessInfo
1320213221
.REASON_PROVIDER_IN_USE;
1320313222
app.adjSource = client;
13223+
app.adjSourceOom = clientAdj;
1320413224
app.adjTarget = cpr.name;
1320513225
}
1320613226
if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
@@ -13511,16 +13531,21 @@ private final boolean updateOomAdjLocked(
1351113531
computeOomAdjLocked(app, hiddenAdj, TOP_APP, false);
1351213532

1351313533
if (app.curRawAdj != app.setRawAdj) {
13514-
if (app.curRawAdj > ProcessList.FOREGROUND_APP_ADJ
13515-
&& app.setRawAdj <= ProcessList.FOREGROUND_APP_ADJ) {
13516-
// If this app is transitioning from foreground to
13517-
// non-foreground, have it do a gc.
13518-
scheduleAppGcLocked(app);
13519-
} else if (app.curRawAdj >= ProcessList.HIDDEN_APP_MIN_ADJ
13520-
&& app.setRawAdj < ProcessList.HIDDEN_APP_MIN_ADJ) {
13521-
// Likewise do a gc when an app is moving in to the
13522-
// background (such as a service stopping).
13523-
scheduleAppGcLocked(app);
13534+
if (false) {
13535+
// Removing for now. Forcing GCs is not so useful anymore
13536+
// with Dalvik, and the new memory level hint facility is
13537+
// better for what we need to do these days.
13538+
if (app.curRawAdj > ProcessList.FOREGROUND_APP_ADJ
13539+
&& app.setRawAdj <= ProcessList.FOREGROUND_APP_ADJ) {
13540+
// If this app is transitioning from foreground to
13541+
// non-foreground, have it do a gc.
13542+
scheduleAppGcLocked(app);
13543+
} else if (app.curRawAdj >= ProcessList.HIDDEN_APP_MIN_ADJ
13544+
&& app.setRawAdj < ProcessList.HIDDEN_APP_MIN_ADJ) {
13545+
// Likewise do a gc when an app is moving in to the
13546+
// background (such as a service stopping).
13547+
scheduleAppGcLocked(app);
13548+
}
1352413549
}
1352513550

1352613551
if (wasKeeping && !app.keeping) {

services/java/com/android/server/am/ActivityStack.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ final void ensureActivitiesVisibleLocked(ActivityRecord top,
11511151
try {
11521152
mService.mWindowManager.setAppVisibility(r, true);
11531153
r.sleeping = false;
1154+
r.app.pendingUiClean = true;
11541155
r.app.thread.scheduleWindowVisibility(r, true);
11551156
r.stopFreezingScreenLocked(false);
11561157
} catch (Exception e) {
@@ -1497,6 +1498,7 @@ final boolean resumeTopActivityLocked(ActivityRecord prev) {
14971498

14981499
next.sleeping = false;
14991500
showAskCompatModeDialogLocked(next);
1501+
next.app.pendingUiClean = true;
15001502
next.app.thread.scheduleResumeActivity(next,
15011503
mService.isNextTransitionForward());
15021504

0 commit comments

Comments
 (0)