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

Commit 4fc05c89 authored by Omar Elmekkawy's avatar Omar Elmekkawy
Browse files

[9/n] Adding user change support for tiling

Destroying tiling session on user changing.

Flag: com.android.window.flags.enable_tile_resizing
Test: new unit tests and on device testing
Bug: 375430719

Change-Id: I332d995d8bd4893c90974fd616f6461cb58f23e3
parent 6bdd4046
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2123,6 +2123,7 @@ class DesktopTasksController(
    // TODO(b/366397912): Support full multi-user mode in Windowing.
    override fun onUserChanged(newUserId: Int, userContext: Context) {
        userId = newUserId
        desktopTilingDecorViewModel.onUserChange()
    }

    /** Called when a task's info changes. */
+6 −0
Original line number Diff line number Diff line
@@ -99,4 +99,10 @@ class DesktopTilingDecorViewModel(
            tilingHandler.onOverviewAnimationStateChange(isRunning)
        }
    }

    fun onUserChange() {
        for (tilingHandler in tilingTransitionHandlerByDisplayId.valueIterator()) {
            tilingHandler.onUserChange()
        }
    }
}
+16 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.view.WindowManager.TRANSIT_TO_FRONT
import android.window.TransitionInfo
import android.window.TransitionRequestInfo
import android.window.WindowContainerTransaction
import com.android.internal.annotations.VisibleForTesting
import com.android.launcher3.icons.BaseIconFactory
import com.android.launcher3.icons.BaseIconFactory.MODE_DEFAULT
import com.android.launcher3.icons.IconProvider
@@ -57,7 +58,7 @@ import com.android.wm.shell.windowdecor.extension.isFullscreen
import java.util.function.Supplier

class DesktopTilingWindowDecoration(
    private val context: Context,
    private var context: Context,
    private val syncQueue: SyncTransactionQueue,
    private val displayController: DisplayController,
    private val displayId: Int,
@@ -82,7 +83,8 @@ class DesktopTilingWindowDecoration(
    var leftTaskResizingHelper: AppResizingHelper? = null
    var rightTaskResizingHelper: AppResizingHelper? = null
    private var isTilingManagerInitialised = false
    private var desktopTilingDividerWindowManager: DesktopTilingDividerWindowManager? = null
    @VisibleForTesting
    var desktopTilingDividerWindowManager: DesktopTilingDividerWindowManager? = null
    private lateinit var dividerBounds: Rect
    private var isResizing = false
    private var isTilingFocused = false
@@ -476,6 +478,18 @@ class DesktopTilingWindowDecoration(
        }
    }

    fun onUserChange() {
        if (leftTaskResizingHelper != null) {
            removeTask(leftTaskResizingHelper, taskVanished = false, shouldDelayUpdate = true)
            leftTaskResizingHelper = null
        }
        if (rightTaskResizingHelper != null) {
            removeTask(rightTaskResizingHelper, taskVanished = false, shouldDelayUpdate = true)
            rightTaskResizingHelper = null
        }
        tearDownTiling()
    }

    private fun removeTask(
        appResizingHelper: AppResizingHelper?,
        taskVanished: Boolean = false,
+16 −3
Original line number Diff line number Diff line
@@ -102,7 +102,6 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {

    @Test
    fun removeTile_shouldCreate_newTilingDecoration() {

        val task1 = createFreeformTask()
        task1.displayId = 1
        desktopTilingDecorViewModel.tilingTransitionHandlerByDisplayId.put(
@@ -130,8 +129,6 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {

    @Test
    fun overviewAnimation_starting_ShouldNotifyAllDecorations() {
        val task1 = createFreeformTask()
        task1.displayId = 1
        desktopTilingDecorViewModel.tilingTransitionHandlerByDisplayId.put(
            1,
            desktopTilingDecoration,
@@ -145,6 +142,22 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {
        verify(desktopTilingDecoration, times(2)).onOverviewAnimationStateChange(any())
    }

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

        desktopTilingDecorViewModel.onUserChange()

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

    companion object {
        private val BOUNDS = Rect(1, 2, 3, 4)
    }
+38 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
    private val info: TransitionInfo = mock()
    private val finishCallback: Transitions.TransitionFinishCallback = mock()
    private val desktopRepository: DesktopRepository = mock()
    private val desktopTilingDividerWindowManager: DesktopTilingDividerWindowManager = mock()
    private lateinit var tilingDecoration: DesktopTilingWindowDecoration

    private val split_divider_width = 10
@@ -443,6 +444,43 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
        verify(tiledTaskHelper, never()).dispose()
    }

    @Test
    fun tasksTiled_shouldBeRemoved_whenSessionDestroyed() {
        val task1 = createFreeformTask()
        val task2 = createFreeformTask()
        val stableBounds = STABLE_BOUNDS_MOCK
        whenever(displayController.getDisplayLayout(any())).thenReturn(displayLayout)
        whenever(displayLayout.getStableBounds(any())).thenAnswer { i ->
            (i.arguments.first() as Rect).set(stableBounds)
        }
        whenever(context.resources).thenReturn(resources)
        whenever(resources.getDimensionPixelSize(any())).thenReturn(split_divider_width)
        whenever(tiledTaskHelper.taskInfo).thenReturn(task1)
        whenever(tiledTaskHelper.desktopModeWindowDecoration).thenReturn(desktopWindowDecoration)
        tilingDecoration.onAppTiled(
            task1,
            desktopWindowDecoration,
            DesktopTasksController.SnapPosition.LEFT,
            BOUNDS,
        )
        tilingDecoration.onAppTiled(
            task2,
            desktopWindowDecoration,
            DesktopTasksController.SnapPosition.RIGHT,
            BOUNDS,
        )
        tilingDecoration.leftTaskResizingHelper = tiledTaskHelper
        tilingDecoration.rightTaskResizingHelper = tiledTaskHelper
        tilingDecoration.desktopTilingDividerWindowManager = desktopTilingDividerWindowManager

        tilingDecoration.onUserChange()

        assertThat(tilingDecoration.leftTaskResizingHelper).isNull()
        assertThat(tilingDecoration.rightTaskResizingHelper).isNull()
        verify(desktopWindowDecoration, times(2)).removeDragResizeListener(any())
        verify(tiledTaskHelper, times(2)).dispose()
    }

    private fun initTiledTaskHelperMock(taskInfo: ActivityManager.RunningTaskInfo) {
        whenever(tiledTaskHelper.bounds).thenReturn(BOUNDS)
        whenever(tiledTaskHelper.taskInfo).thenReturn(taskInfo)