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

Commit 9f45c24c authored by Omar Elmekkawy's avatar Omar Elmekkawy Committed by Android (Google) Code Review
Browse files

Merge "Add support for tiling session persistence." into main

parents c22e54f2 499d1ded
Loading
Loading
Loading
Loading
+34 −1
Original line number Original line Diff line number Diff line
@@ -633,6 +633,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,


        if (decoration == null) {
        if (decoration == null) {
            createWindowDecoration(taskInfo, taskSurface, startT, finishT);
            createWindowDecoration(taskInfo, taskSurface, startT, finishT);
            initializeTiling(taskInfo);
        } else {
        } else {
            decoration.relayout(taskInfo, startT, finishT, false /* applyStartTransactionOnDraw */,
            decoration.relayout(taskInfo, startT, finishT, false /* applyStartTransactionOnDraw */,
                    false /* shouldSetTaskPositionAndCrop */,
                    false /* shouldSetTaskPositionAndCrop */,
@@ -640,6 +641,30 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
        }
        }
    }
    }


    private void initializeTiling(RunningTaskInfo taskInfo) {
        DesktopRepository taskRepository = mDesktopUserRepositories.getCurrent();
        Integer leftTiledTaskId = taskRepository.getLeftTiledTask(taskInfo.displayId);
        Integer rightTiledTaskId = taskRepository.getRightTiledTask(taskInfo.displayId);
        boolean tilingAndPersistenceEnabled = DesktopModeFlags.ENABLE_TILE_RESIZING.isTrue()
                && DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PERSISTENCE.isTrue();
        if (leftTiledTaskId != null && leftTiledTaskId == taskInfo.taskId
                && tilingAndPersistenceEnabled) {
            snapPersistedTaskToHalfScreen(
                    taskInfo,
                    taskInfo.configuration.windowConfiguration.getBounds(),
                    SnapPosition.LEFT
            );
        }
        if (rightTiledTaskId != null && rightTiledTaskId == taskInfo.taskId
                && tilingAndPersistenceEnabled) {
            snapPersistedTaskToHalfScreen(
                    taskInfo,
                    taskInfo.configuration.windowConfiguration.getBounds(),
                    SnapPosition.RIGHT
            );
        }
    }

    @Override
    @Override
    public void onTaskClosing(
    public void onTaskClosing(
            RunningTaskInfo taskInfo,
            RunningTaskInfo taskInfo,
@@ -950,7 +975,15 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
    public boolean snapToHalfScreen(@NonNull RunningTaskInfo taskInfo,
    public boolean snapToHalfScreen(@NonNull RunningTaskInfo taskInfo,
            @NonNull Rect currentDragBounds, @NonNull SnapPosition position) {
            @NonNull Rect currentDragBounds, @NonNull SnapPosition position) {
        return mDesktopTilingDecorViewModel.snapToHalfScreen(taskInfo,
        return mDesktopTilingDecorViewModel.snapToHalfScreen(taskInfo,
                mWindowDecorByTaskId.get(taskInfo.taskId), position, currentDragBounds);
                mWindowDecorByTaskId.get(taskInfo.taskId), position, currentDragBounds, null);
    }

    @Override
    public boolean snapPersistedTaskToHalfScreen(@NotNull RunningTaskInfo taskInfo,
            @NotNull Rect currentDragBounds, @NotNull SnapPosition position) {
        return mDesktopTilingDecorViewModel.snapToHalfScreen(taskInfo,
                mWindowDecorByTaskId.get(taskInfo.taskId), position, currentDragBounds,
                currentDragBounds);
    }
    }


    @Override
    @Override
+8 −4
Original line number Original line Diff line number Diff line
@@ -80,7 +80,8 @@ class DesktopTilingDecorViewModel(
        taskInfo: ActivityManager.RunningTaskInfo,
        taskInfo: ActivityManager.RunningTaskInfo,
        desktopModeWindowDecoration: DesktopModeWindowDecoration,
        desktopModeWindowDecoration: DesktopModeWindowDecoration,
        position: DesktopTasksController.SnapPosition,
        position: DesktopTasksController.SnapPosition,
        destinationBounds: Rect,
        currentBounds: Rect,
        destinationBounds: Rect? = null,
    ): Boolean {
    ): Boolean {
        val displayId = taskInfo.displayId
        val displayId = taskInfo.displayId
        val handler =
        val handler =
@@ -110,12 +111,15 @@ class DesktopTilingDecorViewModel(
                    newHandler
                    newHandler
                }
                }
        transitions.registerObserver(handler)
        transitions.registerObserver(handler)
        return handler.onAppTiled(
        return destinationBounds?.let { handler.onAppTiled(
            taskInfo,
            taskInfo,
            desktopModeWindowDecoration,
            desktopModeWindowDecoration,
            position,
            position,
            destinationBounds,
            currentBounds, it)} ?: handler.onAppTiled(
        )
            taskInfo = taskInfo,
            desktopModeWindowDecoration = desktopModeWindowDecoration,
            position = position,
            currentBounds = currentBounds)
    }
    }


    fun removeTaskIfTiled(displayId: Int, taskId: Int) {
    fun removeTaskIfTiled(displayId: Int, taskId: Int) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -119,8 +119,8 @@ class DesktopTilingWindowDecoration(
        desktopModeWindowDecoration: DesktopModeWindowDecoration,
        desktopModeWindowDecoration: DesktopModeWindowDecoration,
        position: SnapPosition,
        position: SnapPosition,
        currentBounds: Rect,
        currentBounds: Rect,
        destinationBounds: Rect = getSnapBounds(position)
    ): Boolean {
    ): Boolean {
        val destinationBounds = getSnapBounds(position)
        val resizeMetadata =
        val resizeMetadata =
            AppResizingHelper(
            AppResizingHelper(
                taskInfo,
                taskInfo,
+7 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,13 @@ interface SnapEventHandler {
        position: SnapPosition,
        position: SnapPosition,
    ): Boolean
    ): Boolean


    /** Snaps an app to half the screen for tiling after a persistence trigger. */
    fun snapPersistedTaskToHalfScreen(
        taskInfo: RunningTaskInfo,
        currentDragBounds: Rect,
        position: SnapPosition,
    ): Boolean

    /** Removes a task from tiling if it's tiled, for example on task exiting. */
    /** Removes a task from tiling if it's tiled, for example on task exiting. */
    fun removeTaskIfTiled(displayId: Int, taskId: Int)
    fun removeTaskIfTiled(displayId: Int, taskId: Int)


+25 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ import com.android.wm.shell.desktopmode.DesktopImmersiveController
import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.InputMethod
import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.InputMethod
import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.MinimizeReason
import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.MinimizeReason
import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.ResizeTrigger
import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.ResizeTrigger
import com.android.wm.shell.desktopmode.DesktopTasksController
import com.android.wm.shell.desktopmode.DesktopTasksController.SnapPosition
import com.android.wm.shell.desktopmode.DesktopTasksController.SnapPosition
import com.android.wm.shell.desktopmode.common.ToggleTaskSizeInteraction
import com.android.wm.shell.desktopmode.common.ToggleTaskSizeInteraction
import com.android.wm.shell.recents.RecentsTransitionStateListener
import com.android.wm.shell.recents.RecentsTransitionStateListener
@@ -94,6 +95,8 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.mockito.kotlin.whenever
import org.mockito.quality.Strictness
import org.mockito.quality.Strictness
import org.mockito.kotlin.isNotNull
import org.mockito.kotlin.isNull


/**
/**
 * Tests of [DesktopModeWindowDecorViewModel]
 * Tests of [DesktopModeWindowDecorViewModel]
@@ -192,6 +195,28 @@ class DesktopModeWindowDecorViewModelTests : DesktopModeWindowDecorViewModelTest
        verify(mockInputMonitor, times(1)).dispose()
        verify(mockInputMonitor, times(1)).dispose()
    }
    }


    @Test
    fun snapToHalfScreen_callsCorrectPersistenceFunction() {
        val task = createTask(displayId = DEFAULT_DISPLAY, windowingMode = WINDOWING_MODE_FREEFORM)
        desktopModeWindowDecorViewModel.snapToHalfScreen(
            task,
            INITIAL_BOUNDS,
            DesktopTasksController.SnapPosition.LEFT,
        )

        verify(mockTilingWindowDecoration, times(1))
            .snapToHalfScreen(any(), anyOrNull(), any(), any(), isNull())

        desktopModeWindowDecorViewModel.snapPersistedTaskToHalfScreen(
            task,
            INITIAL_BOUNDS,
            DesktopTasksController.SnapPosition.LEFT,
        )

        verify(mockTilingWindowDecoration, times(1))
            .snapToHalfScreen(any(), anyOrNull(), any(), any(), isNotNull())
    }

    @Test
    @Test
    fun testBackEventHasRightDisplayId() {
    fun testBackEventHasRightDisplayId() {
        val secondaryDisplay = createVirtualDisplay() ?: return
        val secondaryDisplay = createVirtualDisplay() ?: return