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

Commit 55997d1a authored by Ats Jenk's avatar Ats Jenk
Browse files

Remove windowing mode override from task when it matches display

When a task is moving from desktop to fullscreen or vice versa, check if
the desired windowing mode matches the display windowing mode. If it
does, remove the windowing mode override and set it to undefined.

Fixes an issue with split screen where a task that has been on desktop,
is not eligible to be in split anymore. As the task had windowing mode
overridden to fullscreen.

Bug: 285358244
Test: atest DesktopTasksControllerTest
Test: move Chrome to freeform and back to fullscreen, use "new window"
  from the menu to create a new chrome window in split screen
Change-Id: I7b683e1cf2353c5cfa58bd1d7d3ab1b5319c9be7
parent 5ec5b7d5
Loading
Loading
Loading
Loading
+31 −18
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_TO_FRONT
import android.window.TransitionInfo
import android.window.TransitionRequestInfo
import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import androidx.annotation.BinderThread
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
@@ -184,7 +183,7 @@ class DesktopTasksController(
        )
        // Bring other apps to front first
        bringDesktopAppsToFront(task.displayId, wct)
        addMoveToDesktopChanges(wct, task.token)
        addMoveToDesktopChanges(wct, task)

        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            transitions.startTransition(TRANSIT_CHANGE, wct, null /* handler */)
@@ -205,7 +204,7 @@ class DesktopTasksController(
        )
        val wct = WindowContainerTransaction()
        moveHomeTaskToFront(wct)
        addMoveToDesktopChanges(wct, taskInfo.getToken())
        addMoveToDesktopChanges(wct, taskInfo)
        wct.setBounds(taskInfo.token, startBounds)

        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
@@ -225,7 +224,7 @@ class DesktopTasksController(
        )
        val wct = WindowContainerTransaction()
        bringDesktopAppsToFront(taskInfo.displayId, wct)
        addMoveToDesktopChanges(wct, taskInfo.getToken())
        addMoveToDesktopChanges(wct, taskInfo)
        wct.setBounds(taskInfo.token, freeformBounds)

        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
@@ -251,7 +250,7 @@ class DesktopTasksController(
        )

        val wct = WindowContainerTransaction()
        addMoveToFullscreenChanges(wct, task.token)
        addMoveToFullscreenChanges(wct, task)
        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            transitions.startTransition(TRANSIT_CHANGE, wct, null /* handler */)
        } else {
@@ -270,7 +269,7 @@ class DesktopTasksController(
                task.taskId
        )
        val wct = WindowContainerTransaction()
        addMoveToFullscreenChanges(wct, task.token)
        addMoveToFullscreenChanges(wct, task)
        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            enterDesktopTaskTransitionHandler.startCancelMoveToDesktopMode(wct, position,
                    mOnAnimationFinishedCallback)
@@ -287,7 +286,7 @@ class DesktopTasksController(
                task.taskId
        )
        val wct = WindowContainerTransaction()
        addMoveToFullscreenChanges(wct, task.token)
        addMoveToFullscreenChanges(wct, task)

        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            exitDesktopTaskTransitionHandler.startTransition(
@@ -516,7 +515,7 @@ class DesktopTasksController(
                    task.taskId
            )
            return WindowContainerTransaction().also { wct ->
                addMoveToFullscreenChanges(wct, task.token)
                addMoveToFullscreenChanges(wct, task)
            }
        }
        return null
@@ -532,7 +531,7 @@ class DesktopTasksController(
                    task.taskId
            )
            return WindowContainerTransaction().also { wct ->
                addMoveToDesktopChanges(wct, task.token)
                addMoveToDesktopChanges(wct, task)
            }
        }
        return null
