summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/data/RecentTaskListProvider.kt9
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/data/ShellRecentTaskListProviderTest.kt46
2 files changed, 52 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/data/RecentTaskListProvider.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/data/RecentTaskListProvider.kt
index 5dde14bf0867..6e16c6eacfff 100644
--- a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/data/RecentTaskListProvider.kt
+++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/data/RecentTaskListProvider.kt
@@ -50,8 +50,13 @@ constructor(
withContext(coroutineDispatcher) {
val groupedTasks: List<GroupedRecentTaskInfo> = recents?.getTasks() ?: emptyList()
// Note: the returned task list is from the most-recent to least-recent order.
- // The last foreground task is at index 1, because at index 0 will be our app selector.
- val foregroundGroup = groupedTasks.elementAtOrNull(1)
+ // When opening the app selector in full screen, index 0 will be just the app selector
+ // activity and a null second task, so the foreground task will be index 1, but when
+ // opening the app selector in split screen mode, the foreground task will be the second
+ // task in index 0.
+ val foregroundGroup =
+ if (groupedTasks.elementAtOrNull(0)?.splitBounds != null) groupedTasks.first()
+ else groupedTasks.elementAtOrNull(1)
val foregroundTaskId1 = foregroundGroup?.taskInfo1?.taskId
val foregroundTaskId2 = foregroundGroup?.taskInfo2?.taskId
val foregroundTaskIds = listOfNotNull(foregroundTaskId1, foregroundTaskId2)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/data/ShellRecentTaskListProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/data/ShellRecentTaskListProviderTest.kt
index b593def283ae..6568175b151d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/data/ShellRecentTaskListProviderTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/data/ShellRecentTaskListProviderTest.kt
@@ -1,6 +1,7 @@
package com.android.systemui.mediaprojection.appselector.data
import android.app.ActivityManager.RecentTaskInfo
+import android.graphics.Rect
import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -8,8 +9,10 @@ import com.android.systemui.settings.UserTracker
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
+import com.android.wm.shell.common.split.SplitScreenConstants
import com.android.wm.shell.recents.RecentTasks
import com.android.wm.shell.util.GroupedRecentTaskInfo
+import com.android.wm.shell.util.SplitBounds
import com.google.common.truth.Truth.assertThat
import java.util.Optional
import java.util.function.Consumer
@@ -90,6 +93,17 @@ class ShellRecentTaskListProviderTest : SysuiTestCase() {
}
@Test
+ fun loadRecentTasks_singleTaskPair_returnsTasksAsForeground() {
+ givenRecentTasks(
+ createTaskPair(taskId1 = 2, taskId2 = 3, isVisible = true),
+ )
+
+ val result = runBlocking { recentTaskListProvider.loadRecentTasks() }
+
+ assertThat(result[0].isForegroundTask).isTrue()
+ }
+
+ @Test
fun loadRecentTasks_multipleTasks_returnsSecondVisibleTaskAsForegroundTask() {
givenRecentTasks(
createSingleTask(taskId = 1),
@@ -133,6 +147,21 @@ class ShellRecentTaskListProviderTest : SysuiTestCase() {
}
@Test
+ fun loadRecentTasks_firstTaskIsGroupedAndVisible_marksBothGroupedTasksAsForeground() {
+ givenRecentTasks(
+ createTaskPair(taskId1 = 1, taskId2 = 2, isVisible = true),
+ createSingleTask(taskId = 3),
+ createSingleTask(taskId = 4),
+ )
+
+ val result = runBlocking { recentTaskListProvider.loadRecentTasks() }
+
+ assertThat(result.map { it.isForegroundTask })
+ .containsExactly(true, true, false, false)
+ .inOrder()
+ }
+
+ @Test
fun loadRecentTasks_secondTaskIsGroupedAndInvisible_marksBothGroupedTasksAsNotForeground() {
givenRecentTasks(
createSingleTask(taskId = 1),
@@ -147,6 +176,21 @@ class ShellRecentTaskListProviderTest : SysuiTestCase() {
.inOrder()
}
+ @Test
+ fun loadRecentTasks_firstTaskIsGroupedAndInvisible_marksBothGroupedTasksAsNotForeground() {
+ givenRecentTasks(
+ createTaskPair(taskId1 = 1, taskId2 = 2, isVisible = false),
+ createSingleTask(taskId = 3),
+ createSingleTask(taskId = 4),
+ )
+
+ val result = runBlocking { recentTaskListProvider.loadRecentTasks() }
+
+ assertThat(result.map { it.isForegroundTask })
+ .containsExactly(false, false, false, false)
+ .inOrder()
+ }
+
@Suppress("UNCHECKED_CAST")
private fun givenRecentTasks(vararg tasks: GroupedRecentTaskInfo) {
whenever(recentTasks.getRecentTasks(any(), any(), any(), any(), any())).thenAnswer {
@@ -177,7 +221,7 @@ class ShellRecentTaskListProviderTest : SysuiTestCase() {
GroupedRecentTaskInfo.forSplitTasks(
createTaskInfo(taskId1, isVisible),
createTaskInfo(taskId2, isVisible),
- null
+ SplitBounds(Rect(), Rect(), taskId1, taskId2, SplitScreenConstants.SNAP_TO_50_50)
)
private fun createTaskInfo(taskId: Int, isVisible: Boolean = false) =