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

Commit add07a33 authored by Omar Elmekkawy's avatar Omar Elmekkawy
Browse files

[14/n] Add support to break tiling on display rotation.

It's a requirement for decorations to be visible on display rotations, and
tasks might be moved slightly to maintain decoration visibility which
make tiled app look broken.

This CL breaks tiling on any no 180 degree display rotation.


Flag: com.android.window.flags.enable_tile_resizing
Test: on device testing of UI and unit tests
Bug: 376667296
Change-Id: Ie5447ead3c581b8007051c6f28b5bc18c08a3c12
parent a1d05e9e
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -21,10 +21,13 @@ import android.app.ActivityManager.RunningTaskInfo
import android.content.Context
import android.graphics.Rect
import android.util.SparseArray
import android.window.DisplayAreaInfo
import android.window.WindowContainerTransaction
import androidx.core.util.valueIterator
import com.android.internal.annotations.VisibleForTesting
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.common.DisplayChangeController
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.SyncTransactionQueue
import com.android.wm.shell.desktopmode.DesktopRepository
@@ -45,10 +48,16 @@ class DesktopTilingDecorViewModel(
    private val toggleResizeDesktopTaskTransitionHandler: ToggleResizeDesktopTaskTransitionHandler,
    private val returnToDragStartAnimator: ReturnToDragStartAnimator,
    private val taskRepository: DesktopRepository,
) {
) : DisplayChangeController.OnDisplayChangingListener {
    @VisibleForTesting
    var tilingTransitionHandlerByDisplayId = SparseArray<DesktopTilingWindowDecoration>()

    init {
        // TODO(b/374309287): Move this interface implementation to
        // [DesktopModeWindowDecorViewModel] when the migration is done.
        displayController.addDisplayChangingController(this)
    }

    fun snapToHalfScreen(
        taskInfo: ActivityManager.RunningTaskInfo,
        desktopModeWindowDecoration: DesktopModeWindowDecoration,
@@ -102,7 +111,20 @@ class DesktopTilingDecorViewModel(

    fun onUserChange() {
        for (tilingHandler in tilingTransitionHandlerByDisplayId.valueIterator()) {
            tilingHandler.onUserChange()
            tilingHandler.resetTilingSession()
        }
    }

    override fun onDisplayChange(
        displayId: Int,
        fromRotation: Int,
        toRotation: Int,
        newDisplayAreaInfo: DisplayAreaInfo?,
        t: WindowContainerTransaction?,
    ) {
        // Exit if the rotation hasn't changed or is changed by 180 degrees. [fromRotation] and
        // [toRotation] can be one of the [@Surface.Rotation] values.
        if ((fromRotation % 2 == toRotation % 2)) return
        tilingTransitionHandlerByDisplayId.get(displayId)?.resetTilingSession()
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -483,7 +483,7 @@ class DesktopTilingWindowDecoration(
        }
    }

    fun onUserChange() {
    fun resetTilingSession() {
        if (leftTaskResizingHelper != null) {
            removeTask(leftTaskResizingHelper, taskVanished = false, shouldDelayUpdate = true)
            leftTaskResizingHelper = null
+25 −2
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
@@ -145,7 +146,7 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {
    }

    @Test
    fun userChange_starting_allTilingSessionsShouldBeDestroyed() {
    fun onUserChange_allTilingSessionsShouldBeDestroyed() {
        desktopTilingDecorViewModel.tilingTransitionHandlerByDisplayId.put(
            1,
            desktopTilingDecoration,
@@ -157,7 +158,29 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {

        desktopTilingDecorViewModel.onUserChange()

        verify(desktopTilingDecoration, times(2)).onUserChange()
        verify(desktopTilingDecoration, times(2)).resetTilingSession()
    }

    @Test
    fun displayOrientationChange_tilingForDisplayShouldBeDestroyed() {
        desktopTilingDecorViewModel.tilingTransitionHandlerByDisplayId.put(
            1,
            desktopTilingDecoration,
        )
        desktopTilingDecorViewModel.tilingTransitionHandlerByDisplayId.put(
            2,
            desktopTilingDecoration,
        )

        desktopTilingDecorViewModel.onDisplayChange(1, 1, 2, null, null)

        verify(desktopTilingDecoration, times(1)).resetTilingSession()
        verify(displayControllerMock, times(1))
            .addDisplayChangingController(eq(desktopTilingDecorViewModel))

        desktopTilingDecorViewModel.onDisplayChange(1, 1, 3, null, null)
        // No extra calls after 180 degree change.
        verify(desktopTilingDecoration, times(1)).resetTilingSession()
    }

    companion object {
+1 −1
Original line number Diff line number Diff line
@@ -475,7 +475,7 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
        tilingDecoration.rightTaskResizingHelper = tiledTaskHelper
        tilingDecoration.desktopTilingDividerWindowManager = desktopTilingDividerWindowManager

        tilingDecoration.onUserChange()
        tilingDecoration.resetTilingSession()

        assertThat(tilingDecoration.leftTaskResizingHelper).isNull()
        assertThat(tilingDecoration.rightTaskResizingHelper).isNull()