From dafc2d4c42437ec096f16d2e50ce621175caca9b Mon Sep 17 00:00:00 2001 From: Ahmed Fakhry Date: Thu, 20 Feb 2025 06:47:07 +0000 Subject: [PATCH] Add `deskId` to `DesktopTask`. Now that `GroupedTaskInfo` propagates the `deskId` from Shell (see ag/31825217), we need to plumb this value in Launcher through `DesktopTask`. Future CLs will use this value in Overview. Bug: 395911284 Test: m, modified existing tests. Flag: com.android.window.flags.enable_multiple_desktops_frontend Flag: com.android.window.flags.enable_multiple_desktops_backend Change-Id: I396250e0cac761c4c5f7e8b2d6cddbe68e646217 --- .../DesktopVisibilityController.kt | 16 +++++++++++- .../android/quickstep/RecentTasksList.java | 21 ++++++++++++---- .../com/android/quickstep/util/DesktopTask.kt | 10 +++++--- .../android/quickstep/views/RecentsView.java | 6 ++++- .../launcher3/taskbar/TaskbarOverflowTest.kt | 2 +- .../TaskbarRecentAppsControllerTest.kt | 2 +- .../recents/data/TasksRepositoryTest.kt | 2 +- .../android/quickstep/util/DesktopTaskTest.kt | 25 ++++++++++++------- .../android/quickstep/util/GroupTaskTest.kt | 2 +- 9 files changed, 62 insertions(+), 24 deletions(-) diff --git a/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt b/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt index 6ee43ff04d..138f40a2dd 100644 --- a/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt +++ b/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt @@ -152,6 +152,20 @@ constructor( } } + /** + * Returns the ID of the active desk (if any) on the display whose ID is [displayId], or + * [INACTIVE_DESK_ID] if no desk is currently active or the multiple desks feature is disabled. + */ + fun getActiveDeskId(displayId: Int): Int { + if (!DesktopModeStatus.enableMultipleDesktops(context)) { + // When the multiple desks feature is disabled, callers should not rely on the concept + // of a desk ID. + return INACTIVE_DESK_ID + } + + return getDisplayDeskConfig(displayId)?.activeDeskId ?: INACTIVE_DESK_ID + } + /** Returns whether a desk is currently active on the display with the given [displayId]. */ fun isInDesktopMode(displayId: Int): Boolean { if (!DesktopModeStatus.enableMultipleDesktops(context)) { @@ -615,6 +629,6 @@ constructor( private const val TAG = "DesktopVisController" private const val DEBUG = false - private const val INACTIVE_DESK_ID = -1 + public const val INACTIVE_DESK_ID = -1 } } diff --git a/quickstep/src/com/android/quickstep/RecentTasksList.java b/quickstep/src/com/android/quickstep/RecentTasksList.java index 561bab4e62..2c4c2f9806 100644 --- a/quickstep/src/com/android/quickstep/RecentTasksList.java +++ b/quickstep/src/com/android/quickstep/RecentTasksList.java @@ -32,10 +32,12 @@ import android.content.Context; import android.os.Process; import android.os.RemoteException; import android.util.SparseBooleanArray; +import android.window.DesktopExperienceFlags; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; +import com.android.launcher3.statehandlers.DesktopVisibilityController; import com.android.launcher3.util.LooperExecutor; import com.android.launcher3.util.SplitConfigurationOptions; import com.android.quickstep.util.DesktopTask; @@ -354,8 +356,8 @@ public class RecentTasksList { int numVisibleTasks = 0; for (GroupedTaskInfo rawTask : rawTasks) { if (rawTask.isBaseType(TYPE_DESK)) { - // TYPE_FREEFORM tasks is only created when desktop mode can be entered, - // leftover TYPE_FREEFORM tasks created when flag was on should be ignored. + // TYPE_DESK tasks is only created when desktop mode can be entered, + // leftover TYPE_DESK tasks created when flag was on should be ignored. if (DesktopModeStatus.canEnterDesktopMode(mContext)) { List desktopTasks = createDesktopTasks( rawTask.getBaseGroupedTask()); @@ -442,7 +444,11 @@ public class RecentTasksList { Set minimizedTaskIds = minimizedTaskIdArray != null ? CollectionsKt.toSet(ArraysKt.asIterable(minimizedTaskIdArray)) : Collections.emptySet(); - if (enableSeparateExternalDisplayTasks()) { + if (enableSeparateExternalDisplayTasks() + && !DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue()) { + // This code is not needed when the multiple desktop feature is enabled, since Shell + // will send a single `GroupedTaskInfo` for each desk with a unique `deskId` across + // all displays. Map> perDisplayTasks = new HashMap<>(); for (TaskInfo taskInfo : recentTaskInfo.getTaskInfoList()) { Task task = createTask(taskInfo, minimizedTaskIds); @@ -450,11 +456,16 @@ public class RecentTasksList { k -> new ArrayList<>()); tasks.add(task); } - return MapsKt.map(perDisplayTasks, it -> new DesktopTask(it.getValue())); + // When the multiple desktop feature is disabled, there can only be up to a single desk + // on each display, The desk ID doesn't matter and should not be used. + return MapsKt.map(perDisplayTasks, + it -> new DesktopTask(DesktopVisibilityController.INACTIVE_DESK_ID, + it.getValue())); } else { + final int deskId = recentTaskInfo.getDeskId(); List tasks = CollectionsKt.map(recentTaskInfo.getTaskInfoList(), it -> createTask(it, minimizedTaskIds)); - return List.of(new DesktopTask(tasks)); + return List.of(new DesktopTask(deskId, tasks)); } } diff --git a/quickstep/src/com/android/quickstep/util/DesktopTask.kt b/quickstep/src/com/android/quickstep/util/DesktopTask.kt index 53ea022a23..fbe3bc64d0 100644 --- a/quickstep/src/com/android/quickstep/util/DesktopTask.kt +++ b/quickstep/src/com/android/quickstep/util/DesktopTask.kt @@ -20,17 +20,19 @@ import com.android.systemui.shared.recents.model.Task /** * A [Task] container that can contain N number of tasks that are part of the desktop in recent - * tasks list. Note that desktops can be empty with no tasks in them. + * tasks list. Note that desktops can be empty with no tasks in them. The [deskId] makes sense only + * when the multiple desks feature is enabled. */ -class DesktopTask(tasks: List) : GroupTask(tasks, TaskViewType.DESKTOP) { +class DesktopTask(val deskId: Int, tasks: List) : GroupTask(tasks, TaskViewType.DESKTOP) { - override fun copy() = DesktopTask(tasks) + override fun copy() = DesktopTask(deskId, tasks) - override fun toString() = "type=$taskViewType tasks=$tasks" + override fun toString() = "type=$taskViewType deskId=$deskId tasks=$tasks" override fun equals(o: Any?): Boolean { if (this === o) return true if (o !is DesktopTask) return false + if (deskId != o.deskId) return false return super.equals(o) } } diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index c5a76cb067..36af01a2e1 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -3044,8 +3044,12 @@ public abstract class RecentsView< // Add an empty view for now until the task plan is loaded and applied final TaskView taskView; if (needDesktopTask) { + final int activeDeskId = + DesktopVisibilityController.INSTANCE.get(mContext).getActiveDeskId( + mContainer.getDisplay().getDisplayId()); taskView = getTaskViewFromPool(TaskViewType.DESKTOP); - ((DesktopTaskView) taskView).bind(new DesktopTask(Arrays.asList(runningTasks)), + ((DesktopTaskView) taskView).bind( + new DesktopTask(activeDeskId, Arrays.asList(runningTasks)), mOrientationState, mTaskOverlayFactory); } else if (needGroupTaskView) { taskView = getTaskViewFromPool(TaskViewType.GROUPED); diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt index bfd53ef480..2cd09cc4a1 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt @@ -332,7 +332,7 @@ class TaskbarOverflowTest { (0..().apply { if (!runningTasks.isEmpty()) { - add(DesktopTask(ArrayList(runningTasks))) + add(DesktopTask(deskId = 0, ArrayList(runningTasks))) } addAll(recentTasks) } diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/TasksRepositoryTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/TasksRepositoryTest.kt index 10be6fdb96..6790567a85 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/TasksRepositoryTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/TasksRepositoryTest.kt @@ -64,7 +64,7 @@ class TasksRepositoryTest { /* snapPosition = */ SNAP_TO_2_50_50, ), ), - DesktopTask(tasks.subList(3, 6)), + DesktopTask(deskId = 0, tasks.subList(3, 6)), ) private val recentsModel = FakeRecentTasksDataSource() private val taskThumbnailDataSource = FakeTaskThumbnailDataSource() diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/util/DesktopTaskTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/util/DesktopTaskTest.kt index 7aed579f44..6fbf4823b7 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/util/DesktopTaskTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/util/DesktopTaskTest.kt @@ -29,35 +29,42 @@ class DesktopTaskTest { @Test fun testDesktopTask_sameInstance_isEqual() { - val task = DesktopTask(createTasks(1)) + val task = DesktopTask(deskId = 0, createTasks(1)) assertThat(task).isEqualTo(task) } @Test fun testDesktopTask_identicalConstructor_isEqual() { - val task1 = DesktopTask(createTasks(1)) - val task2 = DesktopTask(createTasks(1)) + val task1 = DesktopTask(deskId = 0, createTasks(1)) + val task2 = DesktopTask(deskId = 0, createTasks(1)) assertThat(task1).isEqualTo(task2) } @Test fun testDesktopTask_copy_isEqual() { - val task1 = DesktopTask(createTasks(1)) + val task1 = DesktopTask(deskId = 0, createTasks(1)) val task2 = task1.copy() assertThat(task1).isEqualTo(task2) } @Test - fun testDesktopTask_differentId_isNotEqual() { - val task1 = DesktopTask(createTasks(1)) - val task2 = DesktopTask(createTasks(2)) + fun testDesktopTask_differentDeskIds_isNotEqual() { + val task1 = DesktopTask(deskId = 0, createTasks(1)) + val task2 = DesktopTask(deskId = 1, createTasks(1)) + assertThat(task1).isNotEqualTo(task2) + } + + @Test + fun testDesktopTask_differentTaskIds_isNotEqual() { + val task1 = DesktopTask(deskId = 0, createTasks(1)) + val task2 = DesktopTask(deskId = 0, createTasks(2)) assertThat(task1).isNotEqualTo(task2) } @Test fun testDesktopTask_differentLength_isNotEqual() { - val task1 = DesktopTask(createTasks(1)) - val task2 = DesktopTask(createTasks(1, 2)) + val task1 = DesktopTask(deskId = 0, createTasks(1)) + val task2 = DesktopTask(deskId = 0, createTasks(1, 2)) assertThat(task1).isNotEqualTo(task2) } diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/util/GroupTaskTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/util/GroupTaskTest.kt index fa043b969a..67fc62f772 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/util/GroupTaskTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/util/GroupTaskTest.kt @@ -98,7 +98,7 @@ class GroupTaskTest { @Test fun testGroupTask_differentType_isNotEqual() { val task1 = SingleTask(createTask(1)) - val task2 = DesktopTask(listOf(createTask(1))) + val task2 = DesktopTask(deskId = 0, listOf(createTask(1))) assertThat(task1).isNotEqualTo(task2) }