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

Commit fe6766e7 authored by Winson Chung's avatar Winson Chung
Browse files

Migrate intercept back pressed to WindowContainerTransaction



- This call only sets state for a particular container and having it
  in a WCT aligns with other container-states we are setting

Bug: 378565144
Flag: EXEMPT bugfix
Test: atest ResizeTasksSyncTest WindowOrganizerTests
Test: atest TaskViewTest TaskViewTransitionsTest BubbleUtilsTest
Test: atest BubbleTaskViewListenerTest BubbleTaskStackListenerTest
Change-Id: Idb4278f19ba8babad8e4412972b869c315795c01
Signed-off-by: default avatarWinson Chung <winsonc@google.com>
parent 1e073d55
Loading
Loading
Loading
Loading
+0 −7
Original line number Original line Diff line number Diff line
@@ -64,13 +64,6 @@ interface ITaskOrganizerController {
     */
     */
    @nullable WindowContainerToken getImeLayeringTarget(int display);
    @nullable WindowContainerToken getImeLayeringTarget(int display);


    /**
     * Requests that the given task organizer is notified when back is pressed on the root activity
     * of one of its controlled tasks.
     */
    void setInterceptBackPressedOnTaskRoot(in WindowContainerToken task,
            boolean interceptBackPressed);

    /**
    /**
     * Restarts the top activity in the given task by killing its process if it is visible.
     * Restarts the top activity in the given task by killing its process if it is visible.
     */
     */
+5 −7
Original line number Original line Diff line number Diff line
@@ -231,17 +231,15 @@ public class TaskOrganizer extends WindowOrganizer {
    }
    }


    /**
    /**
     * Requests that the given task organizer is notified when back is pressed on the root activity
     * Callers should use {@link
     * of one of its controlled tasks.
     * WindowContainerTransaction#setInterceptBackPressedOnTaskRoot(WindowContainerToken, boolean)}.
     */
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
    @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
    public void setInterceptBackPressedOnTaskRoot(@NonNull WindowContainerToken task,
    public void setInterceptBackPressedOnTaskRoot(@NonNull WindowContainerToken task,
            boolean interceptBackPressed) {
            boolean interceptBackPressed) {
        try {
        final WindowContainerTransaction wct = new WindowContainerTransaction();
            mTaskOrganizerController.setInterceptBackPressedOnTaskRoot(task, interceptBackPressed);
        wct.setInterceptBackPressedOnTaskRoot(task, interceptBackPressed);
        } catch (RemoteException e) {
        applyTransaction(wct);
            throw e.rethrowFromSystemServer();
        }
    }
    }




