Skip to content

Commit 01a7c79

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Various fixes." into jb-mr1-dev
2 parents 3e6d426 + 2d1b378 commit 01a7c79

File tree

5 files changed

+94
-69
lines changed

5 files changed

+94
-69
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,8 +1551,12 @@ boolean forceStopLocked(String name, int userId, boolean evenPersistent, boolean
15511551
}
15521552
}
15531553
} else {
1554-
didSomething = collectForceStopServicesLocked(name, userId, evenPersistent,
1555-
doit, mServiceMap.mServicesByNamePerUser.get(userId), services);
1554+
HashMap<ComponentName, ServiceRecord> items
1555+
= mServiceMap.mServicesByNamePerUser.get(userId);
1556+
if (items != null) {
1557+
didSomething = collectForceStopServicesLocked(name, userId, evenPersistent,
1558+
doit, items, services);
1559+
}
15561560
}
15571561

15581562
int N = services.size();

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ protected String packageForFilter(BroadcastFilter filter) {
546546
*/
547547
final ArrayList mCancelledThumbnails = new ArrayList();
548548

549-
final ProviderMap mProviderMap = new ProviderMap();
549+
final ProviderMap mProviderMap;
550550

551551
/**
552552
* List of content providers who have clients waiting for them. The
@@ -1511,6 +1511,7 @@ private ActivityManagerService() {
15111511
mBroadcastQueues[1] = mBgBroadcastQueue;
15121512

15131513
mServices = new ActiveServices(this);
1514+
mProviderMap = new ProviderMap(this);
15141515

15151516
File dataDir = Environment.getDataDirectory();
15161517
File systemDir = new File(dataDir, "system");
@@ -1792,7 +1793,7 @@ private final void updateLruProcessInternalLocked(ProcessRecord app,
17921793
// Also don't let it kick out the first few "real" hidden processes.
17931794
skipTop = ProcessList.MIN_HIDDEN_APPS;
17941795
}
1795-
1796+
17961797
while (i >= 0) {
17971798
ProcessRecord p = mLruProcesses.get(i);
17981799
// If this app shouldn't be in front of the first N background
@@ -2680,7 +2681,7 @@ public final boolean finishActivity(IBinder token, int resultCode, Intent result
26802681
}
26812682
final long origId = Binder.clearCallingIdentity();
26822683
boolean res = mMainStack.requestFinishActivityLocked(token, resultCode,
2683-
resultData, "app-request");
2684+
resultData, "app-request", true);
26842685
Binder.restoreCallingIdentity(origId);
26852686
return res;
26862687
}
@@ -2710,7 +2711,7 @@ public final void finishHeavyWeightApp() {
27102711
int index = mMainStack.indexOfTokenLocked(r.appToken);
27112712
if (index >= 0) {
27122713
mMainStack.finishActivityLocked(r, index, Activity.RESULT_CANCELED,
2713-
null, "finish-heavy");
2714+
null, "finish-heavy", true);
27142715
}
27152716
}
27162717
}
@@ -3627,7 +3628,7 @@ void closeSystemDialogsLocked(String reason) {
36273628
ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(i);
36283629
if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) {
36293630
r.stack.finishActivityLocked(r, i,
3630-
Activity.RESULT_CANCELED, null, "close-sys");
3631+
Activity.RESULT_CANCELED, null, "close-sys", true);
36313632
}
36323633
}
36333634

@@ -6972,7 +6973,7 @@ public void unhandledBack() {
69726973
if (count > 1) {
69736974
final long origId = Binder.clearCallingIdentity();
69746975
mMainStack.finishActivityLocked((ActivityRecord)mMainStack.mHistory.get(count-1),
6975-
count-1, Activity.RESULT_CANCELED, null, "unhandled-back");
6976+
count-1, Activity.RESULT_CANCELED, null, "unhandled-back", true);
69766977
Binder.restoreCallingIdentity(origId);
69776978
}
69786979
}
@@ -7891,7 +7892,8 @@ private boolean handleAppCrashLocked(ProcessRecord app) {
78917892
if (r.app == app) {
78927893
Slog.w(TAG, " Force finishing activity "
78937894
+ r.intent.getComponent().flattenToShortString());
7894-
r.stack.finishActivityLocked(r, i, Activity.RESULT_CANCELED, null, "crashed");
7895+
r.stack.finishActivityLocked(r, i, Activity.RESULT_CANCELED,
7896+
null, "crashed", false);
78957897
}
78967898
}
78977899
if (!app.persistent) {
@@ -7926,7 +7928,7 @@ private boolean handleAppCrashLocked(ProcessRecord app) {
79267928
+ r.intent.getComponent().flattenToShortString());
79277929
int index = mMainStack.indexOfActivityLocked(r);
79287930
r.stack.finishActivityLocked(r, index,
7929-
Activity.RESULT_CANCELED, null, "crashed");
7931+
Activity.RESULT_CANCELED, null, "crashed", false);
79307932
// Also terminate any activities below it that aren't yet
79317933
// stopped, to avoid a situation where one will get
79327934
// re-start our crashing activity once it gets resumed again.
@@ -7940,7 +7942,7 @@ private boolean handleAppCrashLocked(ProcessRecord app) {
79407942
Slog.w(TAG, " Force finishing activity "
79417943
+ r.intent.getComponent().flattenToShortString());
79427944
r.stack.finishActivityLocked(r, index,
7943-
Activity.RESULT_CANCELED, null, "crashed");
7945+
Activity.RESULT_CANCELED, null, "crashed", false);
79447946
}
79457947
}
79467948
}
@@ -12305,7 +12307,7 @@ public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode,
1230512307
for (int i = start; i > finishTo; i--) {
1230612308
ActivityRecord r = history.get(i);
1230712309
mMainStack.requestFinishActivityLocked(r.appToken, resultCode, resultData,
12308-
"navigate-up");
12310+
"navigate-up", true);
1230912311
// Only return the supplied result for the first activity finished
1231012312
resultCode = Activity.RESULT_CANCELED;
1231112313
resultData = null;
@@ -12331,7 +12333,7 @@ public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode,
1233112333
foundParentInTask = false;
1233212334
}
1233312335
mMainStack.requestFinishActivityLocked(parent.appToken, resultCode,
12334-
resultData, "navigate-up");
12336+
resultData, "navigate-up", true);
1233512337
}
1233612338
}
1233712339
Binder.restoreCallingIdentity(origId);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ static ActivityRecord forToken(IBinder token) {
333333
state = ActivityState.INITIALIZING;
334334
frontOfTask = false;
335335
launchFailed = false;
336-
haveState = false;
337336
stopped = false;
338337
delayedResume = false;
339338
finishing = false;
@@ -347,6 +346,11 @@ static ActivityRecord forToken(IBinder token) {
347346
idle = false;
348347
hasBeenLaunched = false;
349348

349+
// This starts out true, since the initial state of an activity
350+
// is that we have everything, and we shouldn't never consider it
351+
// lacking in state to be removed if it dies.
352+
haveState = true;
353+
350354
if (aInfo != null) {
351355
if (aInfo.targetActivity == null
352356
|| aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE

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

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ final boolean realStartActivityLocked(ActivityRecord r,
725725
+ ", giving up", e);
726726
mService.appDiedLocked(app, app.pid, app.thread);
727727
requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null,
728-
"2nd-crash");
728+
"2nd-crash", false);
729729
return false;
730730
}
731731

@@ -1092,7 +1092,7 @@ private final void completePauseLocked() {
10921092
if (prev != null) {
10931093
if (prev.finishing) {
10941094
if (DEBUG_PAUSE) Slog.v(TAG, "Executing finish of activity: " + prev);
1095-
prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE);
1095+
prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false);
10961096
} else if (prev.app != null) {
10971097
if (DEBUG_PAUSE) Slog.v(TAG, "Enqueueing pending stop: " + prev);
10981098
if (prev.waitingVisible) {
@@ -1504,7 +1504,7 @@ final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
15041504
Slog.d(TAG, "no-history finish of " + last + " on new resume");
15051505
}
15061506
requestFinishActivityLocked(last.appToken, Activity.RESULT_CANCELED, null,
1507-
"no-history");
1507+
"no-history", false);
15081508
}
15091509
}
15101510

@@ -1726,7 +1726,7 @@ final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
17261726
// activity and try the next one.
17271727
Slog.w(TAG, "Exception thrown during resume of " + next, e);
17281728
requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null,
1729-
"resume-exception");
1729+
"resume-exception", true);
17301730
return true;
17311731
}
17321732

@@ -2080,7 +2080,7 @@ private final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop,
20802080
continue;
20812081
}
20822082
if (finishActivityLocked(p, srcPos,
2083-
Activity.RESULT_CANCELED, null, "reset")) {
2083+
Activity.RESULT_CANCELED, null, "reset", false)) {
20842084
replyChainEnd--;
20852085
srcPos--;
20862086
}
@@ -2143,7 +2143,7 @@ private final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop,
21432143
continue;
21442144
}
21452145
if (finishActivityLocked(p, srcPos,
2146-
Activity.RESULT_CANCELED, null, "reset")) {
2146+
Activity.RESULT_CANCELED, null, "reset", false)) {
21472147
taskTopI--;
21482148
lastReparentPos--;
21492149
replyChainEnd--;
@@ -2200,7 +2200,7 @@ private final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop,
22002200
}
22012201
if (p.intent.getComponent().equals(target.intent.getComponent())) {
22022202
if (finishActivityLocked(p, j,
2203-
Activity.RESULT_CANCELED, null, "replace")) {
2203+
Activity.RESULT_CANCELED, null, "replace", false)) {
22042204
taskTopI--;
22052205
lastReparentPos--;
22062206
}
@@ -2270,7 +2270,7 @@ private final ActivityRecord performClearTaskLocked(int taskId,
22702270
continue;
22712271
}
22722272
if (finishActivityLocked(r, i, Activity.RESULT_CANCELED,
2273-
null, "clear")) {
2273+
null, "clear", false)) {
22742274
i--;
22752275
}
22762276
}
@@ -2284,7 +2284,7 @@ private final ActivityRecord performClearTaskLocked(int taskId,
22842284
int index = indexOfTokenLocked(ret.appToken);
22852285
if (index >= 0) {
22862286
finishActivityLocked(ret, index, Activity.RESULT_CANCELED,
2287-
null, "clear");
2287+
null, "clear", false);
22882288
}
22892289
return null;
22902290
}
@@ -2313,7 +2313,7 @@ private final void performClearTaskAtIndexLocked(int taskId, int i) {
23132313
continue;
23142314
}
23152315
if (!finishActivityLocked(r, i, Activity.RESULT_CANCELED,
2316-
null, "clear")) {
2316+
null, "clear", false)) {
23172317
i++;
23182318
}
23192319
}
@@ -2579,6 +2579,7 @@ final int startActivityLocked(IApplicationThread caller,
25792579
mDismissKeyguardOnNextActivity = false;
25802580
mService.mWindowManager.dismissKeyguard();
25812581
}
2582+
Slog.i(TAG, "DONE STARTING!");
25822583
return err;
25832584
}
25842585

@@ -3319,7 +3320,7 @@ private final void stopActivityLocked(ActivityRecord r) {
33193320
Slog.d(TAG, "no-history finish of " + r);
33203321
}
33213322
requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null,
3322-
"no-history");
3323+
"no-history", false);
33233324
} else {
33243325
if (DEBUG_STATES) Slog.d(TAG, "Not finishing noHistory " + r
33253326
+ " on stop because we're just sleeping");
@@ -3531,7 +3532,7 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
35313532
ActivityRecord r = (ActivityRecord)stops.get(i);
35323533
synchronized (mService) {
35333534
if (r.finishing) {
3534-
finishCurrentActivityLocked(r, FINISH_IMMEDIATELY);
3535+
finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false);
35353536
} else {
35363537
stopActivityLocked(r);
35373538
}
@@ -3585,7 +3586,7 @@ final void addStartingUserLocked(UserStartedState uss) {
35853586
* some reason it is being left as-is.
35863587
*/
35873588
final boolean requestFinishActivityLocked(IBinder token, int resultCode,
3588-
Intent resultData, String reason) {
3589+
Intent resultData, String reason, boolean oomAdj) {
35893590
int index = indexOfTokenLocked(token);
35903591
if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(
35913592
TAG, "Finishing activity @" + index + ": token=" + token
@@ -3596,7 +3597,7 @@ final boolean requestFinishActivityLocked(IBinder token, int resultCode,
35963597
}
35973598
ActivityRecord r = mHistory.get(index);
35983599

3599-
finishActivityLocked(r, index, resultCode, resultData, reason);
3600+
finishActivityLocked(r, index, resultCode, resultData, reason, oomAdj);
36003601
return true;
36013602
}
36023603

@@ -3613,10 +3614,11 @@ final void finishSubActivityLocked(IBinder token, String resultWho, int requestC
36133614
if ((r.resultWho == null && resultWho == null) ||
36143615
(r.resultWho != null && r.resultWho.equals(resultWho))) {
36153616
finishActivityLocked(r, i,
3616-
Activity.RESULT_CANCELED, null, "request-sub");
3617+
Activity.RESULT_CANCELED, null, "request-sub", false);
36173618
}
36183619
}
36193620
}
3621+
mService.updateOomAdjLocked();
36203622
}
36213623

