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

Commit bc6abcee authored by Orhan Uysal's avatar Orhan Uysal
Browse files

Launch home using the home intent on exit desktop

In some cases we enter desktop from launcher that's not set to NORMAL
state e.g. ALL APPS state. In those scenarios, upon exiting desktop we
would like land on home page in a NORMAL state. This cl makes sure that
when we are exiting desktop, we launch the home with intent so that
launcher sets its states to NORMAL.

Test: atest DesktopTasksControllerTest
Fix: 341328243
Flag: EXEMPT bug fix

Change-Id: Ie13b14882261563f3876c568f6f3c9dbd145166c
parent b6a6e286
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -1378,6 +1378,31 @@ class DesktopTasksController(
            ?.let { homeTask -> wct.reorder(homeTask.getToken(), /* onTop= */ toTop) }
    }

    private fun addLaunchHomePendingIntent(wct: WindowContainerTransaction, displayId: Int) {
        val launchHomeIntent =
            Intent(Intent.ACTION_MAIN).apply {
                if (displayId != DEFAULT_DISPLAY) {
                    addCategory(Intent.CATEGORY_SECONDARY_HOME)
                } else {
                    addCategory(Intent.CATEGORY_HOME)
                }
            }
        val options =
            ActivityOptions.makeBasic().apply {
                launchWindowingMode = WINDOWING_MODE_FULLSCREEN
                pendingIntentBackgroundActivityStartMode =
                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS
            }
        val pendingIntent =
            PendingIntent.getActivity(
                context,
                /* requestCode = */ 0,
                launchHomeIntent,
                PendingIntent.FLAG_IMMUTABLE,
            )
        wct.sendPendingIntent(pendingIntent, launchHomeIntent, options.toBundle())
    }

    private fun addWallpaperActivity(displayId: Int, wct: WindowContainerTransaction) {
        logV("addWallpaperActivity")
        if (Flags.enableDesktopWallpaperActivityForSystemUser()) {
@@ -1460,6 +1485,7 @@ class DesktopTasksController(
        displayId: Int,
        wct: WindowContainerTransaction,
        forceToFullscreen: Boolean,
        shouldEndUpAtHome: Boolean = true,
    ) {
        taskRepository.setPipShouldKeepDesktopActive(displayId, !forceToFullscreen)
        if (Flags.enablePerDisplayDesktopWallpaperActivity()) {
@@ -1481,6 +1507,11 @@ class DesktopTasksController(
            FULLSCREEN_ANIMATION_DURATION
        )
        removeWallpaperActivity(wct, displayId)
        if (shouldEndUpAtHome) {
            // If the transition should end up with user going to home, launch home with a pending
            // intent.
            addLaunchHomePendingIntent(wct, displayId)
        }
    }

    fun releaseVisualIndicator() {
@@ -2093,6 +2124,7 @@ class DesktopTasksController(
            taskInfo.displayId,
            wct,
            forceToFullscreen = true,
            shouldEndUpAtHome = false,
        )
    }

@@ -2132,6 +2164,7 @@ class DesktopTasksController(
            taskInfo.displayId,
            wct,
            forceToFullscreen = false,
            shouldEndUpAtHome = false,
        )
    }

+43 −9
Original line number Diff line number Diff line
@@ -1569,6 +1569,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
        verify(desktopModeEnterExitTransitionListener)
            .onExitDesktopModeTransitionStarted(FULLSCREEN_ANIMATION_DURATION)
        assertThat(taskChange.windowingMode).isEqualTo(WINDOWING_MODE_UNDEFINED)
        assertThat(wct.hierarchyOps).hasSize(1)
        // Removes wallpaper activity when leaving desktop
        wct.assertReorderAt(index = 0, wallpaperToken, toTop = false)
    }
@@ -1603,6 +1604,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
        assertThat(taskChange.windowingMode).isEqualTo(WINDOWING_MODE_FULLSCREEN)
        verify(desktopModeEnterExitTransitionListener)
            .onExitDesktopModeTransitionStarted(FULLSCREEN_ANIMATION_DURATION)
        assertThat(wct.hierarchyOps).hasSize(1)
        // Removes wallpaper activity when leaving desktop
        wct.assertReorderAt(index = 0, wallpaperToken, toTop = false)
    }
