Introduce SingleTask and SplitTask

See go/refactor-group-task for details. This CL introduces `SingleTask`
and `SplitTask` and makes `GroupTask` abstract.

Bug: 388593902
Test: m
Flag: EXEMPT pure refactor with no behavior change.
Change-Id: I96d0eb0600420ce5cb2fff30ed9d766224b6961e
This commit is contained in:
Ahmed Fakhry committed 2025-01-23 23:48:01 +00:00
1 parent 71cbc13214
commit f87e44376b
16 files changed
+197 -91

No files matched your search

@@ -32,6 +32,7 @@ import com.android.quickstep.RecentsModel;
import com.android.quickstep.util.DesktopTask;
import com.android.quickstep.util.GroupTask;
import com.android.quickstep.util.LayoutUtils;
import com.android.quickstep.util.SingleTask;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.system.ActivityManagerWrapper;
@@ -270,7 +271,7 @@ public final class KeyboardQuickSwitchController implements
if (desktopTask != null) {
mTasks = desktopTask.getTasks().stream()
.map(GroupTask::new)
.map(SingleTask::new)
.filter(task -> !shouldExcludeTask(task, taskIdsToExclude))
.collect(Collectors.toList());
// All other tasks, apart from the grouped desktop task, are hidden
@@ -29,6 +29,7 @@ import com.android.launcher3.util.CancellableTask
import com.android.quickstep.RecentsModel
import com.android.quickstep.util.DesktopTask
import com.android.quickstep.util.GroupTask
import com.android.quickstep.util.SingleTask
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import java.io.PrintWriter
@@ -204,7 +205,7 @@ class TaskbarRecentAppsController(context: Context, private val recentsModel: Re
// Kind of hacky, we wrap each single task in the Desktop as a GroupTask.
val orderFromId = orderedRunningTaskIds.withIndex().associate { (index, id) -> id to index }
val sortedTasks = tasks.sortedWith(compareBy(nullsLast()) { orderFromId[it.key.id] })
return sortedTasks.map { GroupTask(it) }
return sortedTasks.map { SingleTask(it) }
}
private fun reloadRecentTasksIfNeeded() {
@@ -39,6 +39,8 @@ import com.android.launcher3.util.LooperExecutor;
import com.android.launcher3.util.SplitConfigurationOptions;
import com.android.quickstep.util.DesktopTask;
import com.android.quickstep.util.GroupTask;
import com.android.quickstep.util.SingleTask;
import com.android.quickstep.util.SplitTask;
import com.android.systemui.shared.recents.model.Task;
import com.android.wm.shell.Flags;
import com.android.wm.shell.recents.IRecentTasksListener;
@@ -50,6 +52,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -360,22 +363,19 @@ public class RecentTasksList {
final Task.TaskKey task1Key = new Task.TaskKey(taskInfo1);
final Task task1 = Task.from(task1Key, taskInfo1,
tmpLockedUsers.get(task1Key.userId) /* isLocked */);
final Task task2;
final SplitConfigurationOptions.SplitBounds launcherSplitBounds;
if (rawTask.isBaseType(TYPE_SPLIT)) {
final TaskInfo taskInfo2 = rawTask.getBaseGroupedTask().getTaskInfo2();
final Task.TaskKey task2Key = new Task.TaskKey(taskInfo2);
task2 = Task.from(task2Key, taskInfo2,
final Task task2 = Task.from(task2Key, taskInfo2,
tmpLockedUsers.get(task2Key.userId) /* isLocked */);
launcherSplitBounds =
final SplitConfigurationOptions.SplitBounds launcherSplitBounds =
convertShellSplitBoundsToLauncher(
rawTask.getBaseGroupedTask().getSplitBounds());
allTasks.add(new SplitTask(task1, task2, launcherSplitBounds));
} else {
task2 = null;
launcherSplitBounds = null;
allTasks.add(new SingleTask(task1));
}
allTasks.add(new GroupTask(task1, task2, launcherSplitBounds));
} else {
TaskInfo taskInfo1 = rawTask.getTaskInfo1();
TaskInfo taskInfo2 = rawTask.getTaskInfo2();
@@ -407,9 +407,14 @@ public class RecentTasksList {
if (taskInfo1.isVisible) {
numVisibleTasks++;
}
final SplitConfigurationOptions.SplitBounds launcherSplitBounds =
convertShellSplitBoundsToLauncher(rawTask.getSplitBounds());
allTasks.add(new GroupTask(task1, task2, launcherSplitBounds));
if (task2 != null) {
Objects.requireNonNull(rawTask.getSplitBounds());
final SplitConfigurationOptions.SplitBounds launcherSplitBounds =
convertShellSplitBoundsToLauncher(rawTask.getSplitBounds());
allTasks.add(new SplitTask(task1, task2, launcherSplitBounds));
} else {
allTasks.add(new SingleTask(task1));
}
}
}
@@ -142,7 +142,9 @@ public class RemoteTargetGluer {
if (mSplitBounds == null) {
SplitBounds shellSplitBounds = targets.extras.getParcelable(KEY_EXTRA_SPLIT_BOUNDS,
SplitBounds.class);
mSplitBounds = convertShellSplitBoundsToLauncher(shellSplitBounds);
if (shellSplitBounds != null) {
mSplitBounds = convertShellSplitBoundsToLauncher(shellSplitBounds);
}
}
boolean containsSplitTargets = mSplitBounds != null;
@@ -33,7 +33,6 @@ import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.Flags;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.desktop.DesktopRecentsTransitionController;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.statehandlers.DesktopVisibilityController;
@@ -47,6 +46,7 @@ import com.android.quickstep.FallbackActivityInterface;
import com.android.quickstep.GestureState;
import com.android.quickstep.fallback.window.RecentsDisplayModel;
import com.android.quickstep.util.GroupTask;
import com.android.quickstep.util.SingleTask;
import com.android.quickstep.util.SplitSelectStateController;
import com.android.quickstep.util.TaskViewSimulator;
import com.android.quickstep.views.OverviewActionsView;
@@ -210,7 +210,7 @@ public class FallbackRecentsView<CONTAINER_TYPE extends Context & RecentsViewCon
if (!found) {
ArrayList<GroupTask> newList = new ArrayList<>(taskGroups.size() + 1);
newList.addAll(taskGroups);
newList.add(new GroupTask(mHomeTask, null, null));
newList.add(new SingleTask(mHomeTask));
taskGroups = newList;
}
}
@@ -17,7 +17,6 @@ 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
@@ -39,9 +38,6 @@ class DesktopTask(override val tasks: List<Task>) :
override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o !is DesktopTask) return false
if (!super.equals(o)) return false
return tasks == o.tasks
return super.equals(o)
}
override fun hashCode() = Objects.hash(super.hashCode(), tasks)
}
@@ -22,10 +22,10 @@ import com.android.systemui.shared.recents.model.Task
import java.util.Objects
/**
* A [Task] container that can contain one or two tasks, depending on if the two tasks are
* represented as an app-pair in the recents task list.
* An abstract class for creating [Task] containers that can be [SingleTask]s, [SplitTask]s, or
* [DesktopTask]s in the recent tasks list.
*/
open class GroupTask
abstract class GroupTask
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
constructor(
@Deprecated("Prefer using `getTasks()` instead") @JvmField val task1: Task,
@@ -33,13 +33,16 @@ constructor(
@JvmField val mSplitBounds: SplitConfigurationOptions.SplitBounds?,
@JvmField val taskViewType: TaskViewType,
) {
constructor(task: Task) : this(task, null, null)
constructor(
t1: Task,
t2: Task?,
protected constructor(
task1: Task,
task2: Task?,
splitBounds: SplitConfigurationOptions.SplitBounds?,
) : this(t1, t2, splitBounds, if (t2 != null) TaskViewType.GROUPED else TaskViewType.SINGLE)
) : this(
task1,
task2,
splitBounds,
if (task2 != null) TaskViewType.GROUPED else TaskViewType.SINGLE,
)
open fun containsTask(taskId: Int) =
task1.key.id == taskId || (task2 != null && task2.key.id == taskId)
@@ -59,18 +62,50 @@ constructor(
get() = listOfNotNull(task1, task2)
/** Creates a copy of this instance */
open fun copy() = GroupTask(Task(task1), if (task2 != null) Task(task2) else null, mSplitBounds)
abstract fun copy(): GroupTask
override fun toString() = "type=$taskViewType task1=$task1 task2=$task2"
override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o !is GroupTask) return false
return taskViewType == o.taskViewType &&
task1 == o.task1 &&
task2 == o.task2 &&
mSplitBounds == o.mSplitBounds
return taskViewType == o.taskViewType && tasks == o.tasks
}
override fun hashCode() = Objects.hash(task1, task2, mSplitBounds, taskViewType)
override fun hashCode() = Objects.hash(tasks, taskViewType)
}
/** A [Task] container that must contain exactly one task in the recent tasks list. */
class SingleTask(task: Task) :
GroupTask(task, task2 = null, mSplitBounds = null, TaskViewType.SINGLE) {
override fun copy() = SingleTask(task1)
override fun toString() = "type=$taskViewType task=$task1"
override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o !is SingleTask) return false
return super.equals(o)
}
}
/**
* A [Task] container that must contain exactly two tasks and split bounds to represent an app-pair
* in the recent tasks list.
*/
class SplitTask(task1: Task, task2: Task, splitBounds: SplitConfigurationOptions.SplitBounds) :
GroupTask(task1, task2, splitBounds, TaskViewType.GROUPED) {
override fun copy() = SplitTask(task1, task2!!, mSplitBounds!!)
override fun toString() = "type=$taskViewType task1=$task1 task2=$task2"
override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o !is SplitTask) return false
if (mSplitBounds!! != o.mSplitBounds!!) return false
return super.equals(o)
}
override fun hashCode() = Objects.hash(super.hashCode(), mSplitBounds)
}
@@ -33,38 +33,34 @@ class SplitScreenUtils {
// TODO(b/254378592): Remove these methods when the two classes are reunited
/** Converts the shell version of SplitBounds to the launcher version */
@JvmStatic
fun convertShellSplitBoundsToLauncher(
shellSplitBounds: SplitBounds?
): SplitConfigurationOptions.SplitBounds? {
return if (shellSplitBounds == null) {
null
} else {
SplitConfigurationOptions.SplitBounds(
shellSplitBounds.leftTopBounds,
shellSplitBounds.rightBottomBounds,
shellSplitBounds.leftTopTaskId,
shellSplitBounds.rightBottomTaskId,
shellSplitBounds.snapPosition
)
}
}
fun convertShellSplitBoundsToLauncher(shellSplitBounds: SplitBounds) =
SplitConfigurationOptions.SplitBounds(
shellSplitBounds.leftTopBounds,
shellSplitBounds.rightBottomBounds,
shellSplitBounds.leftTopTaskId,
shellSplitBounds.rightBottomTaskId,
shellSplitBounds.snapPosition,
)
/**
* Given a TransitionInfo, generates the tree structure for those changes and extracts out
* the top most root and it's two immediate children.
* Changes can be provided in any order.
* the top most root and it's two immediate children. Changes can be provided in any order.
*
* @return a [Pair] where first -> top most split root,
* second -> [List] of 2, leftTop/bottomRight stage roots
* @return a [Pair] where first -> top most split root, second -> [List] of 2,
* leftTop/bottomRight stage roots
*/
fun extractTopParentAndChildren(transitionInfo: TransitionInfo):
Pair<Change, List<Change>>? {
fun extractTopParentAndChildren(
transitionInfo: TransitionInfo
): Pair<Change, List<Change>>? {
val parentToChildren = mutableMapOf<Change, MutableList<Change>>()
val hasParent = mutableSetOf<Change>()
// filter out anything that isn't opening and the divider
val taskChanges: List<Change> = transitionInfo.changes
.filter { change -> (change.mode == TRANSIT_OPEN ||
change.mode == TRANSIT_TO_FRONT) && change.flags < FLAG_FIRST_CUSTOM}
val taskChanges: List<Change> =
transitionInfo.changes
.filter { change ->
(change.mode == TRANSIT_OPEN || change.mode == TRANSIT_TO_FRONT) &&
change.flags < FLAG_FIRST_CUSTOM
}
.toList()
// 1. Build Parent-Child Relationships
@@ -73,8 +69,8 @@ class SplitScreenUtils {
// startAnimation() and we can know the precise taskIds of launching tasks.
change.parent?.let { parent ->
parentToChildren
.getOrPut(transitionInfo.getChange(parent)!!) { mutableListOf() }
.add(change)
.getOrPut(transitionInfo.getChange(parent)!!) { mutableListOf() }
.add(change)
hasParent.add(change)
}
}