Skip to content

Commit 39cec40

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Add new OOM adjustment for the "previous" process." into ics-mr1
2 parents 07b4b31 + f35fe23 commit 39cec40

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14399,6 +14399,7 @@ package android.os {
1439914399
field public static final int HONEYCOMB_MR1 = 12; // 0xc
1440014400
field public static final int HONEYCOMB_MR2 = 13; // 0xd
1440114401
field public static final int ICE_CREAM_SANDWICH = 14; // 0xe
14402+
field public static final int ICE_CREAM_SANDWICH_MR1 = 15; // 0xf
1440214403
}
1440314404

1440414405
public final class Bundle implements java.lang.Cloneable android.os.Parcelable {

core/java/android/os/Build.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public static class VERSION_CODES {
277277
public static final int HONEYCOMB_MR2 = 13;
278278

279279
/**
280-
* Android 4.0.
280+
* October 2011: Android 4.0.
281281
*
282282
* <p>Applications targeting this or a later release will get these
283283
* new changes in behavior:</p>
@@ -309,6 +309,11 @@ public static class VERSION_CODES {
309309
* </ul>
310310
*/
311311
public static final int ICE_CREAM_SANDWICH = 14;
312+
313+
/**
314+
* Android 4.1.
315+
*/
316+
public static final int ICE_CREAM_SANDWICH_MR1 = 15;
312317
}
313318

314319
/** The type of build, like "user" or "eng". */

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ abstract class ForegroundToken implements IBinder.DeathRecipient {
407407
*/
408408
ProcessRecord mHomeProcess;
409409

410+
/**
411+
* This is the process holding the activity the user last visited that
412+
* is in a different process from the one they are currently in.
413+
*/
414+
ProcessRecord mPreviousProcess;
415+
410416
/**
411417
* Packages that the user has asked to have run in screen size
412418
* compatibility mode instead of filling the screen.
@@ -8114,6 +8120,7 @@ boolean dumpProcessesLocked(FileDescriptor fd, PrintWriter pw, String[] args,
81148120

81158121
pw.println();
81168122
pw.println(" mHomeProcess: " + mHomeProcess);
8123+
pw.println(" mPreviousProcess: " + mPreviousProcess);
81178124
if (mHeavyWeightProcess != null) {
81188125
pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess);
81198126
}
@@ -8212,6 +8219,7 @@ boolean dumpOomLocked(FileDescriptor fd, PrintWriter pw, String[] args,
82128219
pw.print(" BACKUP_APP_ADJ: "); pw.println(ProcessList.BACKUP_APP_ADJ);
82138220
pw.print(" SERVICE_ADJ: "); pw.println(ProcessList.SERVICE_ADJ);
82148221
pw.print(" HOME_APP_ADJ: "); pw.println(ProcessList.HOME_APP_ADJ);
8222+
pw.print(" PREVIOUS_APP_ADJ: "); pw.println(ProcessList.PREVIOUS_APP_ADJ);
82158223
pw.print(" SERVICE_B_ADJ: "); pw.println(ProcessList.SERVICE_B_ADJ);
82168224
pw.print(" HIDDEN_APP_MIN_ADJ: "); pw.println(ProcessList.HIDDEN_APP_MIN_ADJ);
82178225
pw.print(" HIDDEN_APP_MAX_ADJ: "); pw.println(ProcessList.HIDDEN_APP_MAX_ADJ);
@@ -8228,6 +8236,7 @@ boolean dumpOomLocked(FileDescriptor fd, PrintWriter pw, String[] args,
82288236

82298237
pw.println();
82308238
pw.println(" mHomeProcess: " + mHomeProcess);
8239+
pw.println(" mPreviousProcess: " + mPreviousProcess);
82318240
if (mHeavyWeightProcess != null) {
82328241
pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess);
82338242
}
@@ -9009,6 +9018,8 @@ public int compare(Pair<ProcessRecord, Integer> object1,
90099018
oomAdj = buildOomTag("bak", " ", r.setAdj, ProcessList.HIDDEN_APP_MIN_ADJ);
90109019
} else if (r.setAdj >= ProcessList.SERVICE_B_ADJ) {
90119020
oomAdj = buildOomTag("svcb ", null, r.setAdj, ProcessList.SERVICE_B_ADJ);
9021+
} else if (r.setAdj >= ProcessList.PREVIOUS_APP_ADJ) {
9022+
oomAdj = buildOomTag("prev ", null, r.setAdj, ProcessList.PREVIOUS_APP_ADJ);
90129023
} else if (r.setAdj >= ProcessList.HOME_APP_ADJ) {
90139024
oomAdj = buildOomTag("home ", null, r.setAdj, ProcessList.HOME_APP_ADJ);
90149025
} else if (r.setAdj >= ProcessList.SERVICE_ADJ) {
@@ -9287,12 +9298,13 @@ final void dumpApplicationMemoryUsage(FileDescriptor fd,
92879298
ProcessList.SYSTEM_ADJ, ProcessList.PERSISTENT_PROC_ADJ, ProcessList.FOREGROUND_APP_ADJ,
92889299
ProcessList.VISIBLE_APP_ADJ, ProcessList.PERCEPTIBLE_APP_ADJ, ProcessList.HEAVY_WEIGHT_APP_ADJ,
92899300
ProcessList.BACKUP_APP_ADJ, ProcessList.SERVICE_ADJ, ProcessList.HOME_APP_ADJ,
9290-
ProcessList.SERVICE_B_ADJ, ProcessList.HIDDEN_APP_MAX_ADJ
9301+
ProcessList.PREVIOUS_APP_ADJ, ProcessList.SERVICE_B_ADJ, ProcessList.HIDDEN_APP_MAX_ADJ
92919302
};
92929303
final String[] oomLabel = new String[] {
92939304
"System", "Persistent", "Foreground",
92949305
"Visible", "Perceptible", "Heavy Weight",
9295-
"Backup", "A Services", "Home", "B Services", "Background"
9306+
"Backup", "A Services", "Home", "Previous",
9307+
"B Services", "Background"
92969308
};
92979309
long oomPss[] = new long[oomLabel.length];
92989310
ArrayList<MemItem>[] oomProcs = (ArrayList<MemItem>[])new ArrayList[oomLabel.length];
@@ -9714,7 +9726,10 @@ private final void cleanUpApplicationRecordLocked(ProcessRecord app,
97149726
if (app == mHomeProcess) {
97159727
mHomeProcess = null;
97169728
}
9717-
9729+
if (app == mPreviousProcess) {
9730+
mPreviousProcess = null;
9731+
}
9732+
97189733
if (restart) {
97199734
// We have components that still need to be running in the
97209735
// process, so re-launch it.
@@ -13112,6 +13127,17 @@ private final int computeOomAdjLocked(ProcessRecord app, int hiddenAdj,
1311213127
app.adjType = "home";
1311313128
}
1311413129

13130+
if (adj > ProcessList.PREVIOUS_APP_ADJ && app == mPreviousProcess
13131+
&& app.activities.size() > 0) {
13132+
// This was the previous process that showed UI to the user.
13133+
// We want to try to keep it around more aggressively, to give
13134+
// a good experience around switching between two apps.
13135+
adj = ProcessList.PREVIOUS_APP_ADJ;
13136+
schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
13137+
app.hidden = false;
13138+
app.adjType = "previous";
13139+
}
13140+
1311513141
if (false) Slog.i(TAG, "OOM " + app + ": initial adj=" + adj
1311613142
+ " reason=" + app.adjType);
1311713143

@@ -13841,7 +13867,8 @@ final void updateOomAdjLocked() {
1384113867
} else {
1384213868
numBg++;
1384313869
}
13844-
} else if (app.curAdj >= ProcessList.HOME_APP_ADJ) {
13870+
} else if (app.curAdj >= ProcessList.HOME_APP_ADJ
13871+
&& app.curAdj != ProcessList.SERVICE_B_ADJ) {
1384513872
numBg++;
1384613873
}
1384713874
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,13 @@ final boolean resumeTopActivityLocked(ActivityRecord prev) {
13631363
+ ", nowVisible=" + next.nowVisible);
13641364
}
13651365
}
1366+
1367+
if (!prev.finishing && prev.app != null && prev.app != next.app) {
1368+
// We are switching to a new activity that is in a different
1369+
// process than the previous one. Note the previous process,
1370+
// so we can try to keep it around.
1371+
mService.mPreviousProcess = prev.app;
1372+
}
13661373
}
13671374

13681375
// Launching this app's activity, make sure the app is no longer

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,19 @@ class ProcessList {
3838
// This is a process only hosting activities that are not visible,
3939
// so it can be killed without any disruption.
4040
static final int HIDDEN_APP_MAX_ADJ = 15;
41-
static int HIDDEN_APP_MIN_ADJ = 8;
41+
static int HIDDEN_APP_MIN_ADJ = 9;
4242

4343
// The B list of SERVICE_ADJ -- these are the old and decrepit
4444
// services that aren't as shiny and interesting as the ones in the A list.
45-
static final int SERVICE_B_ADJ = 7;
45+
static final int SERVICE_B_ADJ = 8;
46+
47+
// This is the process of the previous application that the user was in.
48+
// This process is kept above other things, because it is very common to
49+
// switch back to the previous app. This is important both for recent
50+
// task switch (toggling between the two top recent apps) as well as normal
51+
// UI flow such as clicking on a URI in the e-mail app to view in the browser,
52+
// and then pressing back to return to e-mail.
53+
static final int PREVIOUS_APP_ADJ = 7;
4654

4755
// This is a process holding the home application -- we want to try
4856
// avoiding killing it, even if it would normally be in the background,

0 commit comments

Comments
 (0)