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

Commit e264ac63 authored by Chris Li's avatar Chris Li
Browse files

Allow TaskDisplayArea to have TaskDisplayArea children (1/n)

- Remove TaskDisplayArea#getRootTaskAt(int index) because the child at
the requested index may not be a Task.
- Change root task traversal to use forAllRootTasks().

For usages in TaskDisplayArea, update to traverse using mChildren for
now. Will revisit them when changing the signature.

Bug: 175136051
Test: manual for refacotor
Change-Id: I36cd6edc99c3218743cde5e64c7892e91cde63b5
parent c43d935c
Loading
Loading
Loading
Loading
+10 −14
Original line number Original line Diff line number Diff line
@@ -2260,9 +2260,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                        taskDisplayArea.getRootTask(rootTaskId));
                        taskDisplayArea.getRootTask(rootTaskId));
    }
    }


    protected int getRootTaskCount() {
    int getRootTaskCount() {
        return reduceOnAllTaskDisplayAreas((taskDisplayArea, count) ->
        final int[] count = new int[1];
                count + taskDisplayArea.getRootTaskCount(), 0 /* initValue */);
        forAllRootTasks(task -> {
            count[0]++;
        });
        return count[0];
    }
    }


    @VisibleForTesting
    @VisibleForTesting
@@ -5355,19 +5358,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        }
        }


        // Check if all task display areas have only the empty home stacks left.
        // Check if all task display areas have only the empty home stacks left.
        boolean hasNonEmptyHomeStack = forAllTaskDisplayAreas(taskDisplayArea -> {
        boolean hasNonEmptyHomeStack = forAllRootTasks(stack ->
            if (taskDisplayArea.getRootTaskCount() != 1) {
                !stack.isActivityTypeHome() || stack.hasChild());
                return true;
        if (!hasNonEmptyHomeStack && getRootTaskCount() > 0) {
            }
            final Task stack = taskDisplayArea.getRootTaskAt(0);
            return !stack.isActivityTypeHome() || stack.hasChild();
        });
        if (!hasNonEmptyHomeStack) {
            // Release this display if only empty home stack(s) are left. This display will be
            // Release this display if only empty home stack(s) are left. This display will be
            // released along with the stack(s) removal.
            // released along with the stack(s) removal.
            forAllTaskDisplayAreas(taskDisplayArea -> {
            forAllRootTasks(Task::removeIfPossible);
                taskDisplayArea.getRootTaskAt(0).removeIfPossible();
            });
        } else if (getTopRootTask() == null) {
        } else if (getTopRootTask() == null) {
            removeIfPossible();
            removeIfPossible();
            mRootWindowContainer.mTaskSupervisor
            mRootWindowContainer.mTaskSupervisor
+2 −10
Original line number Original line Diff line number Diff line
@@ -594,16 +594,8 @@ class KeyguardController {
         */
         */
        @Nullable
        @Nullable
        private Task getRootTaskForControllingOccluding(DisplayContent display) {
        private Task getRootTaskForControllingOccluding(DisplayContent display) {
            return display.getItemFromTaskDisplayAreas(taskDisplayArea -> {
            return display.getRootTask(task ->
                for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                    task != null && task.isFocusableAndVisible() && !task.inPinnedWindowingMode());
                    final Task task = taskDisplayArea.getRootTaskAt(sNdx);
                    if (task != null && task.isFocusableAndVisible()
                            && !task.inPinnedWindowingMode()) {
                        return task;
                    }
                }
                return null;
            });
        }
        }


        void dumpStatus(PrintWriter pw, String prefix) {
        void dumpStatus(PrintWriter pw, String prefix) {
+2 −8
Original line number Original line Diff line number Diff line
@@ -468,14 +468,8 @@ class RecentsAnimation implements RecentsAnimationCallbacks, OnRootTaskOrderChan
     * @return The top stack that is not always-on-top.
     * @return The top stack that is not always-on-top.
     */
     */
    private Task getTopNonAlwaysOnTopStack() {
    private Task getTopNonAlwaysOnTopStack() {
        for (int i = mDefaultTaskDisplayArea.getRootTaskCount() - 1; i >= 0; i--) {
        return mDefaultTaskDisplayArea.getRootTask(task ->
            final Task s = mDefaultTaskDisplayArea.getRootTaskAt(i);
                !task.getWindowConfiguration().isAlwaysOnTop());
            if (s.getWindowConfiguration().isAlwaysOnTop()) {
                continue;
            }
            return s;
        }
        return null;
    }
    }


    /**
    /**
+150 −208
Original line number Original line Diff line number Diff line
@@ -1833,10 +1833,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        final ArrayList<IBinder> topActivityTokens = new ArrayList<>();
        final ArrayList<IBinder> topActivityTokens = new ArrayList<>();
        final Task topFocusedStack = getTopDisplayFocusedRootTask();
        final Task topFocusedStack = getTopDisplayFocusedRootTask();
        // Traverse all displays.
        // Traverse all displays.
        forAllTaskDisplayAreas(taskDisplayArea -> {
        forAllRootTasks(stack -> {
            // Traverse all stacks on a display area.
            for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                final Task stack = taskDisplayArea.getRootTaskAt(sNdx);
            // Get top activity from a visible stack and add it to the list.
            // Get top activity from a visible stack and add it to the list.
            if (stack.shouldBeVisible(null /* starting */)) {
            if (stack.shouldBeVisible(null /* starting */)) {
                final ActivityRecord top = stack.getTopNonFinishingActivity();
                final ActivityRecord top = stack.getTopNonFinishingActivity();
@@ -1848,7 +1845,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                    }
                    }
                }
                }
            }
            }
            }
        });
        });
        return topActivityTokens;
        return topActivityTokens;
    }
    }