+43 −1
Original line number Original line Diff line number Diff line
@@ -562,6 +562,27 @@ public final class WindowContainerTransaction implements Parcelable {
        return this;
        return this;
    }
    }


    /**
     * Sets whether back press should be intercepted for the root activity of the given task
     * container. If true, then
     * {@link TaskOrganizer#onBackPressedOnTaskRoot(ActivityManager.RunningTaskInfo)} will be
     * called.
     *
     * @param container The window container of the task that the intercept-back state is set on.
     * @param interceptBackPressed {@code true} to allow back to be intercepted for the root
     *                             activity of the task, {@code false} otherwise.
     * @hide
     */
    @NonNull
    public WindowContainerTransaction setInterceptBackPressedOnTaskRoot(
            @NonNull WindowContainerToken container,
            boolean interceptBackPressed) {
        final Change change = getOrCreateChange(container.asBinder());
        change.mChangeMask |= Change.CHANGE_INTERCEPT_BACK_PRESSED;
        change.mInterceptBackPressed = interceptBackPressed;
        return this;
    }

    /*
    /*
     * ===========================================================================================
     * ===========================================================================================
     * Hierarchy updates (create/destroy/reorder/reparent containers)
     * Hierarchy updates (create/destroy/reorder/reparent containers)
@@ -757,7 +778,8 @@ public final class WindowContainerTransaction implements Parcelable {
    public WindowContainerTransaction sendPendingIntent(@Nullable PendingIntent sender,
    public WindowContainerTransaction sendPendingIntent(@Nullable PendingIntent sender,
            @Nullable Intent fillInIntent, @Nullable Bundle options) {
            @Nullable Intent fillInIntent, @Nullable Bundle options) {
        if (DEBUG_START_ACTIVITY) {
        if (DEBUG_START_ACTIVITY) {
            Log.d(Instrumentation.TAG, "WCT.sendPendingIntent: sender=" + sender.getIntent()
            Log.d(Instrumentation.TAG, "WCT.sendPendingIntent: sender="
                    + (sender != null ? sender.getIntent() : "null")
                    + " fillInIntent=" + fillInIntent + " options=" + options, new Throwable());
                    + " fillInIntent=" + fillInIntent + " options=" + options, new Throwable());
        }
        }
        mHierarchyOps.add(new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_PENDING_INTENT)
        mHierarchyOps.add(new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_PENDING_INTENT)
@@ -1457,6 +1479,7 @@ public final class WindowContainerTransaction implements Parcelable {
        public static final int CHANGE_DISABLE_PIP = 1 << 11;
        public static final int CHANGE_DISABLE_PIP = 1 << 11;
        public static final int CHANGE_DISABLE_LAUNCH_ADJACENT = 1 << 12;
        public static final int CHANGE_DISABLE_LAUNCH_ADJACENT = 1 << 12;
        public static final int CHANGE_IS_TASK_MOVE_ALLOWED = 1 << 13;
        public static final int CHANGE_IS_TASK_MOVE_ALLOWED = 1 << 13;
        public static final int CHANGE_INTERCEPT_BACK_PRESSED = 1 << 14;


        @IntDef(flag = true, prefix = { "CHANGE_" }, value = {
        @IntDef(flag = true, prefix = { "CHANGE_" }, value = {
                CHANGE_FOCUSABLE,
                CHANGE_FOCUSABLE,
@@ -1473,6 +1496,7 @@ public final class WindowContainerTransaction implements Parcelable {
                CHANGE_DISABLE_PIP,
                CHANGE_DISABLE_PIP,
                CHANGE_DISABLE_LAUNCH_ADJACENT,
                CHANGE_DISABLE_LAUNCH_ADJACENT,
                CHANGE_IS_TASK_MOVE_ALLOWED,
                CHANGE_IS_TASK_MOVE_ALLOWED,
                CHANGE_INTERCEPT_BACK_PRESSED
        })
        })
        @Retention(RetentionPolicy.SOURCE)
        @Retention(RetentionPolicy.SOURCE)
        public @interface ChangeMask {}
        public @interface ChangeMask {}
@@ -1487,6 +1511,7 @@ public final class WindowContainerTransaction implements Parcelable {
        private boolean mDisablePip = false;
        private boolean mDisablePip = false;
        private boolean mDisableLaunchAdjacent = false;
        private boolean mDisableLaunchAdjacent = false;
        private boolean mIsTaskMoveAllowed = false;
        private boolean mIsTaskMoveAllowed = false;
        private boolean mInterceptBackPressed = false;


        private @ChangeMask int mChangeMask = 0;
        private @ChangeMask int mChangeMask = 0;
        private @ActivityInfo.Config int mConfigSetMask = 0;
        private @ActivityInfo.Config int mConfigSetMask = 0;
@@ -1517,6 +1542,7 @@ public final class WindowContainerTransaction implements Parcelable {
            mDisablePip = in.readBoolean();
            mDisablePip = in.readBoolean();
            mDisableLaunchAdjacent = in.readBoolean();
            mDisableLaunchAdjacent = in.readBoolean();
            mIsTaskMoveAllowed = in.readBoolean();
            mIsTaskMoveAllowed = in.readBoolean();
            mInterceptBackPressed = in.readBoolean();
            mChangeMask = in.readInt();
            mChangeMask = in.readInt();
            mConfigSetMask = in.readInt();
            mConfigSetMask = in.readInt();
            mWindowSetMask = in.readInt();
            mWindowSetMask = in.readInt();
@@ -1578,6 +1604,9 @@ public final class WindowContainerTransaction implements Parcelable {
            if ((other.mChangeMask & CHANGE_IS_TASK_MOVE_ALLOWED) != 0) {
            if ((other.mChangeMask & CHANGE_IS_TASK_MOVE_ALLOWED) != 0) {
                mIsTaskMoveAllowed = other.mIsTaskMoveAllowed;
                mIsTaskMoveAllowed = other.mIsTaskMoveAllowed;
            }
            }
            if ((other.mChangeMask & CHANGE_INTERCEPT_BACK_PRESSED) != 0) {
                mInterceptBackPressed = other.mInterceptBackPressed;
            }
            mChangeMask |= other.mChangeMask;
            mChangeMask |= other.mChangeMask;
            if (other.mActivityWindowingMode >= WINDOWING_MODE_UNDEFINED) {
            if (other.mActivityWindowingMode >= WINDOWING_MODE_UNDEFINED) {
                mActivityWindowingMode = other.mActivityWindowingMode;
                mActivityWindowingMode = other.mActivityWindowingMode;
@@ -1684,6 +1713,15 @@ public final class WindowContainerTransaction implements Parcelable {
            return mDisableLaunchAdjacent;
            return mDisableLaunchAdjacent;
        }
        }


        /** Gets the intercept-back-pressed state. */
        public boolean getInterceptBackPressed() {
            if ((mChangeMask & CHANGE_INTERCEPT_BACK_PRESSED) == 0) {
                throw new RuntimeException("Intercept back pressed not set. "
                        + "Check CHANGE_INTERCEPT_BACK_PRESSED first");
            }
            return mInterceptBackPressed;
        }

        /** Gets whether the config should be sent to the client at the end of the transition. */
        /** Gets whether the config should be sent to the client at the end of the transition. */
        public boolean getConfigAtTransitionEnd() {
        public boolean getConfigAtTransitionEnd() {
            return mConfigAtTransitionEnd;
            return mConfigAtTransitionEnd;
@@ -1783,6 +1821,9 @@ public final class WindowContainerTransaction implements Parcelable {
            if ((mChangeMask & CHANGE_IS_TASK_MOVE_ALLOWED) != 0) {
            if ((mChangeMask & CHANGE_IS_TASK_MOVE_ALLOWED) != 0) {
                sb.append("isTaskMoveAllowed:" + mIsTaskMoveAllowed + ",");
                sb.append("isTaskMoveAllowed:" + mIsTaskMoveAllowed + ",");
            }
            }
            if ((mChangeMask & CHANGE_INTERCEPT_BACK_PRESSED) != 0) {
                sb.append("interceptBack:" + mInterceptBackPressed + ",");
            }
            if (mBoundsChangeTransaction != null) {
            if (mBoundsChangeTransaction != null) {
                sb.append("hasBoundsTransaction,");
                sb.append("hasBoundsTransaction,");
            }
            }
@@ -1815,6 +1856,7 @@ public final class WindowContainerTransaction implements Parcelable {
            dest.writeBoolean(mDisablePip);
            dest.writeBoolean(mDisablePip);
            dest.writeBoolean(mDisableLaunchAdjacent);
            dest.writeBoolean(mDisableLaunchAdjacent);
            dest.writeBoolean(mIsTaskMoveAllowed);
            dest.writeBoolean(mIsTaskMoveAllowed);
            dest.writeBoolean(mInterceptBackPressed);
            dest.writeInt(mChangeMask);
            dest.writeInt(mChangeMask);
            dest.writeInt(mConfigSetMask);
            dest.writeInt(mConfigSetMask);
            dest.writeInt(mWindowSetMask);
            dest.writeInt(mWindowSetMask);
+0 −1
Original line number Original line Diff line number Diff line
@@ -144,7 +144,6 @@ class BubbleTaskStackListenerTest {
            wctCaptor.lastValue
            wctCaptor.lastValue
        }
        }
        verifyExitBubbleTransaction(wct, bubbleTaskToken.asBinder(), captionInsetsOwner)
        verifyExitBubbleTransaction(wct, bubbleTaskToken.asBinder(), captionInsetsOwner)
        verify(taskOrganizer).setInterceptBackPressedOnTaskRoot(task.token, false /* intercept */)
        verify(taskViewTaskController).notifyTaskRemovalStarted(task)
        verify(taskViewTaskController).notifyTaskRemovalStarted(task)
    }
    }


+8 −1
Original line number Original line Diff line number Diff line
@@ -525,7 +525,14 @@ class BubbleTaskViewListenerTest {


        verify(expandedViewManager).removeBubble(eq(b.key), eq(Bubbles.DISMISS_TASK_FINISHED))
        verify(expandedViewManager).removeBubble(eq(b.key), eq(Bubbles.DISMISS_TASK_FINISHED))
        verify(mockTaskView).release()
        verify(mockTaskView).release()
        verify(taskOrganizer).setInterceptBackPressedOnTaskRoot(eq(taskViewTaskToken), eq(false))

        // Capture the WCT used to clean up the task
        val wct = argumentCaptor<WindowContainerTransaction>().let { wctCaptor ->
            verify(taskOrganizer).applyTransaction(wctCaptor.capture())
            wctCaptor.lastValue
        }
        val change = wct.changes[taskViewTaskToken.asBinder()]!!
        assertThat(change.interceptBackPressed).isFalse()
        assertThat(parentView.lastRemovedView).isEqualTo(mockTaskView)
        assertThat(parentView.lastRemovedView).isEqualTo(mockTaskView)
        assertThat(bubbleTaskViewListener.taskView).isNull()
        assertThat(bubbleTaskViewListener.taskView).isNull()
        verify(listenerCallback).onTaskRemovalStarted()
        verify(listenerCallback).onTaskRemovalStarted()
Loading