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

Commit c04c4c10 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

WindowContainerTransaction for setting adjacent roots

Ability to specify that 2 root tasks are adjcent there by allowing them
to occlude their parent. Similar to how the legacy primary/secondary
split windowing modes are used to occlude their parent.

Also, occlude parent if a child in multi-window mode as a matching
bounds.

Bug: 177166639
Test: AppConfigurationTests#testSplitscreenPortraitAppOrientationRequests
Change-Id: I7d54bfa188700a76b0bca911d2011123c21553ad
parent 9e5c68e7
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -727,6 +727,11 @@ package android.graphics {
    method @AnyThread @NonNull public static android.graphics.ImageDecoder.Source createSource(android.content.res.Resources, java.io.InputStream, int);
  }

  public final class Rect implements android.os.Parcelable {
    method public void splitHorizontally(@NonNull android.graphics.Rect...);
    method public void splitVertically(@NonNull android.graphics.Rect...);
  }

}

package android.graphics.drawable {
@@ -2560,6 +2565,7 @@ package android.window {
    method @NonNull public android.window.WindowContainerTransaction reparentTasks(@Nullable android.window.WindowContainerToken, @Nullable android.window.WindowContainerToken, @Nullable int[], @Nullable int[], boolean);
    method @NonNull public android.window.WindowContainerTransaction scheduleFinishEnterPip(@NonNull android.window.WindowContainerToken, @NonNull android.graphics.Rect);
    method @NonNull public android.window.WindowContainerTransaction setActivityWindowingMode(@NonNull android.window.WindowContainerToken, int);
    method @NonNull public android.window.WindowContainerTransaction setAdjacentRoots(@NonNull android.window.WindowContainerToken, @NonNull android.window.WindowContainerToken);
    method @NonNull public android.window.WindowContainerTransaction setAppBounds(@NonNull android.window.WindowContainerToken, @NonNull android.graphics.Rect);
    method @NonNull public android.window.WindowContainerTransaction setBounds(@NonNull android.window.WindowContainerToken, @NonNull android.graphics.Rect);
    method @NonNull public android.window.WindowContainerTransaction setBoundsChangeTransaction(@NonNull android.window.WindowContainerToken, @NonNull android.view.SurfaceControl.Transaction);
+29 −0
Original line number Diff line number Diff line
@@ -322,6 +322,21 @@ public final class WindowContainerTransaction implements Parcelable {
        return this;
    }

    /**
     * Sets to containers adjacent to each other. Containers below two visible adjacent roots will
     * be made invisible. This currently only applies to Task containers created by organizer.
     * @param root1 the first root.
     * @param root2 the second root.
     */
    @NonNull
    public WindowContainerTransaction setAdjacentRoots(
            @NonNull WindowContainerToken root1, @NonNull WindowContainerToken root2) {
        mHierarchyOps.add(HierarchyOp.createForAdjacentRoots(
                root1.asBinder(),
                root2.asBinder()));
        return this;
    }

    /**
     * Merges another WCT into this one.
     * @param transfer When true, this will transfer everything from other potentially leaving
@@ -642,6 +657,7 @@ public final class WindowContainerTransaction implements Parcelable {
        public static final int HIERARCHY_OP_TYPE_REORDER = 1;
        public static final int HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT = 2;
        public static final int HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT = 3;
        public static final int HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS = 4;

        private final int mType;

@@ -680,6 +696,11 @@ public final class WindowContainerTransaction implements Parcelable {
                    container, null, windowingModes, activityTypes, false);
        }

        public static HierarchyOp createForAdjacentRoots(IBinder root1, IBinder root2) {
            return new HierarchyOp(HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS,
                    root1, root2, null, null, false);
        }

        private HierarchyOp(int type, @NonNull IBinder container, @Nullable IBinder reparent,
                int[] windowingModes, int[] activityTypes, boolean toTop) {
            mType = type;
@@ -728,6 +749,11 @@ public final class WindowContainerTransaction implements Parcelable {
            return mContainer;
        }

        @NonNull
        public IBinder getAdjacentRoot() {
            return mReparent;
        }

        public boolean getToTop() {
            return mToTop;
        }
@@ -756,6 +782,9 @@ public final class WindowContainerTransaction implements Parcelable {
                            + mReparent + "}";
                case HIERARCHY_OP_TYPE_REORDER:
                    return "{reorder: " + mContainer + " to " + (mToTop ? "top" : "bottom") + "}";
                case HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS:
                    return "{SetAdjacentRoot: container=" + mContainer
                            + " adjacentRoot=" + mReparent + "}";
                default:
                    return "{mType=" + mType + " container=" + mContainer + " reparent=" + mReparent
                            + " mToTop=" + mToTop + " mWindowingMode=" + mWindowingModes
+35 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.graphics;
import android.annotation.CheckResult;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.Parcelable;
@@ -701,6 +702,40 @@ public final class Rect implements Parcelable {
        }
    }

    /**
     * Splits this Rect into small rects of the same width.
     * @hide
     */
    @TestApi
    public void splitVertically(@NonNull Rect ...splits) {
        final int count = splits.length;
        final int splitWidth = width() / count;
        for (int i = 0; i < count; i++) {
            final Rect split = splits[i];
            split.left = left + (splitWidth * i);
            split.top = top;
            split.right = split.left + splitWidth;
            split.bottom = bottom;
        }
    }

    /**
     * Splits this Rect into small rects of the same height.
     * @hide
     */
    @TestApi
    public void splitHorizontally(@NonNull Rect ...outSplits) {
        final int count = outSplits.length;
        final int splitHeight = height() / count;
        for (int i = 0; i < count; i++) {
            final Rect split = outSplits[i];
            split.left = left;
            split.top = top + (splitHeight * i);
            split.right = right;
            split.bottom = split.top + splitHeight;
        }
    }

    /**
     * Parcelable interface methods
     */
+10 −0
Original line number Diff line number Diff line
@@ -142,6 +142,15 @@ class StageCoordinator implements SplitLayout.LayoutChangeListener,
        mTaskOrganizer.applyTransaction(wct);
    }

    private void onStageRootTaskAppeared(StageListenerImpl stageListener) {
        if (mMainStageListener.mHasRootTask && mSideStageListener.mHasRootTask) {
            final WindowContainerTransaction wct = new WindowContainerTransaction();
            // Make the stages adjacent to each other so they occlude what's behind them.
            wct.setAdjacentRoots(mMainStage.mRootTaskInfo.token, mSideStage.mRootTaskInfo.token);
            mTaskOrganizer.applyTransaction(wct);
        }
    }

    private void onStageRootTaskVanished(StageListenerImpl stageListener) {
        if (stageListener == mMainStageListener || stageListener == mSideStageListener) {
            final WindowContainerTransaction wct = new WindowContainerTransaction();
@@ -357,6 +366,7 @@ class StageCoordinator implements SplitLayout.LayoutChangeListener,
        @Override
        public void onRootTaskAppeared() {
            mHasRootTask = true;
            StageCoordinator.this.onStageRootTaskAppeared(this);
        }

        @Override
+1 −1
Original line number Diff line number Diff line
@@ -70,9 +70,9 @@ class StageTaskListener implements ShellTaskOrganizer.TaskListener {
    @CallSuper
    public void onTaskAppeared(ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash) {
        if (!taskInfo.hasParentTask()) {
            mCallbacks.onRootTaskAppeared();
            mRootLeash = leash;
            mRootTaskInfo = taskInfo;
            mCallbacks.onRootTaskAppeared();
        } else if (taskInfo.parentTaskId == mRootTaskInfo.taskId) {
            mChildrenLeashes.put(taskInfo.taskId, leash);
            mChildrenTaskInfo.put(taskInfo.taskId, taskInfo);
Loading