@@ -1890,21 +1886,17 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        // First, found out what is currently the foreground app, so that we don't blow away the
        // First, found out what is currently the foreground app, so that we don't blow away the
        // previous app if this activity is being hosted by the process that is actually still the
        // previous app if this activity is being hosted by the process that is actually still the
        // foreground.
        // foreground.
        WindowProcessController fgApp = reduceOnAllTaskDisplayAreas((taskDisplayArea, app) -> {
        WindowProcessController fgApp = getItemFromRootTasks(stack -> {
            for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                final Task stack = taskDisplayArea.getRootTaskAt(sNdx);
            if (isTopDisplayFocusedRootTask(stack)) {
            if (isTopDisplayFocusedRootTask(stack)) {
                final ActivityRecord resumedActivity = stack.getResumedActivity();
                final ActivityRecord resumedActivity = stack.getResumedActivity();
                if (resumedActivity != null) {
                if (resumedActivity != null) {
                        app = resumedActivity.app;
                    return resumedActivity.app;
                } else if (stack.mPausingActivity != null) {
                } else if (stack.mPausingActivity != null) {
                        app = stack.mPausingActivity.app;
                    return stack.mPausingActivity.app;
                    }
                    break;
                }
                }
            }
            }
            return app;
            return null;
        }, null /* initValue */);
        });


        // Now set this one as the previous process, only if that really makes sense to.
        // Now set this one as the previous process, only if that really makes sense to.
        if (r.hasProcess() && fgApp != null && r.app != fgApp
        if (r.hasProcess() && fgApp != null && r.app != fgApp
@@ -1921,15 +1913,13 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            mTmpRemoteException = null;
            mTmpRemoteException = null;
            mTmpBoolean = false; // Set to true if an activity was started.
            mTmpBoolean = false; // Set to true if an activity was started.
            final DisplayContent display = getChildAt(displayNdx);
            final DisplayContent display = getChildAt(displayNdx);
            display.forAllTaskDisplayAreas(displayArea -> {
            display.forAllRootTasks(rootTask -> {
                if (mTmpRemoteException != null) {
                if (mTmpRemoteException != null) {
                    return;
                    return;
                }
                }


                for (int taskNdx = displayArea.getRootTaskCount() - 1; taskNdx >= 0; --taskNdx) {
                    final Task rootTask = displayArea.getRootTaskAt(taskNdx);
                if (rootTask.getVisibility(null /*starting*/) == TASK_VISIBILITY_INVISIBLE) {
                if (rootTask.getVisibility(null /*starting*/) == TASK_VISIBILITY_INVISIBLE) {
                        break;
                    return;
                }
                }


                final PooledFunction c = PooledLambda.obtainFunction(
                final PooledFunction c = PooledLambda.obtainFunction(
@@ -1938,10 +1928,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                        rootTask.topRunningActivity());
                        rootTask.topRunningActivity());
                rootTask.forAllActivities(c);
                rootTask.forAllActivities(c);
                c.recycle();
                c.recycle();
                    if (mTmpRemoteException != null) {
                        return;
                    }
                }
            });
            });
            if (mTmpRemoteException != null) {
            if (mTmpRemoteException != null) {
                throw mTmpRemoteException;
                throw mTmpRemoteException;
@@ -2025,11 +2011,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        mCurrentUser = userId;
        mCurrentUser = userId;


        mTaskSupervisor.mStartingUsers.add(uss);
        mTaskSupervisor.mStartingUsers.add(uss);
        forAllTaskDisplayAreas(taskDisplayArea -> {
        forAllRootTasks(stack -> {
            for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                final Task stack = taskDisplayArea.getRootTaskAt(sNdx);
            stack.switchUser(userId);
            stack.switchUser(userId);
            }
        });
        });


        final int restoreStackId = mUserRootTaskInFront.get(userId);
        final int restoreStackId = mUserRootTaskInFront.get(userId);
@@ -2292,20 +2275,14 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
     */
     */
    int finishTopCrashedActivities(WindowProcessController app, String reason) {
    int finishTopCrashedActivities(WindowProcessController app, String reason) {
        Task focusedStack = getTopDisplayFocusedRootTask();
        Task focusedStack = getTopDisplayFocusedRootTask();
        Task finishedTask = reduceOnAllTaskDisplayAreas((taskDisplayArea, task) -> {
        final Task[] finishedTask = new Task[1];
            // It is possible that request to finish activity might also remove its task and
        forAllTasks(stack -> {
            // stack, so we need to be careful with indexes in the loop and check child count
            // every time.
            for (int stackNdx = 0; stackNdx < taskDisplayArea.getRootTaskCount(); ++stackNdx) {
                final Task stack = taskDisplayArea.getRootTaskAt(stackNdx);
            final Task t = stack.finishTopCrashedActivityLocked(app, reason);
            final Task t = stack.finishTopCrashedActivityLocked(app, reason);
                if (stack == focusedStack || task == null) {
            if (stack == focusedStack || finishedTask[0] == null) {
                    task = t;
                finishedTask[0] = t;
                }
            }
            }
            return task;
        });
        }, null /* initValue */);
        return finishedTask[0] != null ? finishedTask[0].mTaskId : INVALID_TASK_ID;
        return finishedTask != null ? finishedTask.mTaskId : INVALID_TASK_ID;
    }
    }


    boolean resumeFocusedTasksTopActivities() {
    boolean resumeFocusedTasksTopActivities() {
@@ -2328,36 +2305,32 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        for (int displayNdx = getChildCount() - 1; displayNdx >= 0; --displayNdx) {
        for (int displayNdx = getChildCount() - 1; displayNdx >= 0; --displayNdx) {
            final DisplayContent display = getChildAt(displayNdx);
            final DisplayContent display = getChildAt(displayNdx);
            final boolean curResult = result;
            final boolean curResult = result;
            boolean resumedOnDisplay = display.reduceOnAllTaskDisplayAreas(
            boolean[] resumedOnDisplay = new boolean[1];
                    (taskDisplayArea, resumed) -> {
            display.forAllRootTasks(rootTask -> {
                        for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                            final Task rootTask = taskDisplayArea.getRootTaskAt(sNdx);
                final ActivityRecord topRunningActivity = rootTask.topRunningActivity();
                final ActivityRecord topRunningActivity = rootTask.topRunningActivity();
                if (!rootTask.isFocusableAndVisible() || topRunningActivity == null) {
                if (!rootTask.isFocusableAndVisible() || topRunningActivity == null) {
                                continue;
                    return;
                }
                }
                if (rootTask == targetRootTask) {
                if (rootTask == targetRootTask) {
                    // Simply update the result for targetStack because the targetStack
                    // Simply update the result for targetStack because the targetStack
                    // had already resumed in above. We don't want to resume it again,
                    // had already resumed in above. We don't want to resume it again,
                    // especially in some cases, it would cause a second launch failure
                    // especially in some cases, it would cause a second launch failure
                    // if app process was dead.
                    // if app process was dead.
                                resumed |= curResult;
                    resumedOnDisplay[0] |= curResult;
                                continue;
                    return;
                }
                }
                            if (taskDisplayArea.isTopRootTask(rootTask)
                if (rootTask.getDisplayArea().isTopRootTask(rootTask)
                        && topRunningActivity.isState(RESUMED)) {
                        && topRunningActivity.isState(RESUMED)) {
                    // Kick off any lingering app transitions form the MoveTaskToFront
                    // Kick off any lingering app transitions form the MoveTaskToFront
                    // operation, but only consider the top task and stack on that
                    // operation, but only consider the top task and stack on that
                    // display.
                    // display.
                    rootTask.executeAppTransition(targetOptions);
                    rootTask.executeAppTransition(targetOptions);
                } else {
                } else {
                                resumed |= topRunningActivity.makeActiveIfNeeded(target);
                    resumedOnDisplay[0] |= topRunningActivity.makeActiveIfNeeded(target);
                }
                }
                        }
            });
                        return resumed;
            result |= resumedOnDisplay[0];
                    }, false /* initValue */);
            if (!resumedOnDisplay[0]) {
            result |= resumedOnDisplay;
            if (!resumedOnDisplay) {
                // In cases when there are no valid activities (e.g. device just booted or launcher
                // In cases when there are no valid activities (e.g. device just booted or launcher
                // crashed) it's possible that nothing was resumed on a display. Requesting resume
                // crashed) it's possible that nothing was resumed on a display. Requesting resume
                // of top activity in focused stack explicitly will make sure that at least home
                // of top activity in focused stack explicitly will make sure that at least home
@@ -2390,9 +2363,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            }
            }


            // Set the sleeping state of the stacks on the display.
            // Set the sleeping state of the stacks on the display.
            display.forAllTaskDisplayAreas(taskDisplayArea -> {
            display.forAllRootTasks(stack -> {
                for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                    final Task stack = taskDisplayArea.getRootTaskAt(sNdx);
                if (displayShouldSleep) {
                if (displayShouldSleep) {
                    stack.goToSleepIfPossible(false /* shuttingDown */);
                    stack.goToSleepIfPossible(false /* shuttingDown */);
                } else {
                } else {
@@ -2414,7 +2385,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                    stack.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
                    stack.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
                            false /* preserveWindows */);
                            false /* preserveWindows */);
                }
                }
                }
            });
            });
        }
        }
    }
    }
