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

Commit 06950d6f authored by Jorge Gil's avatar Jorge Gil
Browse files

Resume root task's children preserving order

Changes #resumeTopActivityUncheckedLocked for the non-leaf case from
resuming top->bottom to resuming bottom->top to ensure the original Z
order is preserved inside desktop windowing root tasks used for "desks".

First, we find the tasks that should be resumed (are visible)
top->bottom to keep the break behavior to avoid unnecesarily resuming
activities that won't be visible in the end.
Then, we resume the tasks found in reverse (bottom->top) order so that
order is kept unchanged.

Flag: com.android.window.flags.enable_multiple_desktops_backend
Fix: 414410702
Test: in desktop-first display, open Gmail, then Chrome - verify
"adb shell dumpsys activity activities | grep -e mFocusedApp" shows
Chrome is the focused app, not Gmail

Change-Id: If833078db1ea907ed9e2d5d17b0f309590fca14c
parent e397f4dc
Loading
Loading
Loading
Loading
+50 −19
Original line number Original line Diff line number Diff line
@@ -5244,6 +5244,34 @@ class Task extends TaskFragment {
                if (isFocusableAndVisible()) {
                if (isFocusableAndVisible()) {
                    someActivityResumed = resumeTopActivityInnerLocked(prev, options, deferPause);
                    someActivityResumed = resumeTopActivityInnerLocked(prev, options, deferPause);
                }
                }
            } else {
                if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue()) {
                    // Find visible tasks top-to-bottom.
                    final List<Task> tasksToResumeTopToBottom = new ArrayList<>();
                    for (int i = mChildren.size() - 1; i >= 0; i--) {
                        final Task child = (Task) getChildAt(i);
                        if (!child.isTopActivityFocusable()) {
                            continue;
                        }
                        if (child.getVisibility(null /* starting */)
                                != TASK_FRAGMENT_VISIBILITY_VISIBLE) {
                            if (child.topRunningActivity() == null) {
                                // Skip the task if no running activity and continue resuming next
                                // task.
                                continue;
                            }
                            // Otherwise, assuming everything behind this task should also be
                            // invisible.
                            break;
                        }
                        tasksToResumeTopToBottom.add(child);
                    }
                    // Resume them bottom-to-top, so Z order is preserved.
                    for (int i = tasksToResumeTopToBottom.size() - 1; i >= 0; i--) {
                        final Task child = tasksToResumeTopToBottom.get(i);
                        someActivityResumed |= child.resumeTopActivityUncheckedLocked(prev,
                                options, deferPause);
                    }
                } else {
                } else {
                    int idx = mChildren.size() - 1;
                    int idx = mChildren.size() - 1;
                    while (idx >= 0) {
                    while (idx >= 0) {
@@ -5254,10 +5282,12 @@ class Task extends TaskFragment {
                        if (child.getVisibility(null /* starting */)
                        if (child.getVisibility(null /* starting */)
                                != TASK_FRAGMENT_VISIBILITY_VISIBLE) {
                                != TASK_FRAGMENT_VISIBILITY_VISIBLE) {
                            if (child.topRunningActivity() == null) {
                            if (child.topRunningActivity() == null) {
                            // Skip the task if no running activity and continue resuming next task.
                                // Skip the task if no running activity and continue resuming next
                                // task.
                                continue;
                                continue;
                            }
                            }
                        // Otherwise, assuming everything behind this task should also be invisible.
                            // Otherwise, assuming everything behind this task should also be
                            // invisible.
                            break;
                            break;
                        }
                        }


@@ -5271,6 +5301,7 @@ class Task extends TaskFragment {
                        }
                        }
                    }
                    }
                }
                }
            }


            // When resuming the top activity, it may be necessary to pause the top activity (for
            // When resuming the top activity, it may be necessary to pause the top activity (for
            // example, returning to the lock screen. We suppress the normal pause logic in
            // example, returning to the lock screen. We suppress the normal pause logic in