From f4a21b7e5c132b6a67c4882f4cc3423911cf6eab Mon Sep 17 00:00:00 2001 From: Jordan Silva Date: Mon, 14 Oct 2024 11:59:18 +0100 Subject: [PATCH] Fix RecentsView crash when DesktopTask has only 1 task and it is in split mode This CL fixes a crash happening when no other task is available in Desktop Windowing (DW), and the only task in DW is selected to be part of the pair (split mode). The crash is happening because of the following logic: - applyLoadPlan skips the staged tasks (for split) from the groupTask when adding the TaskViews to RecentsView. - If a groupTask has multiple tasks, and one of the tasks is staged, groupTask will be treated as a single task and applyLoadPlan uses the other task (not staged) to create a single TaskView in Overview. - DesktopTasks returns true for hasMultipleTasks, even when only 1 task is in DW mode. This causes a crash when the only task available in DW is staged for split. This fix will skip DesktopTaskView creation when split selection is active. In addition, it updates DesktopTask to report multiple tasks only when more than 1 task is its task list. Fix: 372357270 Fix: 372375086 Fix: 372864249 Flag: EXEMPT bugfix Test: Manual. Instructions on bug report. Change-Id: I95e32252a5cac4f6b99296422703d69d129a5a47 --- .../taskbar/TaskbarRecentAppsController.kt | 2 +- .../com/android/launcher3/taskbar/TaskbarView.java | 6 +++--- .../src/com/android/quickstep/util/DesktopTask.java | 5 +++++ .../src/com/android/quickstep/util/GroupTask.java | 7 +++++++ .../com/android/quickstep/views/RecentsView.java | 13 ++++++++----- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarRecentAppsController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarRecentAppsController.kt index 9c34ff0eb8..3e8b615b69 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarRecentAppsController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarRecentAppsController.kt @@ -251,7 +251,7 @@ class TaskbarRecentAppsController(context: Context, private val recentsModel: Re // Remove any newly-missing Tasks, and actual group-tasks val newShownTasks = shownTasks - .filter { !it.hasMultipleTasks() } + .filter { !it.supportsMultipleTasks() } .filter { it.task1.key.id in desktopTaskIds } .toMutableList() // Add any new Tasks, maintaining the order from previous shownTasks. diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java index ec9416017e..081100c0ee 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java @@ -65,8 +65,8 @@ import com.android.launcher3.util.LauncherBindableItemsContainer; import com.android.launcher3.util.Themes; import com.android.launcher3.views.ActivityContext; import com.android.launcher3.views.IconButtonView; -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; import com.android.wm.shell.shared.bubbles.BubbleBarLocation; @@ -453,8 +453,8 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar // Replace any Recent views with the appropriate type if it's not already that type. final int expectedLayoutResId; boolean isCollection = false; - if (task.hasMultipleTasks()) { - if (task instanceof DesktopTask) { + if (task.supportsMultipleTasks()) { + if (task.taskViewType == TaskViewType.DESKTOP) { // TODO(b/316004172): use Desktop tile layout. expectedLayoutResId = -1; } else { diff --git a/quickstep/src/com/android/quickstep/util/DesktopTask.java b/quickstep/src/com/android/quickstep/util/DesktopTask.java index a727aa2efb..fc4fc4df78 100644 --- a/quickstep/src/com/android/quickstep/util/DesktopTask.java +++ b/quickstep/src/com/android/quickstep/util/DesktopTask.java @@ -50,6 +50,11 @@ public class DesktopTask extends GroupTask { @Override public boolean hasMultipleTasks() { + return tasks.size() > 1; + } + + @Override + public boolean supportsMultipleTasks() { return true; } diff --git a/quickstep/src/com/android/quickstep/util/GroupTask.java b/quickstep/src/com/android/quickstep/util/GroupTask.java index fba08a96b2..7aeeb2fc32 100644 --- a/quickstep/src/com/android/quickstep/util/GroupTask.java +++ b/quickstep/src/com/android/quickstep/util/GroupTask.java @@ -65,6 +65,13 @@ public class GroupTask { return task2 != null; } + /** + * Returns whether this task supports multiple tasks or not. + */ + public boolean supportsMultipleTasks() { + return taskViewType == TaskViewType.GROUPED; + } + /** * Returns a List of all the Tasks in this GroupTask */ diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 7554c4496a..e84aabcf1c 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -1885,19 +1885,22 @@ public abstract class RecentsView< // taskGroups backwards populates the thumbnail grid from least recent to most recent. for (int i = taskGroups.size() - 1; i >= 0; i--) { GroupTask groupTask = taskGroups.get(i); - boolean isRemovalNeeded = stagedTaskIdToBeRemoved != INVALID_TASK_ID + boolean containsStagedTask = stagedTaskIdToBeRemoved != INVALID_TASK_ID && groupTask.containsTask(stagedTaskIdToBeRemoved); + boolean shouldSkipGroupTask = containsStagedTask && !groupTask.hasMultipleTasks(); - if (isRemovalNeeded && !groupTask.hasMultipleTasks()) { - // If the task we need to remove is not part of a pair, avoiding creating the - // TaskView. + if ((isSplitSelectionActive() && groupTask.taskViewType == TaskViewType.DESKTOP) + || shouldSkipGroupTask) { + // To avoid these tasks from being chosen as the app pair, the creation of a + // TaskView is bypassed. The staged task is already selected for the app pair, + // and the Desktop task should be hidden when selecting a pair. continue; } // If we need to remove half of a pair of tasks, force a TaskView with Type.SINGLE // to be a temporary container for the remaining task. TaskView taskView = getTaskViewFromPool( - isRemovalNeeded ? TaskViewType.SINGLE : groupTask.taskViewType); + containsStagedTask ? TaskViewType.SINGLE : groupTask.taskViewType); if (taskView instanceof GroupedTaskView) { boolean firstTaskIsLeftTopTask = groupTask.mSplitBounds.leftTopTaskId == groupTask.task1.key.id;