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

Commit f0644922 authored by Ats Jenk's avatar Ats Jenk
Browse files

Only allow dragging fullscreen to bubble

When bubble to fullscreen flag is on, we should only be able to drag a
fullscreen task to bubble.
Put logic for dragging a split task to bubble behind bubble anything
flag.

Bug: 404905102
Test: atest DesktopModeVisualIndicatorTest
Test: enable bubble to fullscreen flag, check that split screen can't be
  dragged to bubble
Test: enable bubble anything flag, check that when dragging a split
  task, the bubble indicator is shown
Flag: com.android.wm.shell.enable_bubble_to_fullscreen

Change-Id: I5dd747d87934a9336656e7555215709a285ce696
parent 34f9f07e
Loading
Loading
Loading
Loading
+53 −23
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ import com.android.wm.shell.shared.bubbles.BubbleAnythingFlagHelper;
import com.android.wm.shell.shared.bubbles.BubbleDropTargetBoundsProvider;
import com.android.wm.shell.windowdecor.tiling.SnapEventHandler;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@@ -307,7 +307,8 @@ public class DesktopModeVisualIndicator {
        if (splitRightRegion.contains(x, y)) {
            result = IndicatorType.TO_SPLIT_RIGHT_INDICATOR;
        }
        if (BubbleAnythingFlagHelper.enableBubbleToFullscreen()) {
        if (BubbleAnythingFlagHelper.enableBubbleToFullscreen()
                && mDragStartState == DragStartState.FROM_FULLSCREEN) {
            if (calculateBubbleLeftRegion(layout).contains(x, y)) {
                result = IndicatorType.TO_BUBBLE_LEFT_INDICATOR;
            } else if (calculateBubbleRightRegion(layout).contains(x, y)) {
@@ -415,30 +416,59 @@ public class DesktopModeVisualIndicator {

    private List<Pair<Rect, IndicatorType>> initSmallTabletRegions(DisplayLayout layout,
            boolean isLeftRightSplit) {
        boolean dragFromFullscreen = mDragStartState == DragStartState.FROM_FULLSCREEN;
        boolean dragFromSplit = mDragStartState == DragStartState.FROM_SPLIT;
        if (isLeftRightSplit && (dragFromFullscreen || dragFromSplit)) {
        return switch (mDragStartState) {
            case DragStartState.FROM_FULLSCREEN -> initSmallTabletRegionsFromFullscreen(layout,
                    isLeftRightSplit);
            case DragStartState.FROM_SPLIT -> initSmallTabletRegionsFromSplit(layout,
                    isLeftRightSplit);
            default -> Collections.emptyList();
        };
    }

    private List<Pair<Rect, IndicatorType>> initSmallTabletRegionsFromFullscreen(
            DisplayLayout layout, boolean isLeftRightSplit) {

        List<Pair<Rect, IndicatorType>> result = new ArrayList<>();
        if (BubbleAnythingFlagHelper.enableBubbleToFullscreen()) {
            result.add(new Pair<>(calculateBubbleLeftRegion(layout), TO_BUBBLE_LEFT_INDICATOR));
            result.add(new Pair<>(calculateBubbleRightRegion(layout), TO_BUBBLE_RIGHT_INDICATOR));
        }

        if (isLeftRightSplit) {
            int splitRegionWidth = mContext.getResources().getDimensionPixelSize(
                    com.android.wm.shell.shared.R.dimen.drag_zone_h_split_from_app_width_fold);
            return Arrays.asList(
                    new Pair<>(calculateBubbleLeftRegion(layout), TO_BUBBLE_LEFT_INDICATOR),
                    new Pair<>(calculateBubbleRightRegion(layout), TO_BUBBLE_RIGHT_INDICATOR),
                    new Pair<>(calculateSplitLeftRegion(layout, splitRegionWidth,
                            /* captionHeight= */ 0), TO_SPLIT_LEFT_INDICATOR),
                    new Pair<>(calculateSplitRightRegion(layout, splitRegionWidth,
                            /* captionHeight= */ 0), TO_SPLIT_RIGHT_INDICATOR),
                    new Pair<>(new Rect(), TO_FULLSCREEN_INDICATOR) // default to fullscreen
            );
            result.add(new Pair<>(calculateSplitLeftRegion(layout, splitRegionWidth,
                    /* captionHeight= */ 0), TO_SPLIT_LEFT_INDICATOR));
            result.add(new Pair<>(calculateSplitRightRegion(layout, splitRegionWidth,
                    /* captionHeight= */ 0), TO_SPLIT_RIGHT_INDICATOR));
        }
        if (dragFromFullscreen) {
            // If left/right split is not available, we can only drag fullscreen tasks
        // TODO(b/401352409): add support for top/bottom split zones
            return Arrays.asList(
                    new Pair<>(calculateBubbleLeftRegion(layout), TO_BUBBLE_LEFT_INDICATOR),
                    new Pair<>(calculateBubbleRightRegion(layout), TO_BUBBLE_RIGHT_INDICATOR),
                    new Pair<>(new Rect(), TO_FULLSCREEN_INDICATOR) // default to fullscreen
            );
        // default to fullscreen
        result.add(new Pair<>(new Rect(), TO_FULLSCREEN_INDICATOR));
        return result;
    }

    private List<Pair<Rect, IndicatorType>> initSmallTabletRegionsFromSplit(DisplayLayout layout,
            boolean isLeftRightSplit) {
        if (!isLeftRightSplit) {
            // Dragging a top/bottom split is not supported on small tablets
            return Collections.emptyList();
        }

        List<Pair<Rect, IndicatorType>> result = new ArrayList<>();
        if (BubbleAnythingFlagHelper.enableBubbleAnything()) {
            result.add(new Pair<>(calculateBubbleLeftRegion(layout), TO_BUBBLE_LEFT_INDICATOR));
            result.add(new Pair<>(calculateBubbleRightRegion(layout), TO_BUBBLE_RIGHT_INDICATOR));
        }

        int splitRegionWidth = mContext.getResources().getDimensionPixelSize(
                com.android.wm.shell.shared.R.dimen.drag_zone_h_split_from_app_width_fold);
        result.add(new Pair<>(calculateSplitLeftRegion(layout, splitRegionWidth,
                /* captionHeight= */ 0), TO_SPLIT_LEFT_INDICATOR));
        result.add(new Pair<>(calculateSplitRightRegion(layout, splitRegionWidth,
                /* captionHeight= */ 0), TO_SPLIT_RIGHT_INDICATOR));
        // default to fullscreen
        result.add(new Pair<>(new Rect(), TO_FULLSCREEN_INDICATOR));
        return result;
    }
}
+56 −4
Original line number Diff line number Diff line
@@ -283,14 +283,32 @@ class DesktopModeVisualIndicatorTest : ShellTestCase() {
        com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_TO_FULLSCREEN,
        com.android.wm.shell.Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE,
    )
    fun testDefaultIndicators_bubblesEnabled() {
    fun testDefaultIndicators_enableBubbleToFullscreen() {
        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.FROM_FULLSCREEN)
        var result = visualIndicator.updateIndicatorType(PointF(10f, 1500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_BUBBLE_LEFT_INDICATOR)
        result = visualIndicator.updateIndicatorType(PointF(2300f, 1500f))
        result = visualIndicator.updateIndicatorType(PointF(2390f, 1500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_BUBBLE_RIGHT_INDICATOR)

        // Check that bubble zones are not available from split
        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.FROM_SPLIT)
        result = visualIndicator.updateIndicatorType(PointF(10f, 1500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_SPLIT_LEFT_INDICATOR)
        result = visualIndicator.updateIndicatorType(PointF(2390f, 1500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_SPLIT_RIGHT_INDICATOR)

        // Check that bubble zones are not available from desktop
        createVisualIndicator(DesktopModeVisualIndicator.DragStartState.FROM_FREEFORM)
        result = visualIndicator.updateIndicatorType(PointF(10f, 1500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_SPLIT_LEFT_INDICATOR)
        result = visualIndicator.updateIndicatorType(PointF(2390f, 1500f))
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_SPLIT_RIGHT_INDICATOR)
    }

    @Test
@@ -298,7 +316,7 @@ class DesktopModeVisualIndicatorTest : ShellTestCase() {
        com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_TO_FULLSCREEN,
        com.android.wm.shell.Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE,
    )
    fun testDefaultIndicators_foldable_leftRightSplit() {
    fun testDefaultIndicators_foldable_enableBubbleToFullscreen_dragFromFullscreen() {
        setUpFoldable()

        createVisualIndicator(
@@ -325,13 +343,47 @@ class DesktopModeVisualIndicatorTest : ShellTestCase() {
        result = visualIndicator.updateIndicatorType(foldRightBottom())
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_BUBBLE_RIGHT_INDICATOR)
    }

    @Test
    @EnableFlags(
        com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_TO_FULLSCREEN,
        com.android.wm.shell.Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE,
    )
    @DisableFlags(com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_ANYTHING)
    fun testDefaultIndicators_foldable_enableBubbleToFullscreen_dragFromSplit() {
        setUpFoldable()

        createVisualIndicator(
            DesktopModeVisualIndicator.DragStartState.FROM_SPLIT,
            isSmallTablet = true,
            isLeftRightSplit = true,
        )
        result = visualIndicator.updateIndicatorType(foldCenter())
        var result = visualIndicator.updateIndicatorType(foldCenter())
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_FULLSCREEN_INDICATOR)

        // Check that bubbles are not available from split
        result = visualIndicator.updateIndicatorType(foldLeftBottom())
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_SPLIT_LEFT_INDICATOR)

        result = visualIndicator.updateIndicatorType(foldRightBottom())
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_SPLIT_RIGHT_INDICATOR)
    }

    @Test
    @EnableFlags(com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_ANYTHING)
    fun testDefaultIndicators_foldable_enableBubbleAnything_dragFromSplit() {
        setUpFoldable()

        createVisualIndicator(
            DesktopModeVisualIndicator.DragStartState.FROM_SPLIT,
            isSmallTablet = true,
            isLeftRightSplit = true,
        )
        var result = visualIndicator.updateIndicatorType(foldCenter())
        assertThat(result)
            .isEqualTo(DesktopModeVisualIndicator.IndicatorType.TO_FULLSCREEN_INDICATOR)