@@ -2510,13 +2480,10 @@ class RootWindowContainer extends WindowContainer<DisplayContent>


    /** If displayId == INVALID_DISPLAY, this will get root task infos on all displays */
    /** If displayId == INVALID_DISPLAY, this will get root task infos on all displays */
    ArrayList<RootTaskInfo> getAllRootTaskInfos(int displayId) {
    ArrayList<RootTaskInfo> getAllRootTaskInfos(int displayId) {
        ArrayList<RootTaskInfo> list = new ArrayList<>();
        final ArrayList<RootTaskInfo> list = new ArrayList<>();
        if (displayId == INVALID_DISPLAY) {
        if (displayId == INVALID_DISPLAY) {
            forAllTaskDisplayAreas(taskDisplayArea -> {
            forAllRootTasks(stack -> {
                for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                    final Task stack = taskDisplayArea.getRootTaskAt(sNdx);
                list.add(getRootTaskInfo(stack));
                list.add(getRootTaskInfo(stack));
                }
            });
            });
            return list;
            return list;
        }
        }
@@ -2524,11 +2491,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        if (display == null) {
        if (display == null) {
            return list;
            return list;
        }
        }
        display.forAllTaskDisplayAreas(taskDisplayArea -> {
        display.forAllRootTasks(stack -> {
            for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                final Task stack = taskDisplayArea.getRootTaskAt(sNdx);
            list.add(getRootTaskInfo(stack));
            list.add(getRootTaskInfo(stack));
            }
        });
        });
        return list;
        return list;
    }
    }
