Merge "Update alt+tab behaviour for projected mode" into main

This commit is contained in:
Treehugger Robot authored and Android (Google) Code Review committed 2025-06-02 12:57:36 -07:00
commit 0ff51ee214
3 files changed
+40 -12

No files matched your search

@@ -42,6 +42,7 @@ 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;
import com.android.wm.shell.shared.desktopmode.DesktopState;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -66,9 +67,6 @@ public final class KeyboardQuickSwitchController implements
// Callback used to notify when the KQS view is closed.
@Nullable private Runnable mOnClosed;
// Initialized on init
@Nullable private RecentsModel mModel;
// Used to keep track of the last requested task list id, so that we do not request to load the
// tasks again if we have already requested it and the task list has not changed
private int mTaskListChangeId = -1;
@@ -83,6 +81,8 @@ public final class KeyboardQuickSwitchController implements
// Initialized in init
private TaskbarControllers mControllers;
@Nullable private RecentsModel mModel;
private boolean mIsProjectedMode;
@Nullable private KeyboardQuickSwitchViewController mQuickSwitchViewController;
@Nullable private TaskbarOverlayContext mOverlayContext;
@@ -94,6 +94,8 @@ public final class KeyboardQuickSwitchController implements
public void init(@NonNull TaskbarControllers controllers) {
mControllers = controllers;
mModel = RecentsModel.INSTANCE.get(controllers.taskbarActivityContext);
mIsProjectedMode = DesktopState.fromContext(
mControllers.taskbarActivityContext).isProjectedMode();
}
void onConfigurationChanged(@ActivityInfo.Config int configChanges) {
@@ -243,9 +245,9 @@ public final class KeyboardQuickSwitchController implements
});
}
private boolean shouldExcludeTask(GroupTask task, Set<Integer> taskIdsToExclude) {
return ENABLE_TASKBAR_OVERFLOW.isTrue()
&& task.getTasks().stream().anyMatch(t -> taskIdsToExclude.contains(t.key.id));
private boolean shouldIncludeTask(GroupTask task, Set<Integer> taskIdsToExclude) {
return !ENABLE_TASKBAR_OVERFLOW.isTrue()
|| task.getTasks().stream().noneMatch(t -> taskIdsToExclude.contains(t.key.id));
}
private void processLoadedTasks(boolean openedFromTaskbar, List<GroupTask> tasks,
@@ -275,7 +277,8 @@ public final class KeyboardQuickSwitchController implements
return Stream.of(task);
})
.filter(task -> !shouldExcludeTask(task, taskIdsToExclude))
.filter(task -> shouldIncludeTask(task, taskIdsToExclude))
.filter(this::shouldIncludeTaskBasedOnProjectedMode)
.toList();
mTasks = allTasks.stream()
@@ -285,6 +288,24 @@ public final class KeyboardQuickSwitchController implements
mNumHiddenTasks = Math.max(0, allTasks.size() - MAX_TASKS);
}
private boolean shouldIncludeTaskBasedOnProjectedMode(GroupTask task) {
// When not in projected mode, include tasks from all displays
if (!mIsProjectedMode) {
return true;
}
int primaryDisplayId = mControllers.taskbarActivityContext.getPrimaryDisplayId();
// When on primary device in projected mode, only show tasks from the primary device.
if (mControllers.taskbarActivityContext.isPrimaryDisplay()) {
return task.getDisplayId() == primaryDisplayId;
}
// When on connected display with primary device in projected mode, only include tasks that
// are not on primary device.
return task.getDisplayId() != primaryDisplayId;
}
private static Comparator<GroupTask> combinedTasksComparator() {
return Comparator.comparingLong((GroupTask groupTask) ->
groupTask.getTasks().stream()
@@ -301,7 +322,7 @@ public final class KeyboardQuickSwitchController implements
Collections.reverse(tasks);
mTasks = tasks.stream()
.filter(task -> !(task instanceof DesktopTask)
&& !shouldExcludeTask(task, taskIdsToExclude))
&& shouldIncludeTask(task, taskIdsToExclude))
.limit(MAX_TASKS)
.collect(Collectors.toList());
@@ -334,14 +355,14 @@ public final class KeyboardQuickSwitchController implements
mTasks = desktopTasks.stream()
.flatMap(t -> t.getTasks().stream())
.map(SingleTask::new)
.filter(task -> !shouldExcludeTask(task, taskIdsToExclude))
.filter(task -> shouldIncludeTask(task, taskIdsToExclude))
.collect(Collectors.toList());
mNumHiddenTasks = Math.max(0, tasks.size() - desktopTasks.size());
} else if (!desktopTasks.isEmpty()) {
mTasks = desktopTasks.get(0).getTasks().stream()
.map(SingleTask::new)
.filter(task -> !shouldExcludeTask(task, taskIdsToExclude))
.filter(task -> shouldIncludeTask(task, taskIdsToExclude))
.collect(Collectors.toList());
// All other tasks, apart from the grouped desktop task, are hidden
mNumHiddenTasks = Math.max(0, tasks.size() - 1);