Don't replace task in list if NEW_TASK + MULTIPLE_TASK is set

Bug: 183046894
Test: atest RecentTasksTest
Change-Id: Ifbaac51efa90b7a51bd3d64a32dde293ef45d040
This commit is contained in:
Winson Chung
2021-03-18 13:44:24 -07:00
parent e7ec6b42a9
commit 6c246287c7
2 changed files with 34 additions and 7 deletions

View File

@@ -1573,6 +1573,10 @@ class RecentTasks {
} else if (document || trIsDocument) {
// Only one of these is a document. Not the droid we're looking for.
continue;
} else if (multiTasksAllowed) {
// Neither is a document, but the new task supports multiple tasks so keep the
// existing task
continue;
}
}
return i;

View File

@@ -219,7 +219,7 @@ public class RecentTasksTest extends WindowTestsBase {
}
@Test
public void testAddTasksNoMultiple_expectNoTrim() {
public void testAddDocumentTasksNoMultiple_expectNoTrim() {
// Add same non-multiple-task document tasks will remove the task (to re-add it) but not
// trim it
Task documentTask1 = createDocumentTask(".DocumentTask1");
@@ -262,7 +262,7 @@ public class RecentTasksTest extends WindowTestsBase {
}
@Test
public void testAddTasksMultipleDocumentTasks_expectNoTrim() {
public void testAddMultipleDocumentTasks_expectNoTrim() {
// Add same multiple-task document tasks does not trim the first tasks
Task documentTask1 = createDocumentTask(".DocumentTask1",
FLAG_ACTIVITY_MULTIPLE_TASK);
@@ -278,9 +278,33 @@ public class RecentTasksTest extends WindowTestsBase {
}
@Test
public void testAddTasksMultipleTasks_expectRemovedNoTrim() {
// Add multiple same-affinity non-document tasks, ensure that it removes the other task,
// but that it does not trim it
public void testAddTasks_expectRemovedNoTrim() {
// Add multiple same-affinity non-document tasks, ensure that it removes, but does not trim
// the other task
Task task1 = createTaskBuilder(".Task1")
.setFlags(FLAG_ACTIVITY_NEW_TASK)
.build();
Task task2 = createTaskBuilder(".Task1")
.setFlags(FLAG_ACTIVITY_NEW_TASK)
.build();
mRecentTasks.add(task1);
assertThat(mCallbacksRecorder.mAdded).hasSize(1);
assertThat(mCallbacksRecorder.mAdded).contains(task1);
assertThat(mCallbacksRecorder.mTrimmed).isEmpty();
assertThat(mCallbacksRecorder.mRemoved).isEmpty();
mCallbacksRecorder.clear();
mRecentTasks.add(task2);
assertThat(mCallbacksRecorder.mAdded).hasSize(1);
assertThat(mCallbacksRecorder.mAdded).contains(task2);
assertThat(mCallbacksRecorder.mTrimmed).isEmpty();
assertThat(mCallbacksRecorder.mRemoved).hasSize(1);
assertThat(mCallbacksRecorder.mRemoved).contains(task1);
}
@Test
public void testAddMultipleTasks_expectNotRemoved() {
// Add multiple same-affinity non-document tasks with MULTIPLE_TASK, ensure that it does not
// remove the other task
Task task1 = createTaskBuilder(".Task1")
.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK)
.build();
@@ -297,8 +321,7 @@ public class RecentTasksTest extends WindowTestsBase {
assertThat(mCallbacksRecorder.mAdded).hasSize(1);
assertThat(mCallbacksRecorder.mAdded).contains(task2);
assertThat(mCallbacksRecorder.mTrimmed).isEmpty();
assertThat(mCallbacksRecorder.mRemoved).hasSize(1);
assertThat(mCallbacksRecorder.mRemoved).contains(task1);
assertThat(mCallbacksRecorder.mRemoved).isEmpty();
}
@Test