diff options
| author | 2022-03-07 01:25:26 +0000 | |
|---|---|---|
| committer | 2022-03-07 01:25:26 +0000 | |
| commit | a2bfe5a6fc41c7db8bbfa47b080b0485a3e2ac60 (patch) | |
| tree | 313d9813397dde1ce49776d714a08f606f4d0450 | |
| parent | 54102c21f22fce1729133719d4b83d9ae14bcdcf (diff) | |
| parent | c117a22d6287b46bf3d5c8a3fe06cdb5e4a2b94d (diff) | |
Merge "Adding logs and re-organized the logic of get root task" into tm-dev
| -rw-r--r-- | services/core/java/com/android/server/wm/RootWindowContainer.java | 121 |
1 files changed, 72 insertions, 49 deletions
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index b9cd657da0e2..f65b17db1e10 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -2750,57 +2750,62 @@ class RootWindowContainer extends WindowContainer<DisplayContent> @Nullable ActivityOptions options, @Nullable Task candidateTask, @Nullable Task sourceTask, boolean onTop, @Nullable LaunchParamsController.LaunchParams launchParams, int launchFlags) { - int taskId = INVALID_TASK_ID; - int displayId = INVALID_DISPLAY; - TaskDisplayArea taskDisplayArea = null; - - // We give preference to the launch preference in activity options. + // First preference goes to the launch root task set in the activity options. if (options != null) { - taskId = options.getLaunchTaskId(); - displayId = options.getLaunchDisplayId(); - final WindowContainerToken daToken = options.getLaunchTaskDisplayArea(); - taskDisplayArea = daToken != null - ? (TaskDisplayArea) WindowContainer.fromBinder(daToken.asBinder()) : null; - - final Task rootTask = Task.fromWindowContainerToken(options.getLaunchRootTask()); - if (rootTask != null) { - return rootTask; + final Task candidateRoot = Task.fromWindowContainerToken(options.getLaunchRootTask()); + if (canLaunchOnDisplay(r, candidateRoot)) { + return candidateRoot; } } - // 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(); + // 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(); + } } } - 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())) { + // 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(); + } + } + } } - if (taskDisplayArea == null && displayId != INVALID_DISPLAY - && canLaunchOnDisplay(r, displayId)) { - taskDisplayArea = getDisplayContent(displayId).getDefaultTaskDisplayArea(); - } + + final int activityType = resolveActivityType(r, options, candidateTask); if (taskDisplayArea != null) { - return taskDisplayArea.getOrCreateRootTask(r, options, candidateTask, - sourceTask, launchParams, launchFlags, activityType, onTop); + if (canLaunchOnDisplay(r, taskDisplayArea.getDisplayId())) { + 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 // match the mode we want to launch into. - TaskDisplayArea container = null; + Task rootTask = null; if (candidateTask != null) { rootTask = candidateTask.getRootTask(); } @@ -2810,10 +2815,11 @@ class RootWindowContainer extends WindowContainer<DisplayContent> int windowingMode = launchParams != null ? launchParams.mWindowingMode : WindowConfiguration.WINDOWING_MODE_UNDEFINED; if (rootTask != null) { - container = rootTask.getDisplayArea(); - if (container != null && canLaunchOnDisplay(r, container.mDisplayContent.mDisplayId)) { + taskDisplayArea = rootTask.getDisplayArea(); + if (taskDisplayArea != null + && canLaunchOnDisplay(r, taskDisplayArea.mDisplayContent.mDisplayId)) { 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 // 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) { 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); - } + // Falling back to default task container + if (taskDisplayArea == null) { + taskDisplayArea = getDefaultTaskDisplayArea(); } + return taskDisplayArea.getOrCreateRootTask(r, options, candidateTask, sourceTask, + launchParams, launchFlags, activityType, onTop); + } - return container.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. */ @@ -2842,7 +2861,11 @@ class RootWindowContainer extends WindowContainer<DisplayContent> if (r == null) { 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, |