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

Commit 1e893ffd authored by Ben Lin's avatar Ben Lin
Browse files

Add ActivityOptions.displayId when launching home intent.

When we launch home intents, either primary or secondary, we also must
supply a displayId, or else Core will end up launching all home launcher
types on the default display (e.g. launching secondary_launcher on
primary display/moving it, which is not wanted).

Bug: 397236350
Test: atest
Flag:com.android.window.flags.enable_per_display_desktop_wallpaper_activity

Change-Id: I907cf3f38ef449a5f0550ef06fa2b86ed33b0cf1
parent 78b9ad54
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1745,6 +1745,9 @@ class DesktopTasksController(
                launchWindowingMode = WINDOWING_MODE_FULLSCREEN
                pendingIntentBackgroundActivityStartMode =
                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS
                if (Flags.enablePerDisplayDesktopWallpaperActivity()) {
                    launchDisplayId = displayId
                }
            }
        val pendingIntent =
            PendingIntent.getActivityAsUser(
+17 −0
Original line number Diff line number Diff line
@@ -2809,6 +2809,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()

        // Should launch home
        wct.assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
        wct.assertPendingIntentActivityOptionsLaunchDisplayIdAt(0, DEFAULT_DISPLAY)
    }

    @Test
@@ -3910,6 +3911,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        // Should launch home
        assertNotNull(result, "Should handle request")
            .assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
        result!!.assertPendingIntentActivityOptionsLaunchDisplayIdAt(0, DEFAULT_DISPLAY)
    }

    @Test
@@ -3936,6 +3938,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        // Should launch home
        assertNotNull(result, "Should handle request")
            .assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
        result!!.assertPendingIntentActivityOptionsLaunchDisplayIdAt(0, DEFAULT_DISPLAY)
    }

    @Test
@@ -4068,6 +4071,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        // Should launch home
        assertNotNull(result, "Should handle request")
            .assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
        result!!.assertPendingIntentActivityOptionsLaunchDisplayIdAt(0, DEFAULT_DISPLAY)
    }

    @Test
@@ -4084,6 +4088,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        // Should launch home
        assertNotNull(result, "Should handle request")
            .assertPendingIntentAt(0, launchHomeIntent(SECOND_DISPLAY))
        result!!.assertPendingIntentActivityOptionsLaunchDisplayIdAt(0, SECOND_DISPLAY)
    }

    @Test
@@ -6877,6 +6882,18 @@ private fun WindowContainerTransaction.assertPendingIntentAt(index: Int, intent:
    assertThat(op.pendingIntent?.intent?.categories).isEqualTo(intent.categories)
}

private fun WindowContainerTransaction.assertPendingIntentActivityOptionsLaunchDisplayIdAt(
    index: Int,
    displayId: Int,
) {
    assertIndexInBounds(index)
    val op = hierarchyOps[index]
    if (op.launchOptions != null) {
        val options = ActivityOptions(op.launchOptions)
        assertThat(options.launchDisplayId).isEqualTo(displayId)
    }
}

private fun WindowContainerTransaction.assertLaunchTask(taskId: Int, windowingMode: Int) {
    val keyLaunchWindowingMode = "android.activity.windowingMode"