36223624
final boolean finishActivityAffinityLocked(IBinder token) {
@@ -3639,7 +3641,8 @@ final boolean finishActivityAffinityLocked(IBinder token) {
36393641
if (cur.taskAffinity != null && !cur.taskAffinity.equals(r.taskAffinity)) {
36403642
break;
36413643
}
3642-
finishActivityLocked(cur, index, Activity.RESULT_CANCELED, null, "request-affinity");
3644+
finishActivityLocked(cur, index, Activity.RESULT_CANCELED, null,
3645+
"request-affinity", true);
36433646
index--;
36443647
}
36453648
return true;
@@ -3677,16 +3680,16 @@ final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent
36773680
* list, or false if it is still in the list and will be removed later.
36783681
*/
36793682
final boolean finishActivityLocked(ActivityRecord r, int index,
3680-
int resultCode, Intent resultData, String reason) {
3681-
return finishActivityLocked(r, index, resultCode, resultData, reason, false);
3683+
int resultCode, Intent resultData, String reason, boolean oomAdj) {
3684+
return finishActivityLocked(r, index, resultCode, resultData, reason, false, oomAdj);
36823685
}
36833686

36843687
/**
36853688
* @return Returns true if this activity has been removed from the history
36863689
* list, or false if it is still in the list and will be removed later.
36873690
*/
3688-
final boolean finishActivityLocked(ActivityRecord r, int index,
3689-
int resultCode, Intent resultData, String reason, boolean immediate) {
3691+
final boolean finishActivityLocked(ActivityRecord r, int index, int resultCode,
3692+
Intent resultData, String reason, boolean immediate, boolean oomAdj) {
36903693
if (r.finishing) {
36913694
Slog.w(TAG, "Duplicate finish request for " + r);
36923695
return false;
@@ -3730,7 +3733,7 @@ final boolean finishActivityLocked(ActivityRecord r, int index,
37303733

37313734
if (immediate) {
37323735
return finishCurrentActivityLocked(r, index,
3733-
FINISH_IMMEDIATELY) == null;
3736+
FINISH_IMMEDIATELY, oomAdj) == null;
37343737
} else if (mResumedActivity == r) {
37353738
boolean endTask = index <= 0
37363739
|| (mHistory.get(index-1)).task != r.task;
@@ -3754,7 +3757,7 @@ final boolean finishActivityLocked(ActivityRecord r, int index,
37543757
// it is done pausing; else we can just directly finish it here.
37553758
if (DEBUG_PAUSE) Slog.v(TAG, "Finish not pausing: " + r);
37563759
return finishCurrentActivityLocked(r, index,
3757-
FINISH_AFTER_PAUSE) == null;
3760+
FINISH_AFTER_PAUSE, oomAdj) == null;
37583761
} else {
37593762
if (DEBUG_PAUSE) Slog.v(TAG, "Finish waiting for pause of: " + r);
37603763
}
@@ -3767,17 +3770,17 @@ final boolean finishActivityLocked(ActivityRecord r, int index,
37673770
private static final int FINISH_AFTER_VISIBLE = 2;
37683771

37693772
private final ActivityRecord finishCurrentActivityLocked(ActivityRecord r,
3770-
int mode) {
3773+
int mode, boolean oomAdj) {
37713774
final int index = indexOfActivityLocked(r);
37723775
if (index < 0) {
37733776
return null;
37743777
}
37753778

3776-
return finishCurrentActivityLocked(r, index, mode);
3779+
return finishCurrentActivityLocked(r, index, mode, oomAdj);
37773780
}
37783781

37793782
private final ActivityRecord finishCurrentActivityLocked(ActivityRecord r,
3780-
int index, int mode) {
3783+
int index, int mode, boolean oomAdj) {
37813784
// First things first: if this activity is currently visible,
37823785
// and the resumed activity is not yet visible, then hold off on
37833786
// finishing until the resumed one becomes visible.
@@ -3796,7 +3799,9 @@ private final ActivityRecord finishCurrentActivityLocked(ActivityRecord r,
37963799
if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r
37973800
+ " (finish requested)");
37983801
r.state = ActivityState.STOPPING;
3799-
mService.updateOomAdjLocked();
3802+
if (oomAdj) {
3803+
mService.updateOomAdjLocked();
3804+
}
38003805
return r;
38013806
}
38023807

@@ -3816,7 +3821,8 @@ private final ActivityRecord finishCurrentActivityLocked(ActivityRecord r,
38163821
|| prevState == ActivityState.INITIALIZING) {
38173822
// If this activity is already stopped, we can just finish
38183823
// it right now.
3819-
boolean activityRemoved = destroyActivityLocked(r, true, true, "finish-imm");
3824+
boolean activityRemoved = destroyActivityLocked(r, true,
3825+
oomAdj, "finish-imm");
38203826
if (activityRemoved) {
38213827
resumeTopActivityLocked(null);
38223828
}
@@ -4008,9 +4014,8 @@ final boolean destroyActivityLocked(ActivityRecord r,
40084014
ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG);
40094015
}
40104016
if (r.app.activities.size() == 0) {
4011-
// No longer have activities, so update location in
4012-
// LRU list.
4013-
mService.updateLruProcessLocked(r.app, oomAdj, false);
4017+
// No longer have activities, so update oom adj.
4018+
mService.updateOomAdjLocked();
40144019
}
40154020
}
40164021

0 commit comments

Comments
 (0)