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

Commit 1a36d94a authored by Maryam Dehaini's avatar Maryam Dehaini
Browse files

Do not hide caption if it is being dragged

Test: drag to desktop while in immersive
Bug: 381280828
Flag: com.android.window.flags.enable_desktop_immersive_drag_bugfix
Change-Id: Ib5d122259db9f7e80207e71a1f5defb7c93e3682
parent b80bae8e
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -1215,7 +1215,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
            if (id == R.id.caption_handle) {
                handleCaptionThroughStatusBar(e, decoration);
                final boolean wasDragging = mIsDragging;
                updateDragStatus(e.getActionMasked());
                updateDragStatus(decoration, e);
                final boolean upOrCancel = e.getActionMasked() == ACTION_UP
                        || e.getActionMasked() == ACTION_CANCEL;
                if (wasDragging && upOrCancel) {
@@ -1231,6 +1231,13 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
            return false;
        }

        private void setIsDragging(
                @Nullable DesktopModeWindowDecoration decor, boolean isDragging) {
            mIsDragging = isDragging;
            if (decor == null) return;
            decor.setIsDragging(isDragging);
        }

        private boolean handleFreeformMotionEvent(DesktopModeWindowDecoration decoration,
                RunningTaskInfo taskInfo, View v, MotionEvent e) {
            final int id = v.getId();
@@ -1250,7 +1257,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                        final Rect initialBounds = mDragPositioningCallback.onDragPositioningStart(
                                0 /* ctrlType */, e.getDisplayId(), e.getRawX(0),
                                e.getRawY(0));
                        updateDragStatus(e.getActionMasked());
                        updateDragStatus(decoration, e);
                        mOnDragStartInitialBounds.set(initialBounds);
                    }
                    // Do not consume input event if a button is touched, otherwise it would
@@ -1277,7 +1284,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                            newTaskBounds);
                    //  Flip mIsDragging only if the bounds actually changed.
                    if (mIsDragging || !newTaskBounds.equals(mOnDragStartInitialBounds)) {
                        updateDragStatus(e.getActionMasked());
                        updateDragStatus(decoration, e);
                    }
                    return true;
                }
@@ -1310,7 +1317,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                        // onClick call that results.
                        return false;
                    } else {
                        updateDragStatus(e.getActionMasked());
                        updateDragStatus(decoration, e);
                        return true;
                    }
                }