@@ -2601,10 +2565,17 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
    Task findRootTaskBehind(Task rootTask) {
    Task findRootTaskBehind(Task rootTask) {
        final TaskDisplayArea taskDisplayArea = rootTask.getDisplayArea();
        final TaskDisplayArea taskDisplayArea = rootTask.getDisplayArea();
        if (taskDisplayArea != null) {
        if (taskDisplayArea != null) {
            for (int i = taskDisplayArea.getRootTaskCount() - 1; i >= 0; i--) {
            final boolean[] hasFound = new boolean[1];
                if (taskDisplayArea.getRootTaskAt(i) == rootTask && i > 0) {
            // TODO(b/175136051): should this be only the direct child root task?
                    return taskDisplayArea.getRootTaskAt(i - 1);
            final Task rootTaskBehind = taskDisplayArea.getRootTask(task -> {
                if (hasFound[0]) {
                    return true;
                }
                }
                hasFound[0] = task == rootTask;
                return false;
            });
            if (rootTaskBehind != null) {
                return rootTaskBehind;
            }
            }
        }
        }
        throw new IllegalStateException("Failed to find a root task behind root task =" + rootTask
        throw new IllegalStateException("Failed to find a root task behind root task =" + rootTask
@@ -2746,24 +2717,16 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
    // Tries to put all activity tasks to sleep. Returns true if all tasks were
    // Tries to put all activity tasks to sleep. Returns true if all tasks were
    // successfully put to sleep.
    // successfully put to sleep.
    boolean putTasksToSleep(boolean allowDelay, boolean shuttingDown) {
    boolean putTasksToSleep(boolean allowDelay, boolean shuttingDown) {
        return reduceOnAllTaskDisplayAreas((taskDisplayArea, result) -> {
        final boolean[] result = {true};
            for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
        forAllRootTasks(task -> {
                // Stacks and activities could be removed while putting activities to sleep if
                // the app process was gone. This prevents us getting exception by accessing an
                // invalid stack index.
                if (sNdx >= taskDisplayArea.getRootTaskCount()) {
                    continue;
                }
                final Task task = taskDisplayArea.getRootTaskAt(sNdx);
            if (allowDelay) {
            if (allowDelay) {
                    result &= task.goToSleepIfPossible(shuttingDown);
                result[0] &= task.goToSleepIfPossible(shuttingDown);
            } else {
            } else {
                task.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
                task.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
                        !PRESERVE_WINDOWS);
                        !PRESERVE_WINDOWS);
            }
            }
            }
        });
            return result;
        return result[0];
        }, true /* initValue */);
    }
    }


    void handleAppCrash(WindowProcessController app) {
    void handleAppCrash(WindowProcessController app) {
@@ -3019,11 +2982,11 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                r.getActivityType());
                r.getActivityType());


        // Return the topmost valid stack on the display.
        // Return the topmost valid stack on the display.
        for (int i = taskDisplayArea.getRootTaskCount() - 1; i >= 0; --i) {
        final int targetWindowingMode = windowingMode;
            final Task stack = taskDisplayArea.getRootTaskAt(i);
        final Task topmostValidStack = taskDisplayArea.getRootTask(stack ->
            if (isValidLaunchRootTask(stack, r, windowingMode)) {
                isValidLaunchRootTask(stack, r, targetWindowingMode));
                return stack;
        if (topmostValidStack != null) {
            }
            return topmostValidStack;
        }
        }


        // If there is no valid stack on the secondary display area - check if new dynamic stack
        // If there is no valid stack on the secondary display area - check if new dynamic stack
@@ -3258,12 +3221,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
    }
    }


    void finishVoiceTask(IVoiceInteractionSession session) {
    void finishVoiceTask(IVoiceInteractionSession session) {
        forAllTaskDisplayAreas(taskDisplayArea -> {
        forAllRootTasks(stack -> {
            final int numStacks = taskDisplayArea.getRootTaskCount();
            for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
                final Task stack = taskDisplayArea.getRootTaskAt(stackNdx);
            stack.finishVoiceTask(session);
            stack.finishVoiceTask(session);
            }
        });
        });
    }
    }


