Merge "Adding logs and re-organized the logic of get root task" into tm-dev
This commit is contained in:
@@ -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)) {
|
||||||
|
return candidateRoot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next preference goes to the task id set in the activity options.
|
||||||
|
if (options != null) {
|
||||||
|
final int candidateTaskId = options.getLaunchTaskId();
|
||||||
|
if (candidateTaskId != INVALID_TASK_ID) {
|
||||||
|
// Temporarily set the task id to invalid in case in re-entry.
|
||||||
|
options.setLaunchTaskId(INVALID_TASK_ID);
|
||||||
|
final Task task = anyTaskForId(candidateTaskId,
|
||||||
|
MATCH_ATTACHED_TASK_OR_RECENT_TASKS_AND_RESTORE, options, onTop);
|
||||||
|
options.setLaunchTaskId(candidateTaskId);
|
||||||
|
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();
|
final WindowContainerToken daToken = options.getLaunchTaskDisplayArea();
|
||||||
taskDisplayArea = daToken != null
|
taskDisplayArea = daToken != null
|
||||||
? (TaskDisplayArea) WindowContainer.fromBinder(daToken.asBinder()) : null;
|
? (TaskDisplayArea) WindowContainer.fromBinder(daToken.asBinder()) : null;
|
||||||
|
if (taskDisplayArea == null) {
|
||||||
final Task rootTask = Task.fromWindowContainerToken(options.getLaunchRootTask());
|
final int launchDisplayId = options.getLaunchDisplayId();
|
||||||
if (rootTask != null) {
|
if (launchDisplayId != INVALID_DISPLAY) {
|
||||||
return rootTask;
|
final DisplayContent displayContent = getDisplayContent(launchDisplayId);
|
||||||
|
if (displayContent != null) {
|
||||||
|
taskDisplayArea = displayContent.getDefaultTaskDisplayArea();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// First preference for root task goes to the task Id set in the activity options. Use
|
|
||||||
// the root task associated with that if possible.
|
|
||||||
if (taskId != INVALID_TASK_ID) {
|
|
||||||
// Temporarily set the task id to invalid in case in re-entry.
|
|
||||||
options.setLaunchTaskId(INVALID_TASK_ID);
|
|
||||||
final Task task = anyTaskForId(taskId,
|
|
||||||
MATCH_ATTACHED_TASK_OR_RECENT_TASKS_AND_RESTORE, options, onTop);
|
|
||||||
options.setLaunchTaskId(taskId);
|
|
||||||
if (task != null) {
|
|
||||||
return task.getRootTask();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
if (canLaunchOnDisplay(r, taskDisplayArea.getDisplayId())) {
|
||||||
return taskDisplayArea.getOrCreateRootTask(r, options, candidateTask,
|
return taskDisplayArea.getOrCreateRootTask(r, options, candidateTask,
|
||||||
sourceTask, launchParams, launchFlags, activityType, onTop);
|
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
|
|
||||||
|| !canLaunchOnDisplay(r, container.mDisplayContent.mDisplayId)) {
|
|
||||||
container = getDefaultTaskDisplayArea();
|
|
||||||
if (windowingMode == WindowConfiguration.WINDOWING_MODE_UNDEFINED) {
|
|
||||||
windowingMode = container.resolveWindowingMode(r, options, candidateTask);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return container.getOrCreateRootTask(r, options, candidateTask, sourceTask, launchParams,
|
// Falling back to default task container
|
||||||
launchFlags, activityType, onTop);
|
if (taskDisplayArea == null) {
|
||||||
|
taskDisplayArea = getDefaultTaskDisplayArea();
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!task.isAttached()) {
|
||||||
|
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,
|
||||||
|
|||||||
Reference in New Issue
Block a user