Remove the tasks created by the organizer when it dies.
- Instead of moving these tasks to a different organizer they are now removed. - This is done because it makes sense for the tasks to end along with the organizer that created them. Bug: b/223420767 Test: atest WindowOrganizerTests Change-Id: Ibb53ce28d865e83bbcefc35f5625b3a71b6ee766
This commit is contained in:
@@ -250,7 +250,13 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
|
|||||||
// possible.
|
// possible.
|
||||||
while (!mOrganizedTasks.isEmpty()) {
|
while (!mOrganizedTasks.isEmpty()) {
|
||||||
final Task t = mOrganizedTasks.get(0);
|
final Task t = mOrganizedTasks.get(0);
|
||||||
|
if (t.mCreatedByOrganizer) {
|
||||||
|
// The tasks created by this organizer should ideally be deleted when this
|
||||||
|
// organizer is disposed off to avoid inconsistent behavior.
|
||||||
|
t.removeImmediately();
|
||||||
|
} else {
|
||||||
t.updateTaskOrganizerState(true /* forceUpdate */);
|
t.updateTaskOrganizerState(true /* forceUpdate */);
|
||||||
|
}
|
||||||
if (mOrganizedTasks.contains(t)) {
|
if (mOrganizedTasks.contains(t)) {
|
||||||
// updateTaskOrganizerState should remove the task from the list, but still
|
// updateTaskOrganizerState should remove the task from the list, but still
|
||||||
// check it again to avoid while-loop isn't terminate.
|
// check it again to avoid while-loop isn't terminate.
|
||||||
|
|||||||
@@ -308,6 +308,52 @@ public class WindowOrganizerTests extends WindowTestsBase {
|
|||||||
assertTaskVanished(organizer2, true /* expectVanished */, rootTask, rootTask2, rootTask3);
|
assertTaskVanished(organizer2, true /* expectVanished */, rootTask, rootTask2, rootTask3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnregisterOrganizer_removesTasksCreatedByIt() throws RemoteException {
|
||||||
|
final Task rootTask = createRootTask();
|
||||||
|
final Task task = createTask(rootTask);
|
||||||
|
final Task rootTask2 = createRootTask();
|
||||||
|
rootTask2.mCreatedByOrganizer = true;
|
||||||
|
final Task task2 = createTask(rootTask2);
|
||||||
|
final ArrayList<TaskAppearedInfo> existingTasks = new ArrayList<>();
|
||||||
|
final ITaskOrganizer organizer = registerMockOrganizer(existingTasks);
|
||||||
|
// Ensure events dispatch to organizer.
|
||||||
|
mWm.mAtmService.mTaskOrganizerController.dispatchPendingEvents();
|
||||||
|
|
||||||
|
// verify that tasks are returned and taskAppeared is called only for rootTask2 since it
|
||||||
|
// is the one created by this organizer.
|
||||||
|
assertContainsTasks(existingTasks, rootTask);
|
||||||
|
verify(organizer, times(1)).onTaskAppeared(any(RunningTaskInfo.class),
|
||||||
|
any(SurfaceControl.class));
|
||||||
|
verify(organizer, times(0)).onTaskVanished(any());
|
||||||
|
assertTrue(rootTask.isOrganized());
|
||||||
|
|
||||||
|
// Now we replace the registration and verify the new organizer receives existing tasks
|
||||||
|
final ArrayList<TaskAppearedInfo> existingTasks2 = new ArrayList<>();
|
||||||
|
final ITaskOrganizer organizer2 = registerMockOrganizer(existingTasks2);
|
||||||
|
// Ensure events dispatch to organizer.
|
||||||
|
mWm.mAtmService.mTaskOrganizerController.dispatchPendingEvents();
|
||||||
|
assertContainsTasks(existingTasks2, rootTask);
|
||||||
|
verify(organizer2, times(1)).onTaskAppeared(any(RunningTaskInfo.class),
|
||||||
|
any(SurfaceControl.class));
|
||||||
|
verify(organizer2, times(0)).onTaskVanished(any());
|
||||||
|
// Removed tasks from the original organizer
|
||||||
|
assertTaskVanished(organizer, true /* expectVanished */, rootTask, rootTask2);
|
||||||
|
assertTrue(rootTask2.isOrganized());
|
||||||
|
|
||||||
|
// Now we unregister the second one, the first one should automatically be reregistered
|
||||||
|
// so we verify that it's now seeing changes.
|
||||||
|
mWm.mAtmService.mTaskOrganizerController.unregisterTaskOrganizer(organizer2);
|
||||||
|
// Ensure events dispatch to organizer.
|
||||||
|
mWm.mAtmService.mTaskOrganizerController.dispatchPendingEvents();
|
||||||
|
|
||||||
|
verify(organizer, times(2))
|
||||||
|
.onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class));
|
||||||
|
assertFalse(rootTask2.isOrganized());
|
||||||
|
assertTaskVanished(organizer2, true /* expectVanished */, rootTask,
|
||||||
|
rootTask2);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrganizerDeathReturnsRegistrationToPrevious() throws RemoteException {
|
public void testOrganizerDeathReturnsRegistrationToPrevious() throws RemoteException {
|
||||||
final Task rootTask = createRootTask();
|
final Task rootTask = createRootTask();
|
||||||
|
|||||||
Reference in New Issue
Block a user