@@ -3322,10 +3281,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>


    boolean allResumedActivitiesVisible() {
    boolean allResumedActivitiesVisible() {
        boolean[] foundResumed = {false};
        boolean[] foundResumed = {false};
        final boolean foundInvisibleResumedActivity = forAllTaskDisplayAreas(
        final boolean foundInvisibleResumedActivity = forAllRootTasks(stack -> {
                taskDisplayArea -> {
                    for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                        final Task stack = taskDisplayArea.getRootTaskAt(sNdx);
            final ActivityRecord r = stack.getResumedActivity();
            final ActivityRecord r = stack.getResumedActivity();
            if (r != null) {
            if (r != null) {
                if (!r.nowVisible) {
                if (!r.nowVisible) {
@@ -3333,7 +3289,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                }
                }
                foundResumed[0] = true;
                foundResumed[0] = true;
            }
            }
                    }
            return false;
            return false;
        });
        });
        if (foundInvisibleResumedActivity) {
        if (foundInvisibleResumedActivity) {
@@ -3344,10 +3299,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>


    boolean allPausedActivitiesComplete() {
    boolean allPausedActivitiesComplete() {
        boolean[] pausing = {true};
        boolean[] pausing = {true};
        final boolean hasActivityNotCompleted = forAllTaskDisplayAreas(
        final boolean hasActivityNotCompleted = forAllRootTasks(stack -> {
                taskDisplayArea -> {
                    for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                        final Task stack = taskDisplayArea.getRootTaskAt(sNdx);
            final ActivityRecord r = stack.mPausingActivity;
            final ActivityRecord r = stack.mPausingActivity;
            if (r != null && !r.isState(PAUSED, STOPPED, STOPPING, FINISHING)) {
            if (r != null && !r.isState(PAUSED, STOPPED, STOPPING, FINISHING)) {
                ProtoLog.d(WM_DEBUG_STATES, "allPausedActivitiesComplete: "
                ProtoLog.d(WM_DEBUG_STATES, "allPausedActivitiesComplete: "
@@ -3358,7 +3310,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                    return true;
                    return true;
                }
                }
            }
            }
                    }
            return false;
            return false;
        });
        });
        if (hasActivityNotCompleted) {
        if (hasActivityNotCompleted) {
@@ -3411,13 +3362,10 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
    }
    }


    void cancelInitializingActivities() {
    void cancelInitializingActivities() {
        forAllTaskDisplayAreas(taskDisplayArea -> {
        forAllRootTasks(task -> {
            for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
            // We don't want to clear starting window for activities that aren't occluded
            // We don't want to clear starting window for activities that aren't occluded
            // as we need to display their starting window until they are done initializing.
            // as we need to display their starting window until they are done initializing.
                taskDisplayArea.getRootTaskAt(sNdx).forAllOccludedActivities(
            task.forAllOccludedActivities(ActivityRecord::cancelInitializing);
                        ActivityRecord::cancelInitializing);
            }
        });
        });
    }
    }


@@ -3577,14 +3525,11 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                return new ArrayList<>();
                return new ArrayList<>();
            }
            }
        } else {
        } else {
            ArrayList<ActivityRecord> activities = new ArrayList<>();
            final ArrayList<ActivityRecord> activities = new ArrayList<>();
            forAllTaskDisplayAreas(taskDisplayArea -> {
            forAllRootTasks(stack -> {
                for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                    final Task stack = taskDisplayArea.getRootTaskAt(sNdx);
                if (!dumpVisibleStacksOnly || stack.shouldBeVisible(null)) {
                if (!dumpVisibleStacksOnly || stack.shouldBeVisible(null)) {
                    activities.addAll(stack.getDumpActivitiesLocked(name));
                    activities.addAll(stack.getDumpActivitiesLocked(name));
                }
                }
                }
            });
            });
            return activities;
            return activities;
        }
        }
