From 1e893ffddd1dd05cb2dab1fdfc19f2305d860869 Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Thu, 20 Feb 2025 17:22:24 +0000 Subject: 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 --- .../wm/shell/desktopmode/DesktopTasksController.kt | 3 +++ .../wm/shell/desktopmode/DesktopTasksControllerTest.kt | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'libs') diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt index ca870d2b6988..87d967427d88 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt @@ -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( diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt index 785fb3e875b8..f8803e850ce3 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt @@ -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" -- cgit v1.2.3-59-g8ed1b