@@ -1318,16 +1325,16 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
            return true;
        }

        private void updateDragStatus(int eventAction) {
            switch (eventAction) {
        private void updateDragStatus(DesktopModeWindowDecoration decor, MotionEvent e) {
            switch (e.getActionMasked()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL: {
                    mIsDragging = false;
                    setIsDragging(decor, false /* isDragging */);
                    break;
                }
                case MotionEvent.ACTION_MOVE: {
                    mIsDragging = true;
                    setIsDragging(decor, true /* isDragging */);
                    break;
                }
            }
+16 −4
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    private final WindowDecorCaptionHandleRepository mWindowDecorCaptionHandleRepository;
    private final DesktopUserRepositories mDesktopUserRepositories;
    private boolean mIsRecentsTransitionRunning = false;

    private boolean mIsDragging = false;
    private Runnable mLoadAppInfoRunnable;
    private Runnable mSetAppInfoRunnable;

@@ -513,7 +513,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        updateRelayoutParams(mRelayoutParams, mContext, taskInfo, mSplitScreenController,
                applyStartTransactionOnDraw, shouldSetTaskVisibilityPositionAndCrop,
                mIsStatusBarVisible, mIsKeyguardVisibleAndOccluded, inFullImmersive,
                mDisplayController.getInsetsState(taskInfo.displayId), hasGlobalFocus,
                mIsDragging, mDisplayController.getInsetsState(taskInfo.displayId), hasGlobalFocus,
                displayExclusionRegion, mIsRecentsTransitionRunning,
                mDesktopModeCompatPolicy.shouldExcludeCaptionFromAppBounds(taskInfo));

@@ -911,6 +911,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            boolean isStatusBarVisible,
            boolean isKeyguardVisibleAndOccluded,
            boolean inFullImmersiveMode,
            boolean isDragging,
            @NonNull InsetsState displayInsetsState,
            boolean hasGlobalFocus,
            @NonNull Region displayExclusionRegion,
@@ -933,9 +934,13 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        relayoutParams.mAsyncViewHost = isAppHandle;

        final boolean showCaption;
        if (DesktopModeFlags.ENABLE_FULLY_IMMERSIVE_IN_DESKTOP.isTrue()) {
        if (DesktopModeFlags.ENABLE_DESKTOP_IMMERSIVE_DRAG_BUGFIX.isTrue() && isDragging) {
            // If the task is being dragged, the caption should not be hidden so that it continues
            // receiving input
            showCaption = true;
        } else if (DesktopModeFlags.ENABLE_FULLY_IMMERSIVE_IN_DESKTOP.isTrue()) {
            if (inFullImmersiveMode) {
                showCaption = isStatusBarVisible && !isKeyguardVisibleAndOccluded;
                showCaption = (isStatusBarVisible && !isKeyguardVisibleAndOccluded);
            } else {
                showCaption = taskInfo.isFreeform()
                        || (isStatusBarVisible && !isKeyguardVisibleAndOccluded);
@@ -1798,6 +1803,13 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        mIsRecentsTransitionRunning = isRecentsTransitionRunning;
    }

    /**
     * Declares whether the window decoration is being dragged.
     */
    void setIsDragging(boolean isDragging) {
        mIsDragging = isDragging;
    }

    /**
     * Called when there is a {@link MotionEvent#ACTION_HOVER_EXIT} on the maximize window button.
     */
+41 −0
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
    private static final boolean DEFAULT_IS_STATUSBAR_VISIBLE = true;
    private static final boolean DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED = false;
    private static final boolean DEFAULT_IS_IN_FULL_IMMERSIVE_MODE = false;
    private static final boolean DEFAULT_IS_DRAGGING = false;
    private static final boolean DEFAULT_HAS_GLOBAL_FOCUS = true;
    private static final boolean DEFAULT_SHOULD_IGNORE_CORNER_RADIUS = false;
    private static final boolean DEFAULT_SHOULD_EXCLUDE_CAPTION_FROM_APP_BOUNDS = false;
@@ -415,6 +416,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                DEFAULT_IS_STATUSBAR_VISIBLE,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                DEFAULT_IS_IN_FULL_IMMERSIVE_MODE,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -616,6 +618,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                DEFAULT_IS_STATUSBAR_VISIBLE,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                DEFAULT_IS_IN_FULL_IMMERSIVE_MODE,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -650,6 +653,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                DEFAULT_IS_STATUSBAR_VISIBLE,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                DEFAULT_IS_IN_FULL_IMMERSIVE_MODE,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -728,6 +732,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                DEFAULT_IS_STATUSBAR_VISIBLE,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                /* inFullImmersiveMode */ true,
                DEFAULT_IS_DRAGGING,
                insetsState,
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -755,6 +760,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                DEFAULT_IS_STATUSBAR_VISIBLE,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                /* inFullImmersiveMode */ true,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -781,6 +787,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                /* isStatusBarVisible */ false,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                DEFAULT_IS_IN_FULL_IMMERSIVE_MODE,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -807,6 +814,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                /* isStatusBarVisible */ true,
                /* isKeyguardVisibleAndOccluded */ false,
                DEFAULT_IS_IN_FULL_IMMERSIVE_MODE,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -832,6 +840,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                /* isStatusBarVisible */ false,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                DEFAULT_IS_IN_FULL_IMMERSIVE_MODE,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -857,6 +866,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                DEFAULT_IS_STATUSBAR_VISIBLE,
                /* isKeyguardVisibleAndOccluded */ true,
                DEFAULT_IS_IN_FULL_IMMERSIVE_MODE,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -883,6 +893,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                /* isStatusBarVisible */ true,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                /* inFullImmersiveMode */ true,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -901,6 +912,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                /* isStatusBarVisible */ false,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                /* inFullImmersiveMode */ true,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -910,6 +922,33 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        assertThat(relayoutParams.mIsCaptionVisible).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_IMMERSIVE_DRAG_BUGFIX)
    public void updateRelayoutParams_header_fullyImmersive_captionVisDuringDrag() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(/* visible= */ true);
        taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
        final RelayoutParams relayoutParams = new RelayoutParams();

        DesktopModeWindowDecoration.updateRelayoutParams(
                relayoutParams,
                mTestableContext,
                taskInfo,
                mMockSplitScreenController,
                DEFAULT_APPLY_START_TRANSACTION_ON_DRAW,
                DEFAULT_SHOULD_SET_TASK_POSITIONING_AND_CROP,
                /* isStatusBarVisible */ false,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                /* inFullImmersiveMode */ true,
                /* isDragging */ true,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
                DEFAULT_SHOULD_IGNORE_CORNER_RADIUS,
                DEFAULT_SHOULD_EXCLUDE_CAPTION_FROM_APP_BOUNDS);

        assertThat(relayoutParams.mIsCaptionVisible).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
    public void updateRelayoutParams_header_fullyImmersive_overKeyguard_captionNotVisible() {
@@ -927,6 +966,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                DEFAULT_IS_STATUSBAR_VISIBLE,
                /* isKeyguardVisibleAndOccluded */ true,
                /* inFullImmersiveMode */ true,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,
@@ -1588,6 +1628,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                DEFAULT_IS_STATUSBAR_VISIBLE,
                DEFAULT_IS_KEYGUARD_VISIBLE_AND_OCCLUDED,
                DEFAULT_IS_IN_FULL_IMMERSIVE_MODE,
                DEFAULT_IS_DRAGGING,
                new InsetsState(),
                DEFAULT_HAS_GLOBAL_FOCUS,
                mExclusionRegion,