diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java index d4213e59dd..3861d7994e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchController.java @@ -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) { @@ -241,9 +243,9 @@ public final class KeyboardQuickSwitchController implements }); } - private boolean shouldExcludeTask(GroupTask task, Set taskIdsToExclude) { - return ENABLE_TASKBAR_OVERFLOW.isTrue() - && task.getTasks().stream().anyMatch(t -> taskIdsToExclude.contains(t.key.id)); + private boolean shouldIncludeTask(GroupTask task, Set taskIdsToExclude) { + return !ENABLE_TASKBAR_OVERFLOW.isTrue() + || task.getTasks().stream().noneMatch(t -> taskIdsToExclude.contains(t.key.id)); } private void processLoadedTasks(List tasks, Set taskIdsToExclude) { @@ -272,7 +274,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() @@ -282,6 +285,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 combinedTasksComparator() { return Comparator.comparingLong((GroupTask groupTask) -> groupTask.getTasks().stream() @@ -298,7 +319,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()); @@ -331,14 +352,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); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index ac05982ccf..84877e863f 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -253,6 +253,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { private DeviceProfile mPersistentTaskbarDeviceProfile; private final LauncherPrefs mLauncherPrefs; + private final int mPrimaryDisplayId; private final SystemUiProxy mSysUiProxy; private TaskbarFeatureEvaluator mTaskbarFeatureEvaluator; @@ -267,10 +268,11 @@ public class TaskbarActivityContext extends BaseTaskbarContext { @Nullable Context navigationBarPanelContext, DeviceProfile launcherDp, TaskbarNavButtonController buttonController, ScopedUnfoldTransitionProgressProvider unfoldTransitionProgressProvider, - boolean isPrimaryDisplay, SystemUiProxy sysUiProxy) { + boolean isPrimaryDisplay, int primaryDisplayId, SystemUiProxy sysUiProxy) { super(windowContext, displayId, isPrimaryDisplay); mNavigationBarPanelContext = navigationBarPanelContext; mSysUiProxy = sysUiProxy; + mPrimaryDisplayId = primaryDisplayId; applyDeviceProfile(launcherDp); final Resources resources = getResources(); mTaskbarFeatureEvaluator = TaskbarFeatureEvaluator.getInstance(this); @@ -414,6 +416,10 @@ public class TaskbarActivityContext extends BaseTaskbarContext { dispatchDeviceProfileChanged(); } + public final int getPrimaryDisplayId() { + return mPrimaryDisplayId; + } + @Override public boolean isTransientTaskbar() { return DisplayController.isTransientTaskbar(this) && isPrimaryDisplay() && !isPhoneMode(); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManagerImpl.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManagerImpl.java index b55efb7181..42f7b3f15e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManagerImpl.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManagerImpl.java @@ -1393,7 +1393,8 @@ public class TaskbarManagerImpl implements DisplayDecorationListener { TaskbarActivityContext newTaskbar = new TaskbarActivityContext(displayId, getWindowContext(displayId), navigationBarPanelContext, dp, getNavButtonController(displayId), mUnfoldProgressProvider, - !isExternalDisplay(displayId), SystemUiProxy.INSTANCE.get(mBaseContext)); + !isExternalDisplay(displayId), getPrimaryDisplayId(), + SystemUiProxy.INSTANCE.get(mBaseContext)); addTaskbarToMap(displayId, newTaskbar); return newTaskbar;