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

Commit a0ba0e12 authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Desktop: check wallpaper to know if last window is closing

Before this CL, to know whether Desktop Mode is closing, we would check
whether the closing task is the last active task in our desktop
repository.  However, in cases where we close the last task while the
second to last task is still closing there will still be two active
tasks in our desktop repository.

In this CL we instead determine whether desktop mode is closing by
checking whether the wallpaper activity is closing.

Bug: 379852092
Test: ensure closing last task while 2nd last still closing works
Flag: com.android.window.flags.enable_desktop_windowing_exit_transitions
Change-Id: I7e999e6baf4e809409f54d7093f0b32609866f38

Change-Id: Iab045e98e0e5f88925dfc4f0dd7166494910269b
parent e6f0a017
Loading
Loading
Loading
Loading
+10 −6
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.Handler
import android.os.IBinder
import android.os.IBinder
import android.view.SurfaceControl
import android.view.SurfaceControl
import android.view.WindowManager
import android.view.WindowManager
import android.view.WindowManager.TRANSIT_CLOSE
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_OPEN
import android.window.DesktopModeFlags
import android.window.DesktopModeFlags
import android.window.TransitionInfo
import android.window.TransitionInfo
@@ -197,8 +198,9 @@ class DesktopMixedTransitionHandler(
            logW("Should have closing desktop task")
            logW("Should have closing desktop task")
            return false
            return false
        }
        }
        if (isLastDesktopTask(closeChange)) {
        if (isWallpaperActivityClosing(info)) {
            // Dispatch close desktop task animation to the default transition handlers.
            // If the wallpaper activity is closing then the desktop is closing, animate the closing
            // desktop by dispatching to other transition handlers.
            return dispatchCloseLastDesktopTaskAnimation(
            return dispatchCloseLastDesktopTaskAnimation(
                transition,
                transition,
                info,
                info,
@@ -419,10 +421,12 @@ class DesktopMixedTransitionHandler(
        ) != null
        ) != null
    }
    }


    private fun isLastDesktopTask(change: TransitionInfo.Change): Boolean =
    private fun isWallpaperActivityClosing(info: TransitionInfo) =
        change.taskInfo?.let {
        info.changes.any { change ->
            desktopUserRepositories.getProfile(it.userId).getExpandedTaskCount(it.displayId) == 1
            change.mode == TRANSIT_CLOSE &&
        } ?: false
                change.taskInfo != null &&
                DesktopWallpaperActivity.isWallpaperTask(change.taskInfo!!)
        }


    private fun findCloseDesktopTaskChange(info: TransitionInfo): TransitionInfo.Change? {
    private fun findCloseDesktopTaskChange(info: TransitionInfo): TransitionInfo.Change? {
        if (info.type != WindowManager.TRANSIT_CLOSE) return null
        if (info.type != WindowManager.TRANSIT_CLOSE) return null
+42 −22
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD
import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN
import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN
import android.app.WindowConfiguration.WindowingMode
import android.app.WindowConfiguration.WindowingMode
import android.content.Intent
import android.os.Binder
import android.os.Binder
import android.os.Handler
import android.os.Handler
import android.os.IBinder
import android.os.IBinder
@@ -36,7 +37,9 @@ import android.view.WindowManager.TRANSIT_NONE
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_TO_BACK
import android.view.WindowManager.TRANSIT_TO_BACK
import android.view.WindowManager.TransitionType
import android.view.WindowManager.TransitionType
import android.window.IWindowContainerToken
import android.window.TransitionInfo
import android.window.TransitionInfo
import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import android.window.WindowContainerTransaction
import androidx.test.filters.SmallTest
import androidx.test.filters.SmallTest
import com.android.internal.jank.Cuj.CUJ_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE
import com.android.internal.jank.Cuj.CUJ_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE
@@ -188,7 +191,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
    fun startAnimation_withoutClosingDesktopTask_returnsFalse() {
    fun startAnimation_withoutClosingDesktopTask_returnsFalse() {
        val transition = mock<IBinder>()
        val transition = mock<IBinder>()
        val transitionInfo =
        val transitionInfo =
            createTransitionInfo(
            createCloseTransitionInfo(
                changeMode = TRANSIT_OPEN,
                changeMode = TRANSIT_OPEN,
                task = createTask(WINDOWING_MODE_FREEFORM)
                task = createTask(WINDOWING_MODE_FREEFORM)
            )
            )
@@ -213,8 +216,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
    fun startAnimation_withClosingDesktopTask_callsCloseTaskHandler() {
    fun startAnimation_withClosingDesktopTask_callsCloseTaskHandler() {
        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        val transition = mock<IBinder>()
        val transition = mock<IBinder>()
        val transitionInfo = createTransitionInfo(task = createTask(WINDOWING_MODE_FREEFORM))
        val transitionInfo = createCloseTransitionInfo(task = createTask(WINDOWING_MODE_FREEFORM))
        whenever(desktopRepository.getExpandedTaskCount(any())).thenReturn(2)
        whenever(
        whenever(
                closeDesktopTaskTransitionHandler.startAnimation(any(), any(), any(), any(), any())
                closeDesktopTaskTransitionHandler.startAnimation(any(), any(), any(), any(), any())
            )
            )
@@ -243,8 +245,8 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
    fun startAnimation_withClosingLastDesktopTask_dispatchesTransition() {
    fun startAnimation_withClosingLastDesktopTask_dispatchesTransition() {
        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        val transition = mock<IBinder>()
        val transition = mock<IBinder>()
        val transitionInfo = createTransitionInfo(task = createTask(WINDOWING_MODE_FREEFORM))
        val transitionInfo = createCloseTransitionInfo(
        whenever(desktopRepository.getExpandedTaskCount(any())).thenReturn(1)
            task = createTask(WINDOWING_MODE_FREEFORM), withWallpaper = true)
        whenever(transitions.dispatchTransition(any(), any(), any(), any(), any(), any()))
        whenever(transitions.dispatchTransition(any(), any(), any(), any(), any(), any()))
            .thenReturn(mock())
            .thenReturn(mock())
        whenever(transitions.startTransition(WindowManager.TRANSIT_CLOSE, wct, mixedHandler))
        whenever(transitions.startTransition(WindowManager.TRANSIT_CLOSE, wct, mixedHandler))
@@ -355,7 +357,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
        val otherChange = createChange(createTask(WINDOWING_MODE_FREEFORM))
        val otherChange = createChange(createTask(WINDOWING_MODE_FREEFORM))
        mixedHandler.startAnimation(
        mixedHandler.startAnimation(
            transition,
            transition,
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_OPEN,
                TRANSIT_OPEN,
                listOf(launchTaskChange, otherChange)
                listOf(launchTaskChange, otherChange)
            ),
            ),
@@ -395,7 +397,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
        val immersiveChange = createChange(immersiveTask)
        val immersiveChange = createChange(immersiveTask)
        mixedHandler.startAnimation(
        mixedHandler.startAnimation(
            transition,
            transition,
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_OPEN,
                TRANSIT_OPEN,
                listOf(launchTaskChange, immersiveChange)
                listOf(launchTaskChange, immersiveChange)
            ),
            ),
@@ -437,7 +439,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
        )
        )
        mixedHandler.startAnimation(
        mixedHandler.startAnimation(
            transition,
            transition,
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_OPEN,
                TRANSIT_OPEN,
                listOf(launchTaskChange)
                listOf(launchTaskChange)
            ),
            ),
@@ -471,7 +473,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
        )
        )
        mixedHandler.startAnimation(
        mixedHandler.startAnimation(
            transition,
            transition,
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_OPEN,
                TRANSIT_OPEN,
                listOf(launchTaskChange, minimizeChange)
                listOf(launchTaskChange, minimizeChange)
            ),
            ),
@@ -505,7 +507,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {


        val started = mixedHandler.startAnimation(
        val started = mixedHandler.startAnimation(
            transition,
            transition,
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_OPEN,
                TRANSIT_OPEN,
                listOf(nonLaunchTaskChange)
                listOf(nonLaunchTaskChange)
            ),
            ),
@@ -535,7 +537,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {


        val started = mixedHandler.startAnimation(
        val started = mixedHandler.startAnimation(
            transition,
            transition,
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_OPEN,
                TRANSIT_OPEN,
                listOf(createChange(task, mode = TRANSIT_OPEN))
                listOf(createChange(task, mode = TRANSIT_OPEN))
            ),
            ),
@@ -569,7 +571,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
        val openingChange = createChange(openingTask, mode = TRANSIT_OPEN)
        val openingChange = createChange(openingTask, mode = TRANSIT_OPEN)
        val started = mixedHandler.startAnimation(
        val started = mixedHandler.startAnimation(
            transition,
            transition,
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_OPEN,
                TRANSIT_OPEN,
                listOf(immersiveChange, openingChange)
                listOf(immersiveChange, openingChange)
            ),
            ),
@@ -604,7 +606,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
        )
        )
        mixedHandler.startAnimation(
        mixedHandler.startAnimation(
            transition,
            transition,
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_OPEN,
                TRANSIT_OPEN,
                listOf(launchTaskChange)
                listOf(launchTaskChange)
            ),
            ),
@@ -640,7 +642,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
        )
        )
        mixedHandler.startAnimation(
        mixedHandler.startAnimation(
            transition,
            transition,
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_OPEN,
                TRANSIT_OPEN,
                listOf(launchTaskChange, minimizeChange)
                listOf(launchTaskChange, minimizeChange)
            ),
            ),
@@ -670,7 +672,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
        val launchTaskChange = createChange(launchingTask)
        val launchTaskChange = createChange(launchingTask)
        mixedHandler.startAnimation(
        mixedHandler.startAnimation(
            transition,
            transition,
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_OPEN,
                TRANSIT_OPEN,
                listOf(launchTaskChange)
                listOf(launchTaskChange)
            ),
            ),
@@ -727,7 +729,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
        val started = mixedHandler.startAnimation(
        val started = mixedHandler.startAnimation(
            transition = transition,
            transition = transition,
            info =
            info =
                createTransitionInfo(
                createCloseTransitionInfo(
                TRANSIT_TO_BACK,
                TRANSIT_TO_BACK,
                listOf(minimizingTaskChange)
                listOf(minimizingTaskChange)
            ),
            ),
@@ -766,7 +768,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
        mixedHandler.startAnimation(
        mixedHandler.startAnimation(
            transition = transition,
            transition = transition,
            info =
            info =
            createTransitionInfo(
            createCloseTransitionInfo(
                TRANSIT_TO_BACK,
                TRANSIT_TO_BACK,
                listOf(minimizingTaskChange)
                listOf(minimizingTaskChange)
            ),
            ),
@@ -786,12 +788,12 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
            )
            )
    }
    }


    private fun createTransitionInfo(
    private fun createCloseTransitionInfo(
        type: Int = WindowManager.TRANSIT_CLOSE,
        changeMode: Int = WindowManager.TRANSIT_CLOSE,
        changeMode: Int = WindowManager.TRANSIT_CLOSE,
        task: RunningTaskInfo
        task: RunningTaskInfo,
        withWallpaper: Boolean = false,
    ): TransitionInfo =
    ): TransitionInfo =
        TransitionInfo(type, 0 /* flags */).apply {
        TransitionInfo(WindowManager.TRANSIT_CLOSE, 0 /* flags */).apply {
            addChange(
            addChange(
                TransitionInfo.Change(mock(), closingTaskLeash).apply {
                TransitionInfo.Change(mock(), closingTaskLeash).apply {
                    mode = changeMode
                    mode = changeMode
@@ -799,9 +801,18 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
                    taskInfo = task
                    taskInfo = task
                }
                }
            )
            )
            if (withWallpaper) {
                addChange(
                    TransitionInfo.Change(/* container= */ mock(), /* leash= */ mock()).apply {
                        mode = WindowManager.TRANSIT_CLOSE
                        parent = null
                        taskInfo = createWallpaperTask()
                    }
                )
            }
        }
        }


    private fun createTransitionInfo(
    private fun createCloseTransitionInfo(
        @TransitionType type: Int,
        @TransitionType type: Int,
        changes: List<TransitionInfo.Change> = emptyList()
        changes: List<TransitionInfo.Change> = emptyList()
    ): TransitionInfo = TransitionInfo(type, /* flags= */ 0).apply {
    ): TransitionInfo = TransitionInfo(type, /* flags= */ 0).apply {
@@ -822,4 +833,13 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() {
            .setActivityType(ACTIVITY_TYPE_STANDARD)
            .setActivityType(ACTIVITY_TYPE_STANDARD)
            .setWindowingMode(windowingMode)
            .setWindowingMode(windowingMode)
            .build()
            .build()

    private fun createWallpaperTask() =
        RunningTaskInfo().apply {
            token = WindowContainerToken(mock<IWindowContainerToken>())
            baseIntent =
                Intent().apply {
                    component = DesktopWallpaperActivity.wallpaperActivityComponent
                }
        }
}
}