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

Commit e65ceafe authored by Chris Li's avatar Chris Li Committed by Android (Google) Code Review
Browse files

Merge "Support z-ordering of task display areas"

parents aa21b421 0b002e78
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -2793,7 +2793,6 @@ class ActivityStack extends Task {

        Task task = child.asTask();
        try {

            if (task != null) {
                task.setForceShowForAllUsers(showForAllUsers);
            }
+61 −1
Original line number Diff line number Diff line
@@ -108,6 +108,66 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
        }
    }

    @Override
    void positionChildAt(int position, T child, boolean includingParents) {
        if (child.asDisplayArea() == null) {
            // Reposition other window containers as normal.
            super.positionChildAt(position, child, includingParents);
            return;
        }

        final int targetPosition = findPositionForChildDisplayArea(position, child.asDisplayArea());
        super.positionChildAt(targetPosition, child, false /* includingParents */);

        final WindowContainer parent = getParent();
        if (includingParents && parent != null
                && (position == POSITION_TOP || position == POSITION_BOTTOM)) {
            parent.positionChildAt(position, this /* child */, true /* includingParents */);
        }
    }

    /**
     * When a {@link DisplayArea} is repositioned, it should only be moved among its siblings of the
     * same {@link Type}.
     * For example, when a {@link DisplayArea} of {@link Type#ANY} is repositioned, it shouldn't be
     * moved above any {@link Type#ABOVE_TASKS} siblings, or below any {@link Type#BELOW_TASKS}
     * siblings.
     */
    private int findPositionForChildDisplayArea(int requestPosition, DisplayArea child) {
        if (child.getParent() != this) {
            throw new IllegalArgumentException("positionChildAt: container=" + child.getName()
                    + " is not a child of container=" + getName()
                    + " current parent=" + child.getParent());
        }

        // The max possible position we can insert the child at.
        int maxPosition = findMaxPositionForChildDisplayArea(child);
        // The min possible position we can insert the child at.
        int minPosition = findMinPositionForChildDisplayArea(child);

        return Math.max(Math.min(requestPosition, maxPosition), minPosition);
    }

    private int findMaxPositionForChildDisplayArea(DisplayArea child) {
        final Type childType = Type.typeOf(child);
        for (int i = mChildren.size() - 1; i > 0; i--) {
            if (Type.typeOf(getChildAt(i)) == childType) {
                return i;
            }
        }
        return 0;
    }

    private int findMinPositionForChildDisplayArea(DisplayArea child) {
        final Type childType = Type.typeOf(child);
        for (int i = 0; i < mChildren.size(); i++) {
            if (Type.typeOf(getChildAt(i)) == childType) {
                return i;
            }
        }
        return mChildren.size() - 1;
    }

    @Override
    boolean needsZBoost() {
        // Z Boost should only happen at or below the ActivityStack level.
@@ -423,7 +483,7 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
        }

        static Type typeOf(WindowContainer c) {
            if (c instanceof DisplayArea) {
            if (c.asDisplayArea() != null) {
                return ((DisplayArea) c).mType;
            } else if (c instanceof WindowToken && !(c instanceof ActivityRecord)) {
                return typeOf((WindowToken) c);
+5 −0
Original line number Diff line number Diff line
@@ -63,6 +63,11 @@ public abstract class DisplayAreaPolicy {
     */
    public abstract List<DisplayArea<? extends WindowContainer>> getDisplayAreas(int featureId);

    /**
     * @return the default/fallback {@link TaskDisplayArea} on the display.
     */
    public abstract TaskDisplayArea getDefaultTaskDisplayArea();

    /** Provider for platform-default display area policy. */
    static final class DefaultProvider implements DisplayAreaPolicy.Provider {
        @Override
+25 −3
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ import java.util.function.BiFunction;
 *
 * </pre>
 *
 * // TODO(b/157683117): document more complex scenarios where we need multiple areas per feature.
 * // TODO(b/158713595): document more complex scenarios where we need multiple areas per feature.
 */
class DisplayAreaPolicyBuilder {
    @Nullable private HierarchyBuilder mRootHierarchyBuilder;
@@ -123,8 +123,14 @@ class DisplayAreaPolicyBuilder {
            }

            containsImeContainer = containsImeContainer || hierarchyBuilder.mImeContainer != null;
            containsDefaultTda = containsDefaultTda
                    || containsDefaultTaskDisplayArea(hierarchyBuilder);
            if (containsDefaultTda) {
                if (containsDefaultTaskDisplayArea(hierarchyBuilder)) {
                    throw new IllegalStateException("Only one TaskDisplayArea can have the feature "
                            + "of FEATURE_DEFAULT_TASK_CONTAINER");
                }
            } else {
                containsDefaultTda = containsDefaultTaskDisplayArea(hierarchyBuilder);
            }
        }

        if (!containsImeContainer) {
@@ -506,6 +512,7 @@ class DisplayAreaPolicyBuilder {
    static class Result extends DisplayAreaPolicy {
        final List<RootDisplayArea> mDisplayAreaGroupRoots;
        final BiFunction<WindowToken, Bundle, RootDisplayArea> mSelectRootForWindowFunc;
        private final TaskDisplayArea mDefaultTaskDisplayArea;

        Result(WindowManagerService wmService, RootDisplayArea root,
                List<RootDisplayArea> displayAreaGroupRoots,
@@ -518,6 +525,16 @@ class DisplayAreaPolicyBuilder {
                    // not specified.
                    ? (window, options) -> mRoot
                    : selectRootForWindowFunc;

            // Cache the default TaskDisplayArea for quick access.
            mDefaultTaskDisplayArea = mRoot.getItemFromTaskDisplayAreas(taskDisplayArea ->
                    taskDisplayArea.mFeatureId == FEATURE_DEFAULT_TASK_CONTAINER
                            ? taskDisplayArea
                            : null);
            if (mDefaultTaskDisplayArea == null) {
                throw new IllegalStateException(
                        "No display area with FEATURE_DEFAULT_TASK_CONTAINER");
            }
        }

        @Override
@@ -561,6 +578,11 @@ class DisplayAreaPolicyBuilder {
                }
            }
        }

        @Override
        public TaskDisplayArea getDefaultTaskDisplayArea() {
            return mDefaultTaskDisplayArea;
        }
    }

    static class PendingArea {
+5 −4
Original line number Diff line number Diff line
@@ -2512,8 +2512,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     * or for cases when multi-instance is not supported yet (like Split-screen, PiP or Recents).
     */
    TaskDisplayArea getDefaultTaskDisplayArea() {
        return getItemFromTaskDisplayAreas(taskDisplayArea -> taskDisplayArea,
                false /* traverseTopToBottom */);
        return mDisplayAreaPolicy.getDefaultTaskDisplayArea();
    }

    void positionDisplayAt(int position, boolean includingParents) {
@@ -2545,9 +2544,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     * Find the task whose outside touch area (for resizing) (x, y) falls within.
     * Returns null if the touch doesn't fall into a resizing area.
     */
    @Nullable
    Task findTaskForResizePoint(int x, int y) {
        final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
        return mTmpTaskForResizePointSearchResult.process(getDefaultTaskDisplayArea(), x, y, delta);
        return getItemFromTaskDisplayAreas(taskDisplayArea ->
                mTmpTaskForResizePointSearchResult.process(taskDisplayArea, x, y, delta));
    }

    void updateTouchExcludeRegion() {
@@ -2615,7 +2616,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        // to exclude the docked stack from touch so we need the entire screen area and not just a
        // small portion which the home stack currently is resized to.
        if (task.isActivityTypeHome() && task.isVisible() && task.isResizeable()) {
            mDisplayContent.getBounds(mTmpRect);
            task.getDisplayArea().getBounds(mTmpRect);
        } else {
            task.getDimBounds(mTmpRect);
        }
Loading