@@ -2010,15 +2012,15 @@ class DesktopTasksControllerTest : ShellTestCase() {
    }

    @Test
    fun onDesktopWindowClose_singleActiveTask_noWallpaperActivityToken() {
    fun onDesktopWindowClose_singleActiveTask_noWallpaperActivityToken_launchesHome() {
        val task = setUpFreeformTask()
        val wct = WindowContainerTransaction()
        whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)

        controller.onDesktopWindowClose(wct, displayId = DEFAULT_DISPLAY, task)

        // Doesn't modify transaction
        assertThat(wct.hierarchyOps).isEmpty()
        // Should launch home
        wct.assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
    }

    @Test
@@ -2867,14 +2869,16 @@ class DesktopTasksControllerTest : ShellTestCase() {

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
    fun handleRequest_backTransition_singleTaskNoToken_withWallpaper_removesTask() {
    fun handleRequest_backTransition_singleTaskNoToken_withWallpaper_launchesHome() {
        val task = setUpFreeformTask()
        whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)

        val result =
            controller.handleRequest(Binder(), createTransition(task, type = TRANSIT_TO_BACK))

        assertNull(result, "Should not handle request")
        // Should launch home
        assertNotNull(result, "Should handle request")
            .assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
    }

    @Test
@@ -2891,14 +2895,16 @@ class DesktopTasksControllerTest : ShellTestCase() {

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
    fun handleRequest_backTransition_singleTaskNoToken_doesNotHandle() {
    fun handleRequest_backTransition_singleTaskNoToken_launchesHomes() {
        val task = setUpFreeformTask()
        whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)

        val result =
            controller.handleRequest(Binder(), createTransition(task, type = TRANSIT_TO_BACK))

        assertNull(result, "Should not handle request")
        // Should launch home
        assertNotNull(result, "Should handle request")
            .assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
    }

    @Test
@@ -3017,14 +3023,30 @@ class DesktopTasksControllerTest : ShellTestCase() {

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
    fun handleRequest_closeTransition_singleTaskNoToken_doesNotHandle() {
    fun handleRequest_closeTransition_singleTaskNoToken_launchesHome() {
        val task = setUpFreeformTask()
        whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)

        val result =
            controller.handleRequest(Binder(), createTransition(task, type = TRANSIT_CLOSE))

        assertNull(result, "Should not handle request")
        // Should launch home
        assertNotNull(result, "Should handle request")
            .assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
    fun handleRequest_closeTransition_singleTaskNoToken_secondaryDisplay_launchesHome() {
        val task = setUpFreeformTask(displayId = SECOND_DISPLAY)
        whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)

        val result =
            controller.handleRequest(Binder(), createTransition(task, type = TRANSIT_CLOSE))

        // Should launch home
        assertNotNull(result, "Should handle request")
            .assertPendingIntentAt(0, launchHomeIntent(SECOND_DISPLAY))
    }

    @Test
@@ -3750,6 +3772,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
                eq(SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT),
                eq(task2.configuration.windowConfiguration.bounds),
            )
        assertThat(wctArgument.value.hierarchyOps).hasSize(1)
        // Removes wallpaper activity when leaving desktop
        wctArgument.value.assertReorderAt(index = 0, wallpaperToken, toTop = false)
    }
@@ -4947,6 +4970,16 @@ class DesktopTasksControllerTest : ShellTestCase() {
    private val desktopWallpaperIntent: Intent
        get() = Intent(context, DesktopWallpaperActivity::class.java)

    private fun launchHomeIntent(displayId: Int): Intent {
        return Intent(Intent.ACTION_MAIN).apply {
            if (displayId != DEFAULT_DISPLAY) {
                addCategory(Intent.CATEGORY_SECONDARY_HOME)
            } else {
                addCategory(Intent.CATEGORY_HOME)
            }
        }
    }

    private fun addFreeformTaskAtPosition(
        pos: DesktopTaskPosition,
        stableBounds: Rect,
@@ -5260,6 +5293,7 @@ private fun WindowContainerTransaction.assertPendingIntentAt(index: Int, intent:
    val op = hierarchyOps[index]
    assertThat(op.type).isEqualTo(HIERARCHY_OP_TYPE_PENDING_INTENT)
    assertThat(op.pendingIntent?.intent?.component).isEqualTo(intent.component)
    assertThat(op.pendingIntent?.intent?.categories).isEqualTo(intent.categories)
}

private fun WindowContainerTransaction.assertLaunchTaskAt(