Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34aa1c53 authored by Jeremy Sim's avatar Jeremy Sim Committed by Android (Google) Code Review
Browse files

Merge "Fixes two bugs with findLastActiveTasksAndRunCallback()" into main

parents 10473c59 42a44d79
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1144,7 +1144,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
                componentKeys,
                findExactPairMatch,
                foundTasks -> {
                    @Nullable Task foundTask = foundTasks.get(0);
                    @Nullable Task foundTask = foundTasks[0];
                    if (foundTask != null) {
                        TaskView foundTaskView = recents.getTaskViewByTaskId(foundTask.key.id);
                        if (foundTaskView != null
+2 −2
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ public class TaskbarUIController {
                Collections.singletonList(splitSelectSource.itemInfo.getComponentKey()),
                false /* findExactPairMatch */,
                foundTasks -> {
                    @Nullable Task foundTask = foundTasks.get(0);
                    @Nullable Task foundTask = foundTasks[0];
                    splitSelectSource.alreadyRunningTaskId = foundTask == null
                            ? INVALID_TASK_ID
                            : foundTask.key.id;
@@ -238,7 +238,7 @@ public class TaskbarUIController {
                Collections.singletonList(info.getComponentKey()),
                false /* findExactPairMatch */,
                foundTasks -> {
                    @Nullable Task foundTask = foundTasks.get(0);
                    @Nullable Task foundTask = foundTasks[0];
                    if (foundTask != null) {
                        TaskView foundTaskView = recents.getTaskViewByTaskId(foundTask.key.id);
                        // TODO (b/266482558): This additional null check is needed because there
+1 −1
Original line number Diff line number Diff line
@@ -644,7 +644,7 @@ public class QuickstepLauncher extends Launcher {
                Collections.singletonList(splitSelectSource.itemInfo.getComponentKey()),
                false /* findExactPairMatch */,
                foundTasks -> {
                    @Nullable Task foundTask = foundTasks.get(0);
                    @Nullable Task foundTask = foundTasks[0];
                    boolean taskWasFound = foundTask != null;
                    splitSelectSource.alreadyRunningTaskId = taskWasFound
                            ? foundTask.key.id
+2 −2
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ public class AppPairsController {
                Arrays.asList(app1Key, app2Key),
                false /* findExactPairMatch */,
                foundTasks -> {
                    @Nullable Task foundTask1 = foundTasks.get(0);
                    @Nullable Task foundTask1 = foundTasks[0];
                    Intent task1Intent;
                    int task1Id;
                    if (foundTask1 != null) {
@@ -147,7 +147,7 @@ public class AppPairsController {
                            LAUNCHER_APP_PAIR_LAUNCH,
                            task1Id);

                    @Nullable Task foundTask2 = foundTasks.get(1);
                    @Nullable Task foundTask2 = foundTasks[1];
                    if (foundTask2 != null) {
                        mSplitSelectStateController.setSecondTask(foundTask2);
                    } else {
+14 −11
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ import com.android.wm.shell.splitscreen.ISplitSelectListener;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

@@ -225,14 +225,14 @@ public class SplitSelectStateController {
     *                           tasks (i.e. searching for a running pair of tasks.)
     */
    public void findLastActiveTasksAndRunCallback(@Nullable List<ComponentKey> componentKeys,
            boolean findExactPairMatch, Consumer<List<Task>> callback) {
            boolean findExactPairMatch, Consumer<Task[]> callback) {
        mRecentTasksModel.getTasks(taskGroups -> {
            if (componentKeys == null || componentKeys.isEmpty()) {
                callback.accept(Collections.emptyList());
                callback.accept(new Task[]{});
                return;
            }

            List<Task> lastActiveTasks = new ArrayList<>();
            Task[] lastActiveTasks = new Task[componentKeys.size()];

            if (findExactPairMatch) {
                // Loop through tasks in reverse, since they are ordered with most-recent tasks last
@@ -240,32 +240,35 @@ public class SplitSelectStateController {
                    GroupTask groupTask = taskGroups.get(i);
                    if (isInstanceOfAppPair(
                            groupTask, componentKeys.get(0), componentKeys.get(1))) {
                        lastActiveTasks.add(groupTask.task1);
                        lastActiveTasks[0] = groupTask.task1;
                        break;
                    }
                }
            } else {
                // For each key we are looking for, add to lastActiveTasks with the corresponding
                // Task (or do nothing if not found).
                for (ComponentKey key : componentKeys) {
                for (int i = 0; i < componentKeys.size(); i++) {
                    ComponentKey key = componentKeys.get(i);
                    Task lastActiveTask = null;
                    // Loop through tasks in reverse, since they are ordered with recent tasks last
                    for (int i = taskGroups.size() - 1; i >= 0; i--) {
                        GroupTask groupTask = taskGroups.get(i);
                    for (int j = taskGroups.size() - 1; j >= 0; j--) {
                        GroupTask groupTask = taskGroups.get(j);
                        Task task1 = groupTask.task1;
                        // Don't add duplicate Tasks
                        if (isInstanceOfComponent(task1, key) && !lastActiveTasks.contains(task1)) {
                        if (isInstanceOfComponent(task1, key)
                                && !Arrays.asList(lastActiveTasks).contains(task1)) {
                            lastActiveTask = task1;
                            break;
                        }
                        Task task2 = groupTask.task2;
                        if (isInstanceOfComponent(task2, key) && !lastActiveTasks.contains(task2)) {
                        if (isInstanceOfComponent(task2, key)
                                && !Arrays.asList(lastActiveTasks).contains(task2)) {
                            lastActiveTask = task2;
                            break;
                        }
                    }

                    lastActiveTasks.add(lastActiveTask);
                    lastActiveTasks[i] = lastActiveTask;
                }
            }

Loading