From 99ccc8786e75b8decba06440a3e7983060427a34 Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Tue, 6 Jun 2023 11:28:37 +0000 Subject: [PATCH] Fix SystemUI crash from continues launch task with setLaunchRootTask In StageCoordinator#addActivityOptions, there will use KEY_LAUNCH_ROOT_TASK_TOKEN to specify the "parent task" of current launch, but that isn't align the definition of "root task" after single split root was introduced. So the method "getOrCreateRootTask" also seems weird now. WindowContainer#reparent will throw IllegalArgumentException when no parent change. Bug: 286028934 Test: create a split pair, continues drag chrome to the same stage. Change-Id: Ic165eca258a8ef1f365b4f86f98211453243a465 --- .../java/com/android/server/wm/RootWindowContainer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index bc7fa31125f99..6bab371ba4db9 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -3310,9 +3310,14 @@ class RootWindowContainer extends WindowContainer if (aOptions != null) { // Resolve the root task the task should be placed in now based on options // and reparent if needed. + // TODO(b/229927851) For split-screen, setLaunchRootTask is no longer the "root" + // task, consider to rename methods like "parentTask" instead of "rootTask". final Task targetRootTask = getOrCreateRootTask(null, aOptions, task, onTop); - if (targetRootTask != null && task.getRootTask() != targetRootTask) { + // When launch with ActivityOptions#getLaunchRootTask, the "root task" just mean the + // parent of current launch, not the "root task" in hierarchy. + if (targetRootTask != null && task.getRootTask() != targetRootTask + && task.getParent() != targetRootTask) { final int reparentMode = onTop ? REPARENT_MOVE_ROOT_TASK_TO_FRONT : REPARENT_LEAVE_ROOT_TASK_IN_PLACE; task.reparent(targetRootTask, onTop, reparentMode, ANIMATE, DEFER_RESUME,