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

Commit 9ba524e7 authored by Evan Rosky's avatar Evan Rosky Committed by Garfield Tan
Browse files

Enable window-mode propagation to tasks.

Removes a number of places where both bounds and windowingMode were
hard-coded.

ActivityDisplay:
- Added support for unspecified windowing mode (removing hard-coded
  FULLSCREEN).
- Enabled propagation of windowing-mode from display to stacks/tasks
  (via unspecified mode).

ActivityStack:
- Don't always set override-bounds if UNDEFINED. Instead, rely on
  inheritance from ActivityDisplay. Continue to validate defined
  modes though.

ActivityStackSupervisor:
- Since task to stack is 1-to-1 (except potentially in split modes),
  have isValidLaunchStack return false most of the time.

TaskRecord:
- Fixed a NPE where override-bounds wasn't being checked for nullness
  when recording lastNonFullscreenBounds.

Change-Id: Ic67419464e5c7863deb31ba4a79eaa60d4f47df0
Bug: 71028874
Test: go/wm-smoke
parent 352a72ca
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -315,16 +315,6 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack>
                    + windowingMode);
        }

        if (windowingMode == WINDOWING_MODE_UNDEFINED) {
            // TODO: Should be okay to have stacks with with undefined windowing mode long term, but
            // have to set them to something for now due to logic that depending on them.
            windowingMode = getWindowingMode(); // Put in current display's windowing mode
            if (windowingMode == WINDOWING_MODE_UNDEFINED) {
                // Else fullscreen for now...
                windowingMode = WINDOWING_MODE_FULLSCREEN;
            }
        }

        final int stackId = getNextStackId();
        return createStackUnchecked(windowingMode, activityType, stackId, onTop);
    }
