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

Commit 10971ff2 authored by Jorge Gil's avatar Jorge Gil
Browse files

Disable App Header drag-move and drag-resize in full immersive

Full immersive desktop tasks can't be resized, drag-moved nor resizeable
via double-tap on the header.

Flag: com.android.window.flags.enable_fully_immersive_in_desktop
Bug: 370816278
Test: atest WMShellUnitTests
Change-Id: I983c2ac39a84b9339836d20ac523dbdd9355b736
parent 4ef320df
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -935,14 +935,18 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
            }
            final boolean touchingButton = (id == R.id.close_window || id == R.id.maximize_window
                    || id == R.id.open_menu_button || id == R.id.minimize_window);
            final boolean dragAllowed =
                    !mDesktopRepository.isTaskInFullImmersiveState(taskInfo.taskId);
            switch (e.getActionMasked()) {
                case MotionEvent.ACTION_DOWN: {
                    if (dragAllowed) {
                        mDragPointerId = e.getPointerId(0);
                        final Rect initialBounds = mDragPositioningCallback.onDragPositioningStart(
                                0 /* ctrlType */, e.getRawX(0),
                                e.getRawY(0));
                        updateDragStatus(e.getActionMasked());
                        mOnDragStartInitialBounds.set(initialBounds);
                    }
                    mHasLongClicked = false;
                    // Do not consume input event if a button is touched, otherwise it would
                    // prevent the button's ripple effect from showing.
@@ -951,6 +955,9 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                case ACTION_MOVE: {
                    // If a decor's resize drag zone is active, don't also try to reposition it.
                    if (decoration.isHandlingDragResize()) break;
                    // Dragging the header isn't allowed, so skip the positioning work.
                    if (!dragAllowed) break;

                    decoration.closeMaximizeMenu();
                    if (e.findPointerIndex(mDragPointerId) == -1) {
                        mDragPointerId = e.getPointerId(0);
@@ -1036,6 +1043,10 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                    && action != MotionEvent.ACTION_CANCEL)) {
                return false;
            }
            if (mDesktopRepository.isTaskInFullImmersiveState(mTaskId)) {
                // Disallow double-tap to resize when in full immersive.
                return false;
            }
            onMaximizeOrRestore(mTaskId, "double_tap");
            return true;
        }
+24 −13
Original line number Diff line number Diff line
@@ -517,8 +517,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            closeManageWindowsMenu();
            closeMaximizeMenu();
        }
        updateDragResizeListener(oldDecorationSurface);
        updateMaximizeMenu(startT);
        updateDragResizeListener(oldDecorationSurface, inFullImmersive);
        updateMaximizeMenu(startT, inFullImmersive);
        Trace.endSection(); // DesktopModeWindowDecoration#updateRelayoutParamsAndSurfaces
    }

@@ -571,11 +571,12 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        return mUserContext.getUser();
    }

    private void updateDragResizeListener(SurfaceControl oldDecorationSurface) {
        if (!isDragResizable(mTaskInfo)) {
    private void updateDragResizeListener(SurfaceControl oldDecorationSurface,
            boolean inFullImmersive) {
        if (!isDragResizable(mTaskInfo, inFullImmersive)) {
            if (!mTaskInfo.positionInParent.equals(mPositionInParent)) {
                // We still want to track caption bar's exclusion region on a non-resizeable task.
                updateExclusionRegion();
                updateExclusionRegion(inFullImmersive);
            }
            closeDragResizeListener();
            return;
@@ -609,11 +610,16 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                        getResizeEdgeHandleSize(res), getResizeHandleEdgeInset(res),
                        getFineResizeCornerSize(res), getLargeResizeCornerSize(res)), touchSlop)
                || !mTaskInfo.positionInParent.equals(mPositionInParent)) {
            updateExclusionRegion();
            updateExclusionRegion(inFullImmersive);
        }
    }

    private static boolean isDragResizable(ActivityManager.RunningTaskInfo taskInfo) {
    private static boolean isDragResizable(ActivityManager.RunningTaskInfo taskInfo,
            boolean inFullImmersive) {
        if (inFullImmersive) {
            // Task cannot be resized in full immersive.
            return false;
        }
        if (DesktopModeFlags.ENABLE_WINDOWING_SCALED_RESIZING.isTrue()) {
            return taskInfo.isFreeform();
        }
@@ -677,8 +683,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        mWindowDecorCaptionHandleRepository.notifyCaptionChanged(captionState);
    }

    private void updateMaximizeMenu(SurfaceControl.Transaction startT) {
        if (!isDragResizable(mTaskInfo) || !isMaximizeMenuActive()) {
    private void updateMaximizeMenu(SurfaceControl.Transaction startT, boolean inFullImmersive) {
        if (!isDragResizable(mTaskInfo, inFullImmersive) || !isMaximizeMenuActive()) {
            return;
        }
        if (!mTaskInfo.isVisible()) {
@@ -1546,24 +1552,29 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        mPositionInParent.set(mTaskInfo.positionInParent);
    }

    private void updateExclusionRegion() {
    private void updateExclusionRegion(boolean inFullImmersive) {
        // An outdated position in parent is one reason for this to be called; update it here.
        updatePositionInParent();
        mExclusionRegionListener
                .onExclusionRegionChanged(mTaskInfo.taskId, getGlobalExclusionRegion());
                .onExclusionRegionChanged(mTaskInfo.taskId,
                        getGlobalExclusionRegion(inFullImmersive));
    }

    /**
     * Create a new exclusion region from the corner rects (if resizeable) and caption bounds
     * of this task.
     */
    private Region getGlobalExclusionRegion() {
    private Region getGlobalExclusionRegion(boolean inFullImmersive) {
        Region exclusionRegion;
        if (mDragResizeListener != null && isDragResizable(mTaskInfo)) {
        if (mDragResizeListener != null && isDragResizable(mTaskInfo, inFullImmersive)) {
            exclusionRegion = mDragResizeListener.getCornersRegion();
        } else {
            exclusionRegion = new Region();
        }
        if (inFullImmersive) {
            // Task can't be moved in full immersive, so skip excluding the caption region.
            return exclusionRegion;
        }
        exclusionRegion.union(new Rect(0, 0, mResult.mWidth,
                getCaptionHeight(mTaskInfo.getWindowingMode())));
        exclusionRegion.translate(mPositionInParent.x, mPositionInParent.y);