From 9ce27637d7b5417f30c47a12ff640f9c70a3ebf3 Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Wed, 25 Sep 2024 15:35:05 +0000 Subject: [PATCH] Filter out running pinned app tasks from KeyboardQuickSwitch. - Opening KQS from keyboard shortcuts shows all the tasks. - Opening KQS from taskbar will filter out all the running pinned apps from the list of views. Bug: 368119679 Change-Id: I6090679f9fc359212db00a325917892ae6e1eb39 Test: open KQS via taskbar affordance, obseerve filtered list, use alt + option observe list changes to show all tasks click affordance again, observe list changes back to filtered Flag: com.android.launcher3.taskbar_overflow --- .../KeyboardQuickSwitchController.java | 40 +++++++++++++++---- .../taskbar/TaskbarViewCallbacks.java | 6 ++- .../taskbar/TaskbarViewController.java | 22 ++++++++++ 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java index ea432f3d28..f98245d23e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java @@ -22,6 +22,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; +import com.android.launcher3.Flags; import com.android.launcher3.R; import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext; import com.android.quickstep.RecentsModel; @@ -36,6 +37,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -95,7 +97,21 @@ public final class KeyboardQuickSwitchController implements openQuickSwitchView(-1); } + /** + * Opens the view with a filtered list of tasks. + * @param taskIdsToExclude A list of tasks to exclude in the opened view. + */ + void openQuickSwitchView(@NonNull Set taskIdsToExclude) { + openQuickSwitchView(-1, taskIdsToExclude); + } + + private void openQuickSwitchView(int currentFocusedIndex) { + openQuickSwitchView(currentFocusedIndex, Collections.emptySet()); + } + + private void openQuickSwitchView(int currentFocusedIndex, + @NonNull Set taskIdsToExclude) { if (mQuickSwitchViewController != null) { if (!mQuickSwitchViewController.isCloseAnimationRunning()) { return; @@ -117,7 +133,9 @@ public final class KeyboardQuickSwitchController implements final boolean onDesktop = mControllers.taskbarDesktopModeController.getAreDesktopTasksVisible(); - if (mModel.isTaskListValid(mTaskListChangeId)) { + // TODO(b/368119679) For now we will re-process the task list every time, but this can be + // optimized if we have the same set of task ids to exclude. + if (mModel.isTaskListValid(mTaskListChangeId) && !Flags.taskbarOverflow()) { // When we are opening the KQS with no focus override, check if the first task is // running. If not, focus that first task. mQuickSwitchViewController.openQuickSwitchView( @@ -136,9 +154,9 @@ public final class KeyboardQuickSwitchController implements mHasDesktopTask = false; mWasDesktopTaskFilteredOut = false; if (onDesktop) { - processLoadedTasksOnDesktop(tasks); + processLoadedTasksOnDesktop(tasks, taskIdsToExclude); } else { - processLoadedTasks(tasks); + processLoadedTasks(tasks, taskIdsToExclude); } // Check if the first task is running after the recents model has updated so that we use // the correct index. @@ -154,11 +172,16 @@ public final class KeyboardQuickSwitchController implements }); } - private void processLoadedTasks(List tasks) { + private boolean shouldExcludeTask(GroupTask task, Set taskIdsToExclude) { + return Flags.taskbarOverflow() && taskIdsToExclude.contains(task.task1.key.id); + } + + private void processLoadedTasks(List tasks, Set taskIdsToExclude) { // Only store MAX_TASK tasks, from most to least recent Collections.reverse(tasks); mTasks = tasks.stream() - .filter(task -> !(task instanceof DesktopTask)) + .filter(task -> !(task instanceof DesktopTask) + && !shouldExcludeTask(task, taskIdsToExclude)) .limit(MAX_TASKS) .collect(Collectors.toList()); @@ -176,12 +199,15 @@ public final class KeyboardQuickSwitchController implements tasks.size() - (mWasDesktopTaskFilteredOut ? 1 : 0) - MAX_TASKS); } - private void processLoadedTasksOnDesktop(List tasks) { + private void processLoadedTasksOnDesktop(List tasks, Set taskIdsToExclude) { // Find the single desktop task that contains a grouping of desktop tasks DesktopTask desktopTask = findDesktopTask(tasks); if (desktopTask != null) { - mTasks = desktopTask.tasks.stream().map(GroupTask::new).collect(Collectors.toList()); + mTasks = desktopTask.tasks.stream() + .map(GroupTask::new) + .filter(task -> !shouldExcludeTask(task, taskIdsToExclude)) + .collect(Collectors.toList()); // All other tasks, apart from the grouped desktop task, are hidden mNumHiddenTasks = Math.max(0, tasks.size() - 1); } else { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java index d108d8c357..176be1ce5b 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java @@ -140,7 +140,8 @@ public class TaskbarViewCallbacks { return new View.OnClickListener() { @Override public void onClick(View v) { - mControllers.keyboardQuickSwitchController.openQuickSwitchView(); + mControllers.keyboardQuickSwitchController.openQuickSwitchView( + mControllers.taskbarViewController.getTaskIdsForPinnedApps()); } }; } @@ -150,7 +151,8 @@ public class TaskbarViewCallbacks { return new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - mControllers.keyboardQuickSwitchController.openQuickSwitchView(); + mControllers.keyboardQuickSwitchController.openQuickSwitchView( + mControllers.taskbarViewController.getTaskIdsForPinnedApps()); return true; } }; diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java index b207b37f56..83527ab0e2 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java @@ -18,6 +18,7 @@ package com.android.launcher3.taskbar; import static com.android.app.animation.Interpolators.FINAL_FRAME; import static com.android.app.animation.Interpolators.LINEAR; import static com.android.launcher3.Flags.enableScalingRevealHomeAnimation; +import static com.android.launcher3.Flags.taskbarOverflow; import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY; import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA; import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X; @@ -81,6 +82,9 @@ import com.android.wm.shell.Flags; import com.android.wm.shell.shared.bubbles.BubbleBarLocation; import java.io.PrintWriter; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.function.Predicate; @@ -629,6 +633,24 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar } } + /** + * @return A set of Task ids of running apps that are pinned in the taskbar. + */ + protected Set getTaskIdsForPinnedApps() { + if (!taskbarOverflow()) { + return Collections.emptySet(); + } + + Set pinnedAppsWithTasks = new HashSet<>(); + for (View iconView : getIconViews()) { + if (iconView instanceof BubbleTextView btv + && btv.getTag() instanceof TaskItemInfo itemInfo) { + pinnedAppsWithTasks.add(itemInfo.getTaskId()); + } + } + return pinnedAppsWithTasks; + } + private BubbleTextView.RunningAppState getRunningAppState( BubbleTextView btv, Set runningTaskIds,