summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Craig Mautner <cmautner@google.com> 2013-09-30 17:10:02 -0700
committer Android Git Automerger <android-git-automerger@android.com> 2013-09-30 17:10:02 -0700
commit98b96d2c420d24aa9dc65881c6dd87c84baf5f0b (patch)
tree789d4f514be9ff560b116ce009f768e3b3820a50
parent4056c94adf97a4cbb3e8dce7caed8508f6524a0d (diff)
parent16e6e203c0c86a1cbc1a7c1cf20cb5447f705a32 (diff)
am 16e6e203: Merge "Centralize handleAppDied and fix return to home." into klp-dev
* commit '16e6e203c0c86a1cbc1a7c1cf20cb5447f705a32': Centralize handleAppDied and fix return to home.
-rw-r--r--services/java/com/android/server/am/ActivityStack.java65
-rw-r--r--services/java/com/android/server/am/ActivityStackSupervisor.java22
-rw-r--r--services/java/com/android/server/am/TaskRecord.java10
3 files changed, 65 insertions, 32 deletions
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index 18ff8197c5b1..a7fc99593301 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -334,20 +334,16 @@ final class ActivityStack {
mCurrentUser = service.mCurrentUserId;
}
- private boolean okToShow(ActivityRecord r) {
+ boolean okToShow(ActivityRecord r) {
return r.userId == mCurrentUser
|| (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0;
}
final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
- final TaskRecord task = mTaskHistory.get(taskNdx);
- final ArrayList<ActivityRecord> activities = task.mActivities;
- for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
- ActivityRecord r = activities.get(activityNdx);
- if (!r.finishing && r != notTop && okToShow(r)) {
- return r;
- }
+ ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(notTop);
+ if (r != null) {
+ return r;
}
}
return null;
@@ -3405,11 +3401,16 @@ final class ActivityStack {
}
}
- void handleAppDiedLocked(ProcessRecord app, boolean restarting) {
+ /**
+ * Reset local parameters because an app's activity died.
+ * @param app The app of the activity that died.
+ * @return true if home should be launched next.
+ */
+ boolean handleAppDiedLocked(ProcessRecord app) {
if (!containsApp(app)) {
- return;
+ return false;
}
- // TODO: handle the case where an app spans multiple stacks.
+
if (mPausingActivity != null && mPausingActivity.app == app) {
if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG,
"App died while pausing: " + mPausingActivity);
@@ -3419,28 +3420,32 @@ final class ActivityStack {
mLastPausedActivity = null;
mLastNoHistoryActivity = null;
}
- final ActivityRecord top = topRunningActivityLocked(null);
- final boolean launchHomeTaskNext =
- top != null && top.app == app && top.task.mOnTopOfHome;
-
- // Remove this application's activities from active lists.
- boolean hasVisibleActivities = removeHistoryRecordsForAppLocked(app);
- if (!restarting) {
- ActivityStack stack = mStackSupervisor.getFocusedStack();
- if (stack == null || launchHomeTaskNext) {
- mStackSupervisor.resumeHomeActivity(null);
- } else if (!mStackSupervisor.resumeTopActivitiesLocked(stack, null, null)) {
- // If there was nothing to resume, and we are not already
- // restarting this process, but there is a visible activity that
- // is hosted by the process... then make sure all visible
- // activities are running, taking care of restarting this
- // process.
- if (hasVisibleActivities) {
- mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
- }
+ // Determine if the top task is exiting and should return to home. Do this before it gets
+ // removed in removeHistoryRecordsForAppsLocked.
+ boolean launchHomeNext = false;
+ int top = mTaskHistory.size() - 1;
+ while (top >= 0) {
+ final TaskRecord topTask = mTaskHistory.get(top);
+ if (topTask.mActivities.isEmpty()) {
+ // Not possible, but just in case.
+ --top;
+ continue;
}
+ ActivityRecord r = topTask.topRunningActivityLocked(null);
+ if (r != null) {
+ // r will be launched next.
+ break;
+ }
+ // There is an activity in topTask that is finishing. If topTask belongs to the app
+ // return to home depending on the task flag.
+ launchHomeNext = topTask.mOnTopOfHome;
+ break;
}
+
+ removeHistoryRecordsForAppLocked(app);
+
+ return launchHomeNext;
}
void handleAppCrashLocked(ProcessRecord app) {
diff --git a/services/java/com/android/server/am/ActivityStackSupervisor.java b/services/java/com/android/server/am/ActivityStackSupervisor.java
index 1ee13ec96ed1..bf9190435d2b 100644
--- a/services/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/java/com/android/server/am/ActivityStackSupervisor.java
@@ -1932,10 +1932,28 @@ public final class ActivityStackSupervisor {
}
void handleAppDiedLocked(ProcessRecord app, boolean restarting) {
- // Just in case.
+ boolean launchHomeTaskNext = false;
+ final ActivityStack focusedStack = getFocusedStack();
final int numStacks = mStacks.size();
for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
- mStacks.get(stackNdx).handleAppDiedLocked(app, restarting);
+ final ActivityStack stack = mStacks.get(stackNdx);
+ // Only update launchHomeTaskNext for the focused stack.
+ launchHomeTaskNext |= (stack == focusedStack && stack.handleAppDiedLocked(app));
+ }
+
+ if (!restarting) {
+ if (launchHomeTaskNext) {
+ resumeHomeActivity(null);
+ } else {
+ if (!resumeTopActivitiesLocked(focusedStack, null, null)) {
+ // If there was nothing to resume, and we are not already
+ // restarting this process, but there is a visible activity that
+ // is hosted by the process... then make sure all visible
+ // activities are running, taking care of restarting this
+ // process.
+ ensureActivitiesVisibleLocked(null, 0);
+ }
+ }
}
}
diff --git a/services/java/com/android/server/am/TaskRecord.java b/services/java/com/android/server/am/TaskRecord.java
index f0bba4f99726..8a9324ce0d2b 100644
--- a/services/java/com/android/server/am/TaskRecord.java
+++ b/services/java/com/android/server/am/TaskRecord.java
@@ -139,6 +139,16 @@ final class TaskRecord extends ThumbnailHolder {
return null;
}
+ ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
+ for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
+ ActivityRecord r = mActivities.get(activityNdx);
+ if (!r.finishing && r != notTop && stack.okToShow(r)) {
+ return r;
+ }
+ }
+ return null;
+ }
+
/**
* Reorder the history stack so that the activity at the given index is
* brought to the front.