Do not reposition leaf tasks from grandparent tasks

A leaf task was added to be the child of its grandparent while
switch user, which caused exception while reparenting split-screen
tasks to fullscreen.

Bug: 161167885
Test: switch user in split-screen
Test: atest TaskTests
Change-Id: Iffde4ddfbe315d0226961f7d98a897b34062c376
This commit is contained in:
Louis Chang
2020-07-21 13:38:54 +08:00
parent b7f02a3e1d
commit 8b2554732e
3 changed files with 19 additions and 7 deletions

View File

@@ -5400,12 +5400,9 @@ class Task extends WindowContainer<WindowContainer> {
mCurrentUser = userId;
super.switchUser(userId);
forAllLeafTasks((t) -> {
if (t.showToCurrentUser() && t != this) {
mChildren.remove(t);
mChildren.add(t);
}
}, true /* traverseTopToBottom */);
if (isLeafTask() && showToCurrentUser()) {
getParent().positionChildAt(POSITION_TOP, this, false /*includeParents*/);
}
}
void minimalResumeActivityLocked(ActivityRecord r) {

View File

@@ -353,7 +353,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
}
}
} else {
throw new RuntimeException("Reparenting leaf Tasks is not supported now.");
throw new RuntimeException("Reparenting leaf Tasks is not supported now. " + task);
}
} else {
// Ugh, of course ActivityStack has its own special reorder logic...

View File

@@ -186,4 +186,19 @@ public class TaskTests extends WindowTestsBase {
assertTrue(r.finishing);
});
}
@Test
public void testSwitchUser() {
final Task rootTask = createTaskStackOnDisplay(mDisplayContent);
final Task childTask = createTaskInStack(rootTask, 0 /* userId */);
final Task leafTask1 = createTaskInStack(childTask, 10 /* userId */);
final Task leafTask2 = createTaskInStack(childTask, 0 /* userId */);
assertEquals(1, rootTask.getChildCount());
assertEquals(leafTask2, childTask.getTopChild());
doReturn(true).when(leafTask1).showToCurrentUser();
rootTask.switchUser(10);
assertEquals(1, rootTask.getChildCount());
assertEquals(leafTask1, childTask.getTopChild());
}
}