Get displayId from DesktopTask for DesktopTaskView

Bug: 401011627
Flag: com.android.window.flags.enable_multiple_desktops_frontend
Flag: com.android.window.flags.enable_multiple_desktops_backend
Test: Added a test in RecentTasksListTest
Change-Id: I21164de812d57b79cd84370bbf0426268c4b645d
This commit is contained in:
minch committed 2025-03-13 22:24:22 +00:00
1 parent 837e576c56
commit 68e116e79f
12 files changed
+127 -36

No files matched your search

@@ -511,13 +511,14 @@ public class RecentTasksList implements WindowManagerProxy.DesktopVisibilityList
// 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 -> new DesktopTask(DesktopVisibilityController.INACTIVE_DESK_ID, it.getKey(),
it.getValue()));
} else {
final int deskId = recentTaskInfo.getDeskId();
final int displayId = recentTaskInfo.getDeskDisplayId();
List<Task> tasks = CollectionsKt.map(recentTaskInfo.getTaskInfoList(),
it -> createTask(it, minimizedTaskIds));
return List.of(new DesktopTask(deskId, tasks));
return List.of(new DesktopTask(deskId, displayId, tasks));
}
}
@@ -17,22 +17,27 @@ package com.android.quickstep.util
import com.android.quickstep.views.TaskViewType
import com.android.systemui.shared.recents.model.Task
import java.util.Objects
/**
* 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. The [deskId] makes sense only
* when the multiple desks feature is enabled.
* tasks list. Note that desktops can be empty with no tasks in them. The [deskId], [displayId]
* makes sense only when the multiple desks feature is enabled.
*/
class DesktopTask(val deskId: Int, tasks: List<Task>) : GroupTask(tasks, TaskViewType.DESKTOP) {
class DesktopTask(val deskId: Int, val displayId: Int, tasks: List<Task>) :
GroupTask(tasks, TaskViewType.DESKTOP) {
override fun copy() = DesktopTask(deskId, tasks)
override fun copy() = DesktopTask(deskId, displayId, tasks)
override fun toString() = "type=$taskViewType deskId=$deskId tasks=$tasks"
override fun toString() = "type=$taskViewType deskId=$deskId displayId=$displayId 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
if (displayId != o.displayId) return false
return super.equals(o)
}
override fun hashCode() = Objects.hash(super.hashCode(), deskId, displayId)
}
@@ -86,6 +86,8 @@ class SingleTask(task: Task) : GroupTask(listOf(task), TaskViewType.SINGLE) {
return TaskItemInfo(task.task.key.id, wii)
}
}
override fun hashCode() = super.hashCode()
}
/**
@@ -25,6 +25,7 @@ import android.graphics.RectF
import android.util.AttributeSet
import android.util.Log
import android.util.Size
import android.view.Display.INVALID_DISPLAY
import android.view.Gravity
import android.view.View
import android.view.ViewStub
@@ -59,6 +60,7 @@ import com.android.quickstep.task.thumbnail.TaskContentView
import com.android.quickstep.task.thumbnail.TaskThumbnailView
import com.android.quickstep.util.DesktopTask
import com.android.quickstep.util.RecentsOrientedState
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus.enableMultipleDesktops
import kotlin.math.roundToInt
/** TaskView that contains all tasks that are part of the desktop. */
@@ -69,7 +71,10 @@ class DesktopTaskView @JvmOverloads constructor(context: Context, attrs: Attribu
type = TaskViewType.DESKTOP,
thumbnailFullscreenParams = DesktopFullscreenDrawParams(context),
) {
var deskId = DesktopVisibilityController.INACTIVE_DESK_ID
val deskId
get() = desktopTask?.deskId ?: DesktopVisibilityController.INACTIVE_DESK_ID
private var desktopTask: DesktopTask? = null
private val contentViewFullscreenParams = FullscreenDrawParams(context)
@@ -112,6 +117,14 @@ class DesktopTaskView @JvmOverloads constructor(context: Context, attrs: Attribu
positionTaskWindows()
}
override val displayId: Int
get() =
if (enableMultipleDesktops(context)) {
desktopTask?.displayId ?: INVALID_DISPLAY
} else {
super.displayId
}
private fun getRemoteTargetHandle(taskId: Int): RemoteTargetHandle? =
remoteTargetHandles?.firstOrNull {
it.transformParams.targetSet.firstAppTargetTaskId == taskId
@@ -284,7 +297,7 @@ class DesktopTaskView @JvmOverloads constructor(context: Context, attrs: Attribu
orientedState: RecentsOrientedState,
taskOverlayFactory: TaskOverlayFactory,
) {
deskId = desktopTask.deskId
this.desktopTask = desktopTask
// TODO(b/370495260): Minimized tasks should not be filtered with desktop exploded view
// support.
// Minimized tasks should not be shown in Overview.
@@ -336,7 +349,7 @@ class DesktopTaskView @JvmOverloads constructor(context: Context, attrs: Attribu
override fun onRecycle() {
super.onRecycle()
deskId = DesktopVisibilityController.INACTIVE_DESK_ID
desktopTask = null
explodeProgress = 0.0f
viewModel = null
visibility = VISIBLE
@@ -142,7 +142,6 @@ import androidx.annotation.UiThread;
import androidx.core.graphics.ColorUtils;
import androidx.dynamicanimation.animation.SpringAnimation;
import com.android.app.tracing.TraceUtilsKt;
import com.android.internal.jank.Cuj;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseActivity.MultiWindowModeChangedListener;
@@ -3121,7 +3120,8 @@ public abstract class RecentsView<
// TODO: b/401582344 - Implement a way to exclude the `DesktopWallpaperActivity`.
desktopTaskView.bind(
new DesktopTask(activeDeskId, Arrays.asList(runningTasks)),
new DesktopTask(activeDeskId, mContainer.getDisplayId(),
Arrays.asList(runningTasks)),
mOrientationState, mTaskOverlayFactory);
return desktopTaskView;
}
@@ -7026,7 +7026,7 @@ public abstract class RecentsView<
// `AddNewDesktopButton`.
DesktopTaskView desktopTaskView =
(DesktopTaskView) getTaskViewFromPool(TaskViewType.DESKTOP);
desktopTaskView.bind(new DesktopTask(deskId, new ArrayList<>()),
desktopTaskView.bind(new DesktopTask(deskId, displayId, new ArrayList<>()),
mOrientationState, mTaskOverlayFactory);
Objects.requireNonNull(mAddDesktopButton);
@@ -146,7 +146,7 @@ constructor(
val isRunningTask: Boolean
get() = this === recentsView?.runningTaskView
val displayId: Int
open val displayId: Int
get() = taskContainers.firstOrNull()?.task.displayId
val isExternalDisplay: Boolean
@@ -1484,10 +1484,11 @@ constructor(
}
private fun closeTaskMenu(): Boolean {
val floatingView: AbstractFloatingView? = AbstractFloatingView.getTopOpenViewWithType(
container,
AbstractFloatingView.TYPE_TASK_MENU
)
val floatingView: AbstractFloatingView? =
AbstractFloatingView.getTopOpenViewWithType(
container,
AbstractFloatingView.TYPE_TASK_MENU,
)
if (floatingView?.isOpen == true) {
floatingView.close(true)
return true
@@ -23,6 +23,7 @@ import android.os.Process
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import android.view.Display.DEFAULT_DISPLAY
import androidx.test.core.app.ApplicationProvider
import com.android.launcher3.Flags.FLAG_ENABLE_MULTI_INSTANCE_MENU_TASKBAR
import com.android.launcher3.Flags.FLAG_TASKBAR_OVERFLOW
@@ -446,7 +447,7 @@ class TaskbarOverflowTest {
)
})
recentsModel.updateRecentTasks(listOf(DesktopTask(deskId = 0, tasks)))
recentsModel.updateRecentTasks(listOf(DesktopTask(deskId = 0, DEFAULT_DISPLAY, tasks)))
for (task in 1..tasks.size) {
desktopTaskListener?.onTasksVisibilityChanged(
context.virtualDisplay.display.displayId,
@@ -25,6 +25,7 @@ import android.graphics.Rect
import android.os.Process
import android.os.UserHandle
import android.platform.test.annotations.EnableFlags
import android.view.Display.DEFAULT_DISPLAY
import androidx.test.annotation.UiThreadTest
import com.android.internal.R
import com.android.launcher3.BubbleTextView.RunningAppState
@@ -877,7 +878,7 @@ class TaskbarRecentAppsControllerTest : TaskbarBaseTestCase() {
val allTasks =
ArrayList<GroupTask>().apply {
if (!runningTasks.isEmpty()) {
add(DesktopTask(deskId = 0, ArrayList(runningTasks)))
add(DesktopTask(deskId = 0, DEFAULT_DISPLAY, ArrayList(runningTasks)))
}
addAll(recentTasks)
}
@@ -52,6 +52,7 @@ import com.android.internal.R;
import com.android.launcher3.statehandlers.DesktopVisibilityController;
import com.android.launcher3.util.DaggerSingletonTracker;
import com.android.launcher3.util.LooperExecutor;
import com.android.quickstep.util.DesktopTask;
import com.android.quickstep.util.GroupTask;
import com.android.quickstep.views.TaskViewType;
import com.android.systemui.shared.recents.model.Task;
@@ -147,6 +148,66 @@ public class RecentTasksListTest {
assertThat(taskList).isEmpty();
}
@Test
@EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
public void loadTasksInBackground_freeformTask_multiDesksInMultiDisplays() throws Exception {
List<TaskInfo> tasksInDefaultDesk1 = Arrays.asList(
createRecentTaskInfo(/* taskId = */ 1, DEFAULT_DISPLAY),
createRecentTaskInfo(/* taskId = */ 4, DEFAULT_DISPLAY));
List<TaskInfo> tasksInDefaultDesk2 = Arrays.asList(
createRecentTaskInfo(/* taskId = */ 2, DEFAULT_DISPLAY),
createRecentTaskInfo(/* taskId = */ 3, DEFAULT_DISPLAY));
List<TaskInfo> tasksInExtend = Arrays.asList(
createRecentTaskInfo(/* taskId = */ 5, /* displayId = */ 1),
createRecentTaskInfo(/* taskId = */ 6, /* displayId = */ 1));
GroupedTaskInfo recentTaskInfosOfDesk1 = GroupedTaskInfo.forDeskTasks(/* deskId = */1,
DEFAULT_DISPLAY, tasksInDefaultDesk1, /* minimizedTaskIds = */
Collections.emptySet());
GroupedTaskInfo recentTaskInfosOfDesk2 = GroupedTaskInfo.forDeskTasks(/* deskId = */2,
DEFAULT_DISPLAY, tasksInDefaultDesk2, /* minimizedTaskIds = */
Collections.emptySet());
GroupedTaskInfo recentTaskInfosOfDesk3 = GroupedTaskInfo.forDeskTasks(/* deskId = */3,
/* displayId = */ 1, tasksInExtend, /* minimizedTaskIds = */
Collections.emptySet());
when(mSystemUiProxy.getRecentTasks(anyInt(), anyInt())).thenReturn(
new ArrayList<>(Arrays.asList(recentTaskInfosOfDesk1, recentTaskInfosOfDesk2,
recentTaskInfosOfDesk3)));
List<GroupTask> taskList = mRecentTasksList.loadTasksInBackground(Integer.MAX_VALUE, -1,
false);
assertThat(taskList).hasSize(3);
assertThat(taskList.get(2).taskViewType).isEqualTo(TaskViewType.DESKTOP);
List<Task> actualFreeformTasksInDesk1 = taskList.get(2).getTasks();
assertThat(actualFreeformTasksInDesk1).hasSize(2);
assertThat(actualFreeformTasksInDesk1.get(0).key.id).isEqualTo(1);
assertThat(actualFreeformTasksInDesk1.get(0).isMinimized).isFalse();
assertThat(actualFreeformTasksInDesk1.get(1).key.id).isEqualTo(4);
assertThat(actualFreeformTasksInDesk1.get(1).isMinimized).isFalse();
assertThat(((DesktopTask) taskList.get(2)).getDeskId()).isEqualTo(1);
assertThat(((DesktopTask) taskList.get(2)).getDisplayId()).isEqualTo(DEFAULT_DISPLAY);
assertThat(taskList.get(1).taskViewType).isEqualTo(TaskViewType.DESKTOP);
List<Task> actualFreeformTasksInDesk2 = taskList.get(1).getTasks();
assertThat(actualFreeformTasksInDesk2).hasSize(2);
assertThat(actualFreeformTasksInDesk2.get(0).key.id).isEqualTo(2);
assertThat(actualFreeformTasksInDesk2.get(0).isMinimized).isFalse();
assertThat(actualFreeformTasksInDesk2.get(1).key.id).isEqualTo(3);
assertThat(actualFreeformTasksInDesk2.get(1).isMinimized).isFalse();
assertThat(((DesktopTask) taskList.get(1)).getDeskId()).isEqualTo(2);
assertThat(((DesktopTask) taskList.get(1)).getDisplayId()).isEqualTo(DEFAULT_DISPLAY);
assertThat(taskList.get(0).taskViewType).isEqualTo(TaskViewType.DESKTOP);
List<Task> actualFreeformTasksInDesk3 = taskList.get(0).getTasks();
assertThat(actualFreeformTasksInDesk3).hasSize(2);
assertThat(actualFreeformTasksInDesk3.get(0).key.id).isEqualTo(5);
assertThat(actualFreeformTasksInDesk3.get(0).isMinimized).isFalse();
assertThat(actualFreeformTasksInDesk3.get(1).key.id).isEqualTo(6);
assertThat(actualFreeformTasksInDesk3.get(1).isMinimized).isFalse();
assertThat(((DesktopTask) taskList.get(0)).getDeskId()).isEqualTo(3);
assertThat(((DesktopTask) taskList.get(0)).getDisplayId()).isEqualTo(1);
}
@Test
public void loadTasksInBackground_moreThanKeys_hasValidTaskDescription() throws Exception {
String taskDescription = "Wheeee!";
@@ -175,7 +236,8 @@ public class RecentTasksListTest {
}
@Test
@DisableFlags(FLAG_ENABLE_SEPARATE_EXTERNAL_DISPLAY_TASKS)
@DisableFlags({FLAG_ENABLE_SEPARATE_EXTERNAL_DISPLAY_TASKS,
FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND})
public void loadTasksInBackground_freeformTask_createsDesktopTask() throws Exception {
List<TaskInfo> tasks = Arrays.asList(
createRecentTaskInfo(1 /* taskId */, DEFAULT_DISPLAY),
@@ -183,7 +245,8 @@ public class RecentTasksListTest {
createRecentTaskInfo(5 /* taskId */, 1 /* displayId */),
createRecentTaskInfo(6 /* taskId */, 1 /* displayId */));
GroupedTaskInfo recentTaskInfos = GroupedTaskInfo.forDeskTasks(
0 /* deskId */, tasks, Collections.emptySet() /* minimizedTaskIds */);
0 /* deskId */, DEFAULT_DISPLAY, tasks,
Collections.emptySet() /* minimizedTaskIds */);
when(mSystemUiProxy.getRecentTasks(anyInt(), anyInt()))
.thenReturn(new ArrayList<>(Collections.singletonList(recentTaskInfos)));
@@ -214,7 +277,8 @@ public class RecentTasksListTest {
createRecentTaskInfo(5 /* taskId */, 1 /* displayId */),
createRecentTaskInfo(6 /* taskId */, 1 /* displayId */));
GroupedTaskInfo recentTaskInfos = GroupedTaskInfo.forDeskTasks(
0 /* deskId */, tasks, Collections.emptySet() /* minimizedTaskIds */);
0 /* deskId */, DEFAULT_DISPLAY, tasks,
Collections.emptySet() /* minimizedTaskIds */);
when(mSystemUiProxy.getRecentTasks(anyInt(), anyInt()))
.thenReturn(new ArrayList<>(Collections.singletonList(recentTaskInfos)));
@@ -248,7 +312,7 @@ public class RecentTasksListTest {
Set<Integer> minimizedTaskIds =
Arrays.stream(new Integer[]{1, 4, 5}).collect(Collectors.toSet());
GroupedTaskInfo recentTaskInfos = GroupedTaskInfo.forDeskTasks(
0 /* deskId */, tasks, minimizedTaskIds);
0 /* deskId */, DEFAULT_DISPLAY, tasks, minimizedTaskIds);
when(mSystemUiProxy.getRecentTasks(anyInt(), anyInt()))
.thenReturn(new ArrayList<>(Collections.singletonList(recentTaskInfos)));
@@ -21,6 +21,7 @@ import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.view.Display.DEFAULT_DISPLAY
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.launcher3.util.SplitConfigurationOptions
import com.android.launcher3.util.TestDispatcherProvider
@@ -64,7 +65,7 @@ class TasksRepositoryTest {
/* snapPosition = */ SNAP_TO_2_50_50,
),
),
DesktopTask(deskId = 0, tasks.subList(3, 6)),
DesktopTask(deskId = 0, DEFAULT_DISPLAY, tasks.subList(3, 6)),
)
private val recentsModel = FakeRecentTasksDataSource()
private val taskThumbnailDataSource = FakeTaskThumbnailDataSource()
@@ -18,6 +18,7 @@ package com.android.quickstep.util
import android.content.ComponentName
import android.content.Intent
import android.view.Display.DEFAULT_DISPLAY
import com.android.launcher3.util.LauncherMultivalentJUnit
import com.android.systemui.shared.recents.model.Task
import com.google.common.truth.Truth.assertThat
@@ -29,42 +30,42 @@ class DesktopTaskTest {
@Test
fun testDesktopTask_sameInstance_isEqual() {
val task = DesktopTask(deskId = 0, createTasks(1))
val task = DesktopTask(deskId = 0, DEFAULT_DISPLAY, createTasks(1))
assertThat(task).isEqualTo(task)
}
@Test
fun testDesktopTask_identicalConstructor_isEqual() {
val task1 = DesktopTask(deskId = 0, createTasks(1))
val task2 = DesktopTask(deskId = 0, createTasks(1))
val task1 = DesktopTask(deskId = 0, DEFAULT_DISPLAY, createTasks(1))
val task2 = DesktopTask(deskId = 0, DEFAULT_DISPLAY, createTasks(1))
assertThat(task1).isEqualTo(task2)
}
@Test
fun testDesktopTask_copy_isEqual() {
val task1 = DesktopTask(deskId = 0, createTasks(1))
val task1 = DesktopTask(deskId = 0, DEFAULT_DISPLAY, createTasks(1))
val task2 = task1.copy()
assertThat(task1).isEqualTo(task2)
}
@Test
fun testDesktopTask_differentDeskIds_isNotEqual() {
val task1 = DesktopTask(deskId = 0, createTasks(1))
val task2 = DesktopTask(deskId = 1, createTasks(1))
val task1 = DesktopTask(deskId = 0, DEFAULT_DISPLAY, createTasks(1))
val task2 = DesktopTask(deskId = 1, DEFAULT_DISPLAY, 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))
val task1 = DesktopTask(deskId = 0, DEFAULT_DISPLAY, createTasks(1))
val task2 = DesktopTask(deskId = 0, DEFAULT_DISPLAY, createTasks(2))
assertThat(task1).isNotEqualTo(task2)
}
@Test
fun testDesktopTask_differentLength_isNotEqual() {
val task1 = DesktopTask(deskId = 0, createTasks(1))
val task2 = DesktopTask(deskId = 0, createTasks(1, 2))
val task1 = DesktopTask(deskId = 0, DEFAULT_DISPLAY, createTasks(1))
val task2 = DesktopTask(deskId = 0, DEFAULT_DISPLAY, createTasks(1, 2))
assertThat(task1).isNotEqualTo(task2)
}
@@ -19,6 +19,7 @@ package com.android.quickstep.util
import android.content.ComponentName
import android.content.Intent
import android.graphics.Rect
import android.view.Display.DEFAULT_DISPLAY
import com.android.launcher3.util.LauncherMultivalentJUnit
import com.android.launcher3.util.SplitConfigurationOptions
import com.android.systemui.shared.recents.model.Task
@@ -98,7 +99,7 @@ class GroupTaskTest {
@Test
fun testGroupTask_differentType_isNotEqual() {
val task1 = SingleTask(createTask(1))
val task2 = DesktopTask(deskId = 0, listOf(createTask(1)))
val task2 = DesktopTask(deskId = 0, DEFAULT_DISPLAY, listOf(createTask(1)))
assertThat(task1).isNotEqualTo(task2)
}