Update launch root rule to consider created-by-organizer parent first.

Before this, we use the source root task as a default launch root when
starting an activity. Updated to also consider the first
created-by-organizer parent as a default launch root because the
different side of the split will share the same root task after we
migrated split screen to a single-top root task hierachy.

Bug: 207185041
Test: launch activity with launch adjacent flag will enter split screen
Change-Id: I4db5be181c03141b11c77e8f76b49fa9f24686cb
This commit is contained in:
Jerry Chang
2022-03-07 06:07:12 +00:00
parent 57d28b9a6e
commit 9eb625a5f2
3 changed files with 28 additions and 9 deletions

View File

@@ -2929,7 +2929,8 @@ class ActivityStarter {
final boolean onTop =
(aOptions == null || !aOptions.getAvoidMoveToFront()) && !mLaunchTaskBehind;
return mRootWindowContainer.getOrCreateRootTask(r, aOptions, task, mSourceRootTask, onTop,
final Task sourceTask = mSourceRecord != null ? mSourceRecord.getTask() : null;
return mRootWindowContainer.getOrCreateRootTask(r, aOptions, task, sourceTask, onTop,
mLaunchParams, launchFlags);
}

View File

@@ -2360,6 +2360,20 @@ class Task extends TaskFragment {
return parentTask == null ? null : parentTask.getOrganizedTask();
}
/** @return the first create-by-organizer task. */
@Nullable
Task getCreatedByOrganizerTask() {
if (mCreatedByOrganizer) {
return this;
}
final WindowContainer parent = getParent();
if (parent == null) {
return null;
}
final Task parentTask = parent.asTask();
return parentTask == null ? null : parentTask.getCreatedByOrganizerTask();
}
// TODO(task-merge): Figure out what's the right thing to do for places that used it.
boolean isRootTask() {
return getRootTask() == this;

View File

@@ -1125,9 +1125,9 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
if ((launchFlags & FLAG_ACTIVITY_LAUNCH_ADJACENT) != 0
&& mLaunchAdjacentFlagRootTask != null) {
// If the adjacent launch is coming from the same root, launch to adjacent root instead.
if (sourceTask != null
&& sourceTask.getRootTask().mTaskId == mLaunchAdjacentFlagRootTask.mTaskId
&& mLaunchAdjacentFlagRootTask.getAdjacentTaskFragment() != null) {
if (sourceTask != null && mLaunchAdjacentFlagRootTask.getAdjacentTaskFragment() != null
&& (sourceTask == mLaunchAdjacentFlagRootTask
|| sourceTask.isDescendantOf(mLaunchAdjacentFlagRootTask))) {
return mLaunchAdjacentFlagRootTask.getAdjacentTaskFragment().asTask();
} else {
return mLaunchAdjacentFlagRootTask;
@@ -1141,18 +1141,22 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
? launchRootTask.getAdjacentTaskFragment() : null;
final Task adjacentRootTask =
adjacentTaskFragment != null ? adjacentTaskFragment.asTask() : null;
if (sourceTask != null && sourceTask.getRootTask() == adjacentRootTask) {
if (sourceTask != null && adjacentRootTask != null
&& (sourceTask == adjacentRootTask
|| sourceTask.isDescendantOf(adjacentRootTask))) {
return adjacentRootTask;
} else {
return launchRootTask;
}
}
}
// For better split UX, If task launch by the source task which root task is created by
// organizer, it should also launch in that root too.
if (sourceTask != null && sourceTask.getRootTask().mCreatedByOrganizer) {
return sourceTask.getRootTask();
// For a better split UX, If a task is launching from a created-by-organizer task, it should
// be launched into the same created-by-organizer task as well.
if (sourceTask != null) {
return sourceTask.getCreatedByOrganizerTask();
}
return null;
}