Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebf5eee5 authored by riddle_hsu's avatar riddle_hsu Committed by Steve Kondik
Browse files

Fix wrong focused stack if there are finishing tasks.

When there is more than one finishing tasks, topTask()
may not match the current finishing task to adjust.

https://code.google.com/p/android/issues/detail?id=192090

A sample step:
1.Launch task T from home.
2.Press home key.
3.Launch task A from home.
4.A launches task B.
5.B finishes self and A finishes onResume.

When adjustFocusedActivityLocked is called from A's finish,
both A and B are finishing and B has not destroyed yet,
so the top task is B that is not satisfy the original condition
to change focused stack. Then it still uses application stack
to resume, that is T.

After A completed destroy: activityDestroyedLocked ->
removeActivityFromHistoryLocked will check if it is over home.
So T only shows awile then return to home.

To handle this case, still check the behind tasks when the
adjusting task is not top task. If the task is alive, then
it stays in current stack, and if there is a finishing task
over home, then it should go home.

For above example, B is finishing (getTopActivity() will be
null) but it is not over home, then check the next which is A.
And because A is over home, then it can adjust to home stack.


Change-Id: Id5d6d58ccdac38bdbebba6df50a063b78182cd4f
parent dd854708
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -2671,7 +2671,23 @@ final class ActivityStack {
            final String myReason = reason + " adjustFocus";
            if (next != r) {
                final TaskRecord task = r.task;
                if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) {
                boolean adjust = false;
                if ((next == null || next.task != task) && r.frontOfTask) {
                    if (task.isOverHomeStack() && task == topTask()) {
                        adjust = true;
                    } else {
                        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
                            final TaskRecord tr = mTaskHistory.get(taskNdx);
                            if (tr.getTopActivity() != null) {
                                break;
                            } else if (tr.isOverHomeStack()) {
                                adjust = true;
                                break;
                            }
                        }
                    }
                }
                if (adjust) {
                    // 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.