@@ -3633,15 +3578,12 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            pw.print("Display #");
            pw.print("Display #");
            pw.print(displayContent.mDisplayId);
            pw.print(displayContent.mDisplayId);
            pw.println(" (activities from top to bottom):");
            pw.println(" (activities from top to bottom):");
            displayContent.forAllTaskDisplayAreas(taskDisplayArea -> {
            displayContent.forAllRootTasks(stack -> {
                for (int sNdx = taskDisplayArea.getRootTaskCount() - 1; sNdx >= 0; --sNdx) {
                    final Task stack = taskDisplayArea.getRootTaskAt(sNdx);
                if (needSep[0]) {
                if (needSep[0]) {
                    pw.println();
                    pw.println();
                }
                }
                needSep[0] = stack.dump(fd, pw, dumpAll, dumpClient, dumpPackage, false);
                needSep[0] = stack.dump(fd, pw, dumpAll, dumpClient, dumpPackage, false);
                printed[0] |= needSep[0];
                printed[0] |= needSep[0];
                }
            });
            });
            displayContent.forAllTaskDisplayAreas(taskDisplayArea -> {
            displayContent.forAllTaskDisplayAreas(taskDisplayArea -> {
                printed[0] |= printThisActivity(pw, taskDisplayArea.getFocusedActivity(),
                printed[0] |= printThisActivity(pw, taskDisplayArea.getFocusedActivity(),
+24 −1
Original line number Original line Diff line number Diff line
@@ -224,7 +224,6 @@ import com.android.server.uri.NeededUriGrants;


import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.IOException;
@@ -3874,6 +3873,13 @@ class Task extends WindowContainer<WindowContainer> {
        callback.accept(this);
        callback.accept(this);
    }
    }


    @Override
    void forAllRootTasks(Consumer<Task> callback, boolean traverseTopToBottom) {
        if (isRootTask()) {
            callback.accept(this);
        }
    }

    @Override
    @Override
    boolean forAllTasks(Function<Task, Boolean> callback) {
    boolean forAllTasks(Function<Task, Boolean> callback) {
        if (super.forAllTasks(callback)) return true;
        if (super.forAllTasks(callback)) return true;
@@ -3898,6 +3904,11 @@ class Task extends WindowContainer<WindowContainer> {
        return false;
        return false;
    }
    }


    @Override
    boolean forAllRootTasks(Function<Task, Boolean> callback, boolean traverseTopToBottom) {
        return isRootTask() ? callback.apply(this) : false;
    }

    @Override
    @Override
    Task getTask(Predicate<Task> callback, boolean traverseTopToBottom) {
    Task getTask(Predicate<Task> callback, boolean traverseTopToBottom) {
        final Task t = super.getTask(callback, traverseTopToBottom);
        final Task t = super.getTask(callback, traverseTopToBottom);
@@ -3905,6 +3916,18 @@ class Task extends WindowContainer<WindowContainer> {
        return callback.test(this) ? this : null;
        return callback.test(this) ? this : null;
    }
    }


    @Nullable
    @Override
    Task getRootTask(Predicate<Task> callback, boolean traverseTopToBottom) {
        return isRootTask() && callback.test(this) ? this : null;
    }

    @Nullable
    @Override
    <R> R getItemFromRootTasks(Function<Task, R> callback, boolean traverseTopToBottom) {
        return isRootTask() ? callback.apply(this) : null;
    }

    /**
    /**
     * @param canAffectSystemUiFlags If false, all windows in this task can not affect SystemUI
     * @param canAffectSystemUiFlags If false, all windows in this task can not affect SystemUI
     *                               flags. See {@link WindowState#canAffectSystemUiFlags()}.
     *                               flags. See {@link WindowState#canAffectSystemUiFlags()}.
Loading