@@ -546,30 +545,44 @@ class DesktopTasksController(
        )
        val wct = WindowContainerTransaction()
        bringDesktopAppsToFront(task.displayId, wct)
        addMoveToDesktopChanges(wct, task.token)
        addMoveToDesktopChanges(wct, task)
        desktopModeTaskRepository.setStashed(task.displayId, false)
        return wct
    }

    private fun addMoveToDesktopChanges(
        wct: WindowContainerTransaction,
        token: WindowContainerToken
        taskInfo: RunningTaskInfo
    ) {
        wct.setWindowingMode(token, WINDOWING_MODE_FREEFORM)
        wct.reorder(token, true /* onTop */)
        val displayWindowingMode = taskInfo.configuration.windowConfiguration.displayWindowingMode
        val targetWindowingMode = if (displayWindowingMode == WINDOWING_MODE_FREEFORM) {
            // Display windowing is freeform, set to undefined and inherit it
            WINDOWING_MODE_UNDEFINED
        } else {
            WINDOWING_MODE_FREEFORM
        }
        wct.setWindowingMode(taskInfo.token, targetWindowingMode)
        wct.reorder(taskInfo.token, true /* onTop */)
        if (isDesktopDensityOverrideSet()) {
            wct.setDensityDpi(token, getDesktopDensityDpi())
            wct.setDensityDpi(taskInfo.token, getDesktopDensityDpi())
        }
    }

    private fun addMoveToFullscreenChanges(
        wct: WindowContainerTransaction,
        token: WindowContainerToken
        taskInfo: RunningTaskInfo
    ) {
        wct.setWindowingMode(token, WINDOWING_MODE_FULLSCREEN)
        wct.setBounds(token, null)
        val displayWindowingMode = taskInfo.configuration.windowConfiguration.displayWindowingMode
        val targetWindowingMode = if (displayWindowingMode == WINDOWING_MODE_FULLSCREEN) {
            // Display windowing is fullscreen, set to undefined and inherit it
            WINDOWING_MODE_UNDEFINED
        } else {
            WINDOWING_MODE_FULLSCREEN
        }
        wct.setWindowingMode(taskInfo.token, targetWindowingMode)
        wct.setBounds(taskInfo.token, null)
        if (isDesktopDensityOverrideSet()) {
            wct.setDensityDpi(token, getFullscreenDensityDpi())
            wct.setDensityDpi(taskInfo.token, getFullscreenDensityDpi())
        }
    }

+25 −3
Original line number Diff line number Diff line
@@ -270,14 +270,25 @@ class DesktopTasksControllerTest : ShellTestCase() {
    }

    @Test
    fun moveToDesktop() {
    fun moveToDesktop_displayFullscreen_windowingModeSetToFreeform() {
        val task = setUpFullscreenTask()
        task.configuration.windowConfiguration.displayWindowingMode = WINDOWING_MODE_FULLSCREEN
        controller.moveToDesktop(task)
        val wct = getLatestWct(expectTransition = TRANSIT_CHANGE)
        assertThat(wct.changes[task.token.asBinder()]?.windowingMode)
            .isEqualTo(WINDOWING_MODE_FREEFORM)
    }

    @Test
    fun moveToDesktop_displayFreeform_windowingModeSetToUndefined() {
        val task = setUpFullscreenTask()
        task.configuration.windowConfiguration.displayWindowingMode = WINDOWING_MODE_FREEFORM
        controller.moveToDesktop(task)
        val wct = getLatestWct(expectTransition = TRANSIT_CHANGE)
        assertThat(wct.changes[task.token.asBinder()]?.windowingMode)
                .isEqualTo(WINDOWING_MODE_UNDEFINED)
    }

    @Test
    fun moveToDesktop_nonExistentTask_doesNothing() {
        controller.moveToDesktop(999)
@@ -325,8 +336,19 @@ class DesktopTasksControllerTest : ShellTestCase() {
    }

    @Test
    fun moveToFullscreen() {
    fun moveToFullscreen_displayFullscreen_windowingModeSetToUndefined() {
        val task = setUpFreeformTask()
        task.configuration.windowConfiguration.displayWindowingMode = WINDOWING_MODE_FULLSCREEN
        controller.moveToFullscreen(task)
        val wct = getLatestWct(expectTransition = TRANSIT_CHANGE)
        assertThat(wct.changes[task.token.asBinder()]?.windowingMode)
            .isEqualTo(WINDOWING_MODE_UNDEFINED)
    }

    @Test
    fun moveToFullscreen_displayFreeform_windowingModeSetToFullscreen() {
        val task = setUpFreeformTask()
        task.configuration.windowConfiguration.displayWindowingMode = WINDOWING_MODE_FREEFORM
        controller.moveToFullscreen(task)
        val wct = getLatestWct(expectTransition = TRANSIT_CHANGE)
        assertThat(wct.changes[task.token.asBinder()]?.windowingMode)