Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7558f4a7 authored by Louis Chang's avatar Louis Chang Committed by Android Build Coastguard Worker
Browse files

Do not select displays that cannot host the activities as fallback

Bug: 448296189
Bug: 444893446
Test: wm presubmit
Flag: EXEMPT BUGFIX
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:663fea6699595a823af632719c525595ee8a19f7
Merged-In: I82a1cf74c08f60030540b86e259428787fcdf3c6
Change-Id: I82a1cf74c08f60030540b86e259428787fcdf3c6
parent ccab434f
Loading
Loading
Loading
Loading
+30 −4
Original line number Diff line number Diff line
@@ -418,7 +418,8 @@ class LaunchParamsUtil {
            if (controllerFromLaunchingRecord != null) {
                final TaskDisplayArea taskDisplayAreaForLaunchingRecord =
                        controllerFromLaunchingRecord.getTopActivityDisplayArea();
                if (taskDisplayAreaForLaunchingRecord != null) {
                if (canPlaceEntityOnDisplay(taskDisplayAreaForLaunchingRecord, activityRecord,
                        request, supervisor)) {
                    logger.accept("display-area-for-launching-record="
                            + taskDisplayAreaForLaunchingRecord);
                    return taskDisplayAreaForLaunchingRecord;
@@ -431,7 +432,8 @@ class LaunchParamsUtil {
            if (controllerFromProcess != null) {
                final TaskDisplayArea displayAreaForRecord =
                        controllerFromProcess.getTopActivityDisplayArea();
                if (displayAreaForRecord != null) {
                if (canPlaceEntityOnDisplay(displayAreaForRecord, activityRecord,
                        request, supervisor)) {
                    logger.accept("display-area-for-record=" + displayAreaForRecord);
                    return displayAreaForRecord;
                }
@@ -445,7 +447,8 @@ class LaunchParamsUtil {
            if (controllerFromRequest != null) {
                final TaskDisplayArea displayAreaFromSourceProcess =
                        controllerFromRequest.getTopActivityDisplayArea();
                if (displayAreaFromSourceProcess != null) {
                if (canPlaceEntityOnDisplay(displayAreaFromSourceProcess, activityRecord,
                        request, supervisor)) {
                    logger.accept("display-area-source-process=" + displayAreaFromSourceProcess);
                    return displayAreaFromSourceProcess;
                }
@@ -457,7 +460,8 @@ class LaunchParamsUtil {
            final DisplayContent focusedDisplay =
                    supervisor.mRootWindowContainer.getTopFocusedDisplayContent();
            final TaskDisplayArea defaultTaskDisplayArea;
            if (focusedDisplay.mDisplay.canHostTasks()) {
            if (canPlaceEntityOnDisplay(focusedDisplay.getDefaultTaskDisplayArea(), activityRecord,
                    request, supervisor)) {
                defaultTaskDisplayArea = focusedDisplay.getDefaultTaskDisplayArea();
            } else {
                defaultTaskDisplayArea =
@@ -472,4 +476,26 @@ class LaunchParamsUtil {
            return defaultTaskDisplayArea;
        }
    }

    /**
     * Returns {@code true} if the given activity can be placed on the TaskDisplayArea.
     */
    private static boolean canPlaceEntityOnDisplay(@Nullable TaskDisplayArea tda,
            @Nullable ActivityRecord activity, @Nullable ActivityStarter.Request request,
            @NonNull ActivityTaskSupervisor supervisor) {
        if (tda == null) {
            return false;
        }

        final int displayId = tda.getDisplayId();
        if (activity != null) {
            return activity.canBeLaunchedOnDisplay(displayId);
        }

        if (request != null && request.activityInfo != null) {
            return supervisor.canPlaceEntityOnDisplay(displayId, request.callingPid,
                    request.callingUid, request.activityInfo);
        }
        return false;
    }
}