Merge "Fixes two bugs with findLastActiveTasksAndRunCallback()" into main
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ class SplitSelectStateControllerTest {
|
||||
// Assertions happen in the callback we get from what we pass into
|
||||
// #findLastActiveTasksAndRunCallback
|
||||
val taskConsumer =
|
||||
Consumer<List<Task>> { assertNull("No tasks should have matched", it[0] /*task*/) }
|
||||
Consumer<Array<Task>> { assertNull("No tasks should have matched", it[0] /*task*/) }
|
||||
|
||||
// Capture callback from recentsModel#getTasks()
|
||||
val consumer =
|
||||
@@ -148,7 +148,7 @@ class SplitSelectStateControllerTest {
|
||||
// Assertions happen in the callback we get from what we pass into
|
||||
// #findLastActiveTasksAndRunCallback
|
||||
val taskConsumer =
|
||||
Consumer<List<Task>> {
|
||||
Consumer<Array<Task>> {
|
||||
assertEquals(
|
||||
"ComponentName package mismatched",
|
||||
it[0].key.baseIntent.component?.packageName,
|
||||
@@ -201,7 +201,7 @@ class SplitSelectStateControllerTest {
|
||||
// Assertions happen in the callback we get from what we pass into
|
||||
// #findLastActiveTasksAndRunCallback
|
||||
val taskConsumer =
|
||||
Consumer<List<Task>> { assertNull("No tasks should have matched", it[0] /*task*/) }
|
||||
Consumer<Array<Task>> { assertNull("No tasks should have matched", it[0] /*task*/) }
|
||||
|
||||
// Capture callback from recentsModel#getTasks()
|
||||
val consumer =
|
||||
@@ -244,7 +244,7 @@ class SplitSelectStateControllerTest {
|
||||
// Assertions happen in the callback we get from what we pass into
|
||||
// #findLastActiveTasksAndRunCallback
|
||||
val taskConsumer =
|
||||
Consumer<List<Task>> {
|
||||
Consumer<Array<Task>> {
|
||||
assertEquals(
|
||||
"ComponentName package mismatched",
|
||||
it[0].key.baseIntent.component?.packageName,
|
||||
@@ -298,7 +298,7 @@ class SplitSelectStateControllerTest {
|
||||
// Assertions happen in the callback we get from what we pass into
|
||||
// #findLastActiveTasksAndRunCallback
|
||||
val taskConsumer =
|
||||
Consumer<List<Task>> {
|
||||
Consumer<Array<Task>> {
|
||||
assertEquals(
|
||||
"ComponentName package mismatched",
|
||||
it[0].key.baseIntent.component?.packageName,
|
||||
@@ -350,7 +350,7 @@ class SplitSelectStateControllerTest {
|
||||
// Assertions happen in the callback we get from what we pass into
|
||||
// #findLastActiveTasksAndRunCallback
|
||||
val taskConsumer =
|
||||
Consumer<List<Task>> {
|
||||
Consumer<Array<Task>> {
|
||||
assertEquals("Expected array length 2", 2, it.size)
|
||||
assertNull("No tasks should have matched", it[0] /*task*/)
|
||||
assertEquals(
|
||||
@@ -403,7 +403,7 @@ class SplitSelectStateControllerTest {
|
||||
// Assertions happen in the callback we get from what we pass into
|
||||
// #findLastActiveTasksAndRunCallback
|
||||
val taskConsumer =
|
||||
Consumer<List<Task>> {
|
||||
Consumer<Array<Task>> {
|
||||
assertEquals("Expected array length 2", 2, it.size)
|
||||
assertEquals(
|
||||
"ComponentName package mismatched",
|
||||
@@ -459,7 +459,7 @@ class SplitSelectStateControllerTest {
|
||||
// Assertions happen in the callback we get from what we pass into
|
||||
// #findLastActiveTasksAndRunCallback
|
||||
val taskConsumer =
|
||||
Consumer<List<Task>> {
|
||||
Consumer<Array<Task>> {
|
||||
assertEquals("Expected array length 2", 2, it.size)
|
||||
assertEquals(
|
||||
"ComponentName package mismatched",
|
||||
@@ -532,8 +532,8 @@ class SplitSelectStateControllerTest {
|
||||
// Assertions happen in the callback we get from what we pass into
|
||||
// #findLastActiveTasksAndRunCallback
|
||||
val taskConsumer =
|
||||
Consumer<List<Task>> {
|
||||
assertEquals("Expected array length 1", 1, it.size)
|
||||
Consumer<Array<Task>> {
|
||||
assertEquals("Expected array length 2", 2, it.size)
|
||||
assertEquals("Found wrong task", it[0], groupTask2.task1)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user