Merge "Update recent tasks when task moves to top" into udc-qpr-dev

This commit is contained in:
Ats Jenk
2023-05-23 16:27:57 +00:00
committed by Android (Google) Code Review
4 changed files with 48 additions and 1 deletions

View File

@@ -1104,6 +1104,10 @@ class RecentTasks {
// front unless overridden by the provided activity options
mTasks.remove(taskIndex);
mTasks.add(0, task);
if (taskIndex != 0) {
// Only notify when position changes
mTaskNotificationController.notifyTaskListUpdated();
}
if (DEBUG_RECENTS) {
Slog.d(TAG_RECENTS, "addRecent: moving to top " + task
@@ -1552,7 +1556,7 @@ class RecentTasks {
task.affinity != null && task.affinity.equals(t.affinity);
final boolean sameIntent = intent != null && intent.filterEquals(trIntent);
boolean multiTasksAllowed = false;
final int flags = intent.getFlags();
final int flags = intent != null ? intent.getFlags() : 0;
if ((flags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_NEW_DOCUMENT)) != 0
&& (flags & FLAG_ACTIVITY_MULTIPLE_TASK) != 0) {
multiTasksAllowed = true;

View File

@@ -1272,6 +1272,10 @@ class Task extends TaskFragment {
if (isPersistable) {
mLastTimeMoved = System.currentTimeMillis();
}
if (toTop && inRecents) {
// If task is in recents, ensure it is at the top
mTaskSupervisor.mRecentTasks.add(this);
}
}
// Close up recents linked list.

View File

@@ -1702,6 +1702,9 @@ public class ActivityStarterTests extends WindowTestsBase {
@Test
public void testRecordActivityMovementBeforeDeliverToTop() {
// Mock recents as task is only marked to be in recents
mAtm.mTaskSupervisor.setRecentTasks(mock(RecentTasks.class));
final Task task = new TaskBuilder(mAtm.mTaskSupervisor).build();
final ActivityRecord activityBot = new ActivityBuilder(mAtm).setTask(task).build();
final ActivityRecord activityTop = new ActivityBuilder(mAtm).setTask(task).build();

View File

@@ -49,10 +49,12 @@ import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static java.lang.Integer.MAX_VALUE;
@@ -1138,6 +1140,40 @@ public class RecentTasksTest extends WindowTestsBase {
verify(controller, times(2)).notifyTaskListUpdated();
}
@Test
public void addTask_taskAlreadyInRecentsMovedToTop_callsTaskNotificationController() {
final Task firstTask = createTaskBuilder(".Task").build();
final Task secondTask = createTaskBuilder(".Task2").build();
mRecentTasks.add(firstTask);
mRecentTasks.add(secondTask);
TaskChangeNotificationController controller =
mAtm.getTaskChangeNotificationController();
clearInvocations(controller);
// Add firstTask back to top
mRecentTasks.add(firstTask);
verify(controller).notifyTaskListUpdated();
}
@Test
public void addTask_taskAlreadyInRecentsOnTop_doesNotNotify() {
final Task firstTask = createTaskBuilder(".Task").build();
final Task secondTask = createTaskBuilder(".Task2").build();
mRecentTasks.add(firstTask);
mRecentTasks.add(secondTask);
TaskChangeNotificationController controller =
mAtm.getTaskChangeNotificationController();
clearInvocations(controller);
// Add secondTask to top again
mRecentTasks.add(secondTask);
verifyZeroInteractions(controller);
}
@Test
public void removeTask_callsTaskNotificationController() {
final Task task = createTaskBuilder(".Task").build();