Update recent tasks when task moves to top
When a task is moved to the top, ensure that the recents entry is moved to the top at the same time. Bug: 280468885 Test: atest WmTests:RecentTasksTest Change-Id: I780893fd0dc05cb85e9d8473c1feb089593d9793
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1271,6 +1271,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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user