@@ -578,7 +568,21 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack>
                windowingMode = getWindowingMode();
            }
        }
        return validateWindowingMode(windowingMode, r, task, activityType);
    }

    /**
     * Check that the requested windowing-mode is appropriate for the specified task and/or activity
     * on this display.
     *
     * @param windowingMode The windowing-mode to validate.
     * @param r The {@link ActivityRecord} to check against.
     * @param task The {@link TaskRecord} to check against.
     * @param activityType An activity type.
     * @return The provided windowingMode or the closest valid mode which is appropriate.
     */
    int validateWindowingMode(int windowingMode, @Nullable ActivityRecord r,
        @Nullable TaskRecord task, int activityType) {
        // Make sure the windowing mode we are trying to use makes sense for what is supported.
        final ActivityTaskManagerService service = mSupervisor.mService;
        boolean supportsMultiWindow = service.mSupportsMultiWindow;
+15 −19
Original line number Diff line number Diff line
@@ -537,15 +537,17 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        final ActivityStack splitScreenStack = display.getSplitScreenPrimaryStack();
        mTmpOptions.setLaunchWindowingMode(preferredWindowingMode);

        int windowingMode = preferredWindowingMode;
        // Need to make sure windowing mode is supported. If we in the process of creating the stack
        // no need to resolve the windowing mode again as it is already resolved to the right mode.
        int windowingMode = creating
                ? preferredWindowingMode
                : display.resolveWindowingMode(
                        null /* ActivityRecord */, mTmpOptions, topTask, getActivityType());
        if (splitScreenStack == this && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) {
            // Resolution to split-screen secondary for the primary split-screen stack means we want
            // to go fullscreen.
        if (!creating) {
            windowingMode = display.validateWindowingMode(windowingMode,
                    null /* ActivityRecord */, topTask, getActivityType());
        }
        if (splitScreenStack == this
                && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) {
            // Resolution to split-screen secondary for the primary split-screen stack means
            // we want to go fullscreen.
            windowingMode = WINDOWING_MODE_FULLSCREEN;
        }

@@ -595,6 +597,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                mStackSupervisor.mNoAnimActivities.add(topActivity);
            }
            super.setWindowingMode(windowingMode);
            windowingMode = getWindowingMode();

            if (creating) {
                // Nothing else to do if we don't have a window container yet. E.g. call from ctor.
@@ -621,15 +624,6 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
            mTmpRect2.setEmpty();
            if (windowingMode != WINDOWING_MODE_FULLSCREEN) {
                mWindowContainerController.getRawBounds(mTmpRect2);
                if (windowingMode == WINDOWING_MODE_FREEFORM) {
                    if (topTask != null) {
                        // TODO: Can we consolidate this and other sites that call this methods?
                        Rect bounds = topTask().getLaunchBounds();
                        if (bounds != null) {
                            mTmpRect2.set(bounds);
                        }
                    }
                }
            }

            if (!Objects.equals(getOverrideBounds(), mTmpRect2)) {
@@ -4818,9 +4812,11 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                        // For freeform stack we don't adjust the size of the tasks to match that
                        // of the stack, but we do try to make sure the tasks are still contained
                        // with the bounds of the stack.
                        if (task.getOverrideBounds() != null) {
                            mTmpRect2.set(task.getOverrideBounds());
                            fitWithinBounds(mTmpRect2, bounds);
                            task.updateOverrideConfiguration(mTmpRect2);
                        }
                    } else {
                        task.updateOverrideConfiguration(taskBounds, insetBounds);
                    }
+9 −12
Original line number Diff line number Diff line
@@ -2344,6 +2344,9 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
        }
    }

    /**
     * This doesn't just find a task, it also moves the task to front.
     */
    void findTaskToMoveToFront(TaskRecord task, int flags, ActivityOptions options, String reason,
            boolean forceNonResizeable) {
        final ActivityStack currentStack = task.getStack();
@@ -2613,19 +2616,13 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
            case ACTIVITY_TYPE_RECENTS: return r.isActivityTypeRecents();
            case ACTIVITY_TYPE_ASSISTANT: return r.isActivityTypeAssistant();
        }
        switch (stack.getWindowingMode()) {
            case WINDOWING_MODE_FULLSCREEN: return true;
            case WINDOWING_MODE_FREEFORM: return r.supportsFreeform();
            case WINDOWING_MODE_PINNED: return r.supportsPictureInPicture();
            case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: return r.supportsSplitScreenWindowingMode();
            case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: return r.supportsSplitScreenWindowingMode();
        }

        if (!stack.isOnHomeDisplay()) {
            return r.canBeLaunchedOnDisplay(displayId);
        }
        Slog.e(TAG, "isValidLaunchStack: Unexpected stack=" + stack);
        // There is a 1-to-1 relationship between stack and task when not in
        // primary split-windowing mode.
        if (stack.getWindowingMode() != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
            return false;
        } else {
            return r.supportsSplitScreenWindowingMode();
        }
    }

    /**
+10 −2
Original line number Diff line number Diff line
@@ -1748,6 +1748,14 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi
        return updateOverrideConfiguration(bounds, null /* insetBounds */);
    }

    void setLastNonFullscreenBounds(Rect bounds) {
        if (mLastNonFullscreenBounds == null) {
            mLastNonFullscreenBounds = new Rect(bounds);
        } else {
            mLastNonFullscreenBounds.set(bounds);
        }
    }

    /**
     * Update task's override configuration based on the bounds.
     * @param bounds The bounds of the task.
@@ -1769,7 +1777,7 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi
        final boolean persistBounds = getWindowConfiguration().persistTaskBounds();
        if (matchParentBounds) {
            if (!currentBounds.isEmpty() && persistBounds) {
                mLastNonFullscreenBounds = currentBounds;
                setLastNonFullscreenBounds(currentBounds);
            }
            setBounds(null);
            newConfig.unset();
@@ -1779,7 +1787,7 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi
            setBounds(mTmpRect);

            if (mStack == null || persistBounds) {
                mLastNonFullscreenBounds = getOverrideBounds();
                setLastNonFullscreenBounds(getOverrideBounds());
            }
            computeOverrideConfiguration(newConfig, mTmpRect, insetBounds,
                    mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);