Merge "Adding logs and re-organized the logic of get root task" into tm-dev

This commit is contained in:
Louis Chang
2022-03-07 01:25:26 +00:00
committed by Android (Google) Code Review

View File

@@ -2750,57 +2750,62 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
@Nullable ActivityOptions options, @Nullable Task candidateTask, @Nullable ActivityOptions options, @Nullable Task candidateTask,
@Nullable Task sourceTask, boolean onTop, @Nullable Task sourceTask, boolean onTop,
@Nullable LaunchParamsController.LaunchParams launchParams, int launchFlags) { @Nullable LaunchParamsController.LaunchParams launchParams, int launchFlags) {
int taskId = INVALID_TASK_ID; // First preference goes to the launch root task set in the activity options.
int displayId = INVALID_DISPLAY;
TaskDisplayArea taskDisplayArea = null;
// We give preference to the launch preference in activity options.
if (options != null) { if (options != null) {
taskId = options.getLaunchTaskId(); final Task candidateRoot = Task.fromWindowContainerToken(options.getLaunchRootTask());
displayId = options.getLaunchDisplayId(); if (canLaunchOnDisplay(r, candidateRoot)) {
final WindowContainerToken daToken = options.getLaunchTaskDisplayArea(); return candidateRoot;
taskDisplayArea = daToken != null
? (TaskDisplayArea) WindowContainer.fromBinder(daToken.asBinder()) : null;
final Task rootTask = Task.fromWindowContainerToken(options.getLaunchRootTask());
if (rootTask != null) {
return rootTask;
} }
} }
// First preference for root task goes to the task Id set in the activity options. Use // Next preference goes to the task id set in the activity options.
// the root task associated with that if possible. if (options != null) {
if (taskId != INVALID_TASK_ID) { final int candidateTaskId = options.getLaunchTaskId();
// Temporarily set the task id to invalid in case in re-entry. if (candidateTaskId != INVALID_TASK_ID) {
options.setLaunchTaskId(INVALID_TASK_ID); // Temporarily set the task id to invalid in case in re-entry.
final Task task = anyTaskForId(taskId, options.setLaunchTaskId(INVALID_TASK_ID);
MATCH_ATTACHED_TASK_OR_RECENT_TASKS_AND_RESTORE, options, onTop); final Task task = anyTaskForId(candidateTaskId,
options.setLaunchTaskId(taskId); MATCH_ATTACHED_TASK_OR_RECENT_TASKS_AND_RESTORE, options, onTop);
if (task != null) { options.setLaunchTaskId(candidateTaskId);
return task.getRootTask(); if (canLaunchOnDisplay(r, task)) {
return task.getRootTask();
}
}
}
// Next preference goes to the TaskDisplayArea candidate from launchParams
// or activity options.
TaskDisplayArea taskDisplayArea = null;
if (launchParams != null && launchParams.mPreferredTaskDisplayArea != null) {
taskDisplayArea = launchParams.mPreferredTaskDisplayArea;
} else if (options != null) {
final WindowContainerToken daToken = options.getLaunchTaskDisplayArea();
taskDisplayArea = daToken != null
? (TaskDisplayArea) WindowContainer.fromBinder(daToken.asBinder()) : null;
if (taskDisplayArea == null) {
final int launchDisplayId = options.getLaunchDisplayId();
if (launchDisplayId != INVALID_DISPLAY) {
final DisplayContent displayContent = getDisplayContent(launchDisplayId);
if (displayContent != null) {
taskDisplayArea = displayContent.getDefaultTaskDisplayArea();
}
}
} }
} }
final int activityType = resolveActivityType(r, options, candidateTask); final int activityType = resolveActivityType(r, options, candidateTask);
Task rootTask = null;
// Next preference for root task goes to the taskDisplayArea candidate.
if (launchParams != null && launchParams.mPreferredTaskDisplayArea != null
&& canLaunchOnDisplay(r, launchParams.mPreferredTaskDisplayArea.getDisplayId())) {
taskDisplayArea = launchParams.mPreferredTaskDisplayArea;
}
if (taskDisplayArea == null && displayId != INVALID_DISPLAY
&& canLaunchOnDisplay(r, displayId)) {
taskDisplayArea = getDisplayContent(displayId).getDefaultTaskDisplayArea();
}
if (taskDisplayArea != null) { if (taskDisplayArea != null) {
return taskDisplayArea.getOrCreateRootTask(r, options, candidateTask, if (canLaunchOnDisplay(r, taskDisplayArea.getDisplayId())) {
sourceTask, launchParams, launchFlags, activityType, onTop); return taskDisplayArea.getOrCreateRootTask(r, options, candidateTask,
sourceTask, launchParams, launchFlags, activityType, onTop);
} else {
taskDisplayArea = null;
}
} }
// Give preference to the root task and display of the input task and activity if they // Give preference to the root task and display of the input task and activity if they
// match the mode we want to launch into. // match the mode we want to launch into.
TaskDisplayArea container = null; Task rootTask = null;
if (candidateTask != null) { if (candidateTask != null) {
rootTask = candidateTask.getRootTask(); rootTask = candidateTask.getRootTask();
} }
@@ -2810,10 +2815,11 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
int windowingMode = launchParams != null ? launchParams.mWindowingMode int windowingMode = launchParams != null ? launchParams.mWindowingMode
: WindowConfiguration.WINDOWING_MODE_UNDEFINED; : WindowConfiguration.WINDOWING_MODE_UNDEFINED;
if (rootTask != null) { if (rootTask != null) {
container = rootTask.getDisplayArea(); taskDisplayArea = rootTask.getDisplayArea();
if (container != null && canLaunchOnDisplay(r, container.mDisplayContent.mDisplayId)) { if (taskDisplayArea != null
&& canLaunchOnDisplay(r, taskDisplayArea.mDisplayContent.mDisplayId)) {
if (windowingMode == WindowConfiguration.WINDOWING_MODE_UNDEFINED) { if (windowingMode == WindowConfiguration.WINDOWING_MODE_UNDEFINED) {
windowingMode = container.resolveWindowingMode(r, options, candidateTask); windowingMode = taskDisplayArea.resolveWindowingMode(r, options, candidateTask);
} }
// Always allow organized tasks that created by organizer since the activity type // Always allow organized tasks that created by organizer since the activity type
// of an organized task is decided by the activity type of its top child, which // of an organized task is decided by the activity type of its top child, which
@@ -2822,19 +2828,32 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|| rootTask.mCreatedByOrganizer) { || rootTask.mCreatedByOrganizer) {
return rootTask; return rootTask;
} }
} else {
taskDisplayArea = null;
} }
} }
if (container == null // Falling back to default task container
|| !canLaunchOnDisplay(r, container.mDisplayContent.mDisplayId)) { if (taskDisplayArea == null) {
container = getDefaultTaskDisplayArea(); taskDisplayArea = getDefaultTaskDisplayArea();
if (windowingMode == WindowConfiguration.WINDOWING_MODE_UNDEFINED) { }
windowingMode = container.resolveWindowingMode(r, options, candidateTask); return taskDisplayArea.getOrCreateRootTask(r, options, candidateTask, sourceTask,
} launchParams, launchFlags, activityType, onTop);
}
private boolean canLaunchOnDisplay(ActivityRecord r, Task task) {
if (task == null) {
Slog.w(TAG, "canLaunchOnDisplay(), invalid task: " + task);
return false;
} }
return container.getOrCreateRootTask(r, options, candidateTask, sourceTask, launchParams, if (!task.isAttached()) {
launchFlags, activityType, onTop); Slog.w(TAG, "canLaunchOnDisplay(), Task is not attached: " + task);
return false;
}
return canLaunchOnDisplay(r, task.getTaskDisplayArea().getDisplayId());
} }
/** @return true if activity record is null or can be launched on provided display. */ /** @return true if activity record is null or can be launched on provided display. */
@@ -2842,7 +2861,11 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
if (r == null) { if (r == null) {
return true; return true;
} }
return r.canBeLaunchedOnDisplay(displayId); if (!r.canBeLaunchedOnDisplay(displayId)) {
Slog.w(TAG, "Not allow to launch " + r + " on display " + displayId);
return false;
}
return true;
} }
int resolveActivityType(@Nullable ActivityRecord r, @Nullable ActivityOptions options, int resolveActivityType(@Nullable ActivityRecord r, @Nullable ActivityOptions options,