From d34e80c0bc5ddff8289563fef8ca47451b46b459 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Wed, 23 Mar 2016 17:08:44 -0700 Subject: [PATCH] Return to correct home stack task in multi-window mode Previously when determining the next stack to focus to in multi-window mode, if it is the home stack we just bring it forward and focus on whatever the home task/activity is. We should be checking the returnToTask type of the activity/task that is going away to determine which task in the home stack we should return to. Bug: 27776008 Change-Id: I1a864c96b2ef276d2ddeafcb627a2b6a825e2ce7 --- .../com/android/server/am/ActivityStack.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 26eaa8a2b1868..bbc37cd83a18f 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -1980,7 +1980,9 @@ final class ActivityStack { if (next == null) { // There are no more activities! final String reason = "noMoreActivities"; - if (!mFullscreen && adjustFocusToNextFocusableStackLocked(reason)) { + final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() + ? HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); + if (!mFullscreen && adjustFocusToNextFocusableStackLocked(returnTaskType, reason)) { // Try to move focus to the next visible stack with a running activity if this // stack is not covering the entire screen. return mStackSupervisor.resumeFocusedStackTopActivityLocked( @@ -1993,8 +1995,6 @@ final class ActivityStack { "resumeTopActivityLocked: No more activities go home"); if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); // Only resume home if on home display - final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? - HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); return isOnHomeDisplay() && mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason); } @@ -3004,16 +3004,18 @@ final class ActivityStack { } else { final TaskRecord task = r.task; if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) { + final int taskToReturnTo = task.getTaskToReturnTo(); + // For non-fullscreen 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. - if (!mFullscreen && adjustFocusToNextFocusableStackLocked(myReason)) { + if (!mFullscreen + && adjustFocusToNextFocusableStackLocked(taskToReturnTo, myReason)) { return; } // Move the home stack to the top if this stack is fullscreen or there is no // other visible stack. - if (mStackSupervisor.moveHomeStackTaskToTop( - task.getTaskToReturnTo(), myReason)) { + if (mStackSupervisor.moveHomeStackTaskToTop(taskToReturnTo, myReason)) { // Activity focus was already adjusted. Nothing else to do... return; } @@ -3024,12 +3026,16 @@ final class ActivityStack { mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked(), myReason); } - private boolean adjustFocusToNextFocusableStackLocked(String reason) { + private boolean adjustFocusToNextFocusableStackLocked(int taskToReturnTo, String reason) { final ActivityStack stack = getNextFocusableStackLocked(); final String myReason = reason + " adjustFocusToNextFocusableStack"; if (stack == null) { return false; } + + if (stack.isHomeStack()) { + return mStackSupervisor.moveHomeStackTaskToTop(taskToReturnTo, reason); + } return mService.setFocusedActivityLocked(stack.topRunningActivityLocked(), myReason); } @@ -4843,7 +4849,9 @@ final class ActivityStack { // We only need to adjust focused stack if this stack is in focus. if (isOnHomeDisplay() && mStackSupervisor.isFocusedStack(this)) { String myReason = reason + " leftTaskHistoryEmpty"; - if (mFullscreen || !adjustFocusToNextFocusableStackLocked(myReason)) { + if (mFullscreen + || !adjustFocusToNextFocusableStackLocked( + task.getTaskToReturnTo(), myReason)) { mStackSupervisor.moveHomeStackToFront(myReason); } }