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

Commit 24a71cbb authored by Omar Elmekkawy's avatar Omar Elmekkawy
Browse files

Fix a bug where divider is not shown after swiping to home

This CL fixes two minor bugs where the divider is not shown after swiping
to home, it also fixes edge resizing not working after swiping home by
executing callbacks that show the divider and enabling edge resizing.

Flag: com.android.window.flags.enable_tile_resizing

Test: unit tests and on device testing

Bug: 402725243
Change-Id: If5c777fec87d0b965eb37e0771ec6295afa1f5ec
parent 64ffccdd
Loading
Loading
Loading
Loading
+45 −2
Original line number Diff line number Diff line
@@ -432,15 +432,38 @@ class DesktopTilingWindowDecoration(
        startTransaction: Transaction,
        finishTransaction: Transaction,
    ) {
        var leftTaskBroughtToFront = false
        var rightTaskBroughtToFront = false

        for (change in info.changes) {
            change.taskInfo?.let {
                if (it.isFullscreen || isMinimized(change.mode, info.type)) {
                    removeTaskIfTiled(it.taskId, /* taskVanished= */ false, it.isFullscreen)
                } else if (isEnteringPip(change, info.type)) {
                    removeTaskIfTiled(it.taskId, /* taskVanished= */ true, it.isFullscreen)
                } else if (isTransitionToFront(change.mode, info.type)) {
                    handleTaskBroughtToFront(it.taskId)
                    leftTaskBroughtToFront =
                        leftTaskBroughtToFront ||
                            it.taskId == leftTaskResizingHelper?.taskInfo?.taskId
                    rightTaskBroughtToFront =
                        rightTaskBroughtToFront ||
                            it.taskId == rightTaskResizingHelper?.taskInfo?.taskId
                }
            }
        }

        if (leftTaskBroughtToFront && rightTaskBroughtToFront) {
            desktopTilingDividerWindowManager?.showDividerBar()
        }
    }

    private fun handleTaskBroughtToFront(taskId: Int) {
        if (taskId == leftTaskResizingHelper?.taskInfo?.taskId) {
            leftTaskResizingHelper?.onAppBecomingVisible()
        } else if (taskId == rightTaskResizingHelper?.taskInfo?.taskId) {
            rightTaskResizingHelper?.onAppBecomingVisible()
        }
    }

    private fun isMinimized(changeMode: Int, infoType: Int): Boolean {
@@ -471,6 +494,9 @@ class DesktopTilingWindowDecoration(
        return false
    }

    private fun isTransitionToFront(changeMode: Int, transitionType: Int): Boolean =
        changeMode == TRANSIT_TO_FRONT && transitionType == TRANSIT_TO_FRONT

    class AppResizingHelper(
        val taskInfo: RunningTaskInfo,
        val desktopModeWindowDecoration: DesktopModeWindowDecoration,
@@ -484,6 +510,7 @@ class DesktopTilingWindowDecoration(
    ) {
        var isInitialised = false
        var newBounds = Rect(bounds)
        var visibilityCallback: (() -> Unit)? = null
        private lateinit var resizeVeil: ResizeVeil
        private val displayContext = displayController.getDisplayContext(taskInfo.displayId)
        private val userContext =
@@ -521,6 +548,11 @@ class DesktopTilingWindowDecoration(

        fun updateVeil(t: Transaction) = resizeVeil.updateTransactionWithResizeVeil(t, newBounds)

        fun onAppBecomingVisible() {
            visibilityCallback?.invoke()
            visibilityCallback = null
        }

        fun hideVeil() = resizeVeil.hideVeil()

        private fun createIconFactory(context: Context, dimensions: Int): BaseIconFactory {
@@ -593,11 +625,16 @@ class DesktopTilingWindowDecoration(
            removeTask(leftTaskResizingHelper, taskVanished, shouldDelayUpdate)
            leftTaskResizingHelper = null
            val taskId = rightTaskResizingHelper?.taskInfo?.taskId
            if (taskId != null && taskRepository.isVisibleTask(taskId)) {
            val callback: (() -> Unit)? = {
                rightTaskResizingHelper
                    ?.desktopModeWindowDecoration
                    ?.updateDisabledResizingEdge(NONE, shouldDelayUpdate)
            }
            if (taskId != null && taskRepository.isVisibleTask(taskId)) {
                callback?.invoke()
            } else if (rightTaskResizingHelper != null) {
                rightTaskResizingHelper?.visibilityCallback = callback
            }
            tearDownTiling()
            return
        }
@@ -607,11 +644,17 @@ class DesktopTilingWindowDecoration(
            removeTask(rightTaskResizingHelper, taskVanished, shouldDelayUpdate)
            rightTaskResizingHelper = null
            val taskId = leftTaskResizingHelper?.taskInfo?.taskId
            if (taskId != null && taskRepository.isVisibleTask(taskId)) {
            val callback: (() -> Unit)? = {
                leftTaskResizingHelper
                    ?.desktopModeWindowDecoration
                    ?.updateDisabledResizingEdge(NONE, shouldDelayUpdate)
            }
            if (taskId != null && taskRepository.isVisibleTask(taskId)) {
                callback?.invoke()
            } else if (leftTaskResizingHelper != null) {
                leftTaskResizingHelper?.visibilityCallback = callback
            }

            tearDownTiling()
        }
    }
+49 −0
Original line number Diff line number Diff line
@@ -586,6 +586,31 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
        verify(tiledTaskHelper, times(1)).dispose()
    }

    @Test
    fun tilingDivider_shouldBeShown_whenTiledTasksBecomeVisible() {
        val task1 = createVisibleTask()
        val task2 = createVisibleTask()
        val additionalTaskHelper: DesktopTilingWindowDecoration.AppResizingHelper = mock()
        whenever(tiledTaskHelper.taskInfo).thenReturn(task1)
        whenever(tiledTaskHelper.desktopModeWindowDecoration).thenReturn(desktopWindowDecoration)
        whenever(additionalTaskHelper.taskInfo).thenReturn(task2)
        whenever(additionalTaskHelper.desktopModeWindowDecoration)
            .thenReturn(desktopWindowDecoration)

        tilingDecoration.leftTaskResizingHelper = tiledTaskHelper
        tilingDecoration.rightTaskResizingHelper = additionalTaskHelper
        tilingDecoration.desktopTilingDividerWindowManager = desktopTilingDividerWindowManager
        val changeInfo = createTransitFrontTransition(task1, task2)
        tilingDecoration.onTransitionReady(
            transition = mock(),
            info = changeInfo,
            startTransaction = mock(),
            finishTransaction = mock(),
        )

        verify(desktopTilingDividerWindowManager, times(1)).showDividerBar()
    }

    @Test
    fun taskNotTiled_shouldNotBeRemoved_whenNotTiled() {
        val task1 = createVisibleTask()
@@ -762,6 +787,30 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
            )
        }

    private fun createTransitFrontTransition(
        task1: RunningTaskInfo?,
        task2: RunningTaskInfo?,
        type: Int = TRANSIT_TO_FRONT,
    ) =
        TransitionInfo(type, /* flags= */ 0).apply {
            addChange(
                Change(mock(), mock()).apply {
                    mode = TRANSIT_TO_FRONT
                    parent = null
                    taskInfo = task1
                    flags = flags
                }
            )
            addChange(
                Change(mock(), mock()).apply {
                    mode = TRANSIT_TO_FRONT
                    parent = null
                    taskInfo = task2
                    flags = flags
                }
            )
        }

    companion object {
        private val NON_STABLE_BOUNDS_MOCK = Rect(50, 55, 100, 100)
        private val STABLE_BOUNDS_MOCK = Rect(0, 0, 100, 100)