From 63b8ee365d1be3df6e340f94eea05eb59a8e76d8 Mon Sep 17 00:00:00 2001 From: Shunta Sato Date: Mon, 11 Jul 2016 13:32:52 +0900 Subject: [PATCH] Return to Home stack when a context of tasks launched from Home finished When the following conditions happen together, another context in Application stack was launched unexpectedly: - There is a context of tasks in Application stack, which is launched from a task on Home stack. - All tasks/activities in the context are finishing. Solution: Add a condition check to see if the task is NOT one of the task finishing on-top of the top running task. Bug: 30883775 Test: manual Author: Ichitaro Kohara Change-Id: I5d6097a7c8dc2733ff684957370c987dd158e329 --- .../com/android/server/am/ActivityStack.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index f13b11e65a883..b9aa7ec79c544 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -3215,8 +3215,25 @@ class ActivityStack extends ConfigurationContai r.addResultLocked(null, resultWho, requestCode, resultCode, data); } + /** Returns true if the task is one of the task finishing on-top of the top running task. */ + boolean isATopFinishingTask(TaskRecord task) { + for (int i = mTaskHistory.size() - 1; i >= 0; --i) { + final TaskRecord current = mTaskHistory.get(i); + final ActivityRecord r = current.topRunningActivityLocked(); + if (r != null) { + // We got a top running activity, so there isn't a top finishing task... + return false; + } + if (current == task) { + return true; + } + } + return false; + } + private void adjustFocusedActivityStackLocked(ActivityRecord r, String reason) { - if (!mStackSupervisor.isFocusedStack(this) || mResumedActivity != r) { + if (!mStackSupervisor.isFocusedStack(this) || + ((mResumedActivity != r) && (mResumedActivity != null))) { return; } @@ -3231,8 +3248,8 @@ class ActivityStack extends ConfigurationContai final TaskRecord task = r.getTask(); final boolean isAssistantOrOverAssistant = task.getStack().isAssistantStack() || task.isOverAssistantStack(); - if (r.frontOfTask && task == topTask() && - (task.isOverHomeStack() || isAssistantOrOverAssistant)) { + if (r.frontOfTask && isATopFinishingTask(task) + && (task.isOverHomeStack() || isAssistantOrOverAssistant)) { // For non-fullscreen or assistant stack, we want to move the focus to the next // visible stack to prevent the home screen from moving to the top and obscuring // other visible stacks.