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

Commit 428e77b4 authored by Ats Jenk's avatar Ats Jenk
Browse files

Clear task bounds when ActivityOptions request 0,0

Support clearing multi-window task bounds if they are set to 0,0 in
launch bounds in ActivityOptions.
Previously, empty bounds in LaunchParams were treated as the default
value, and not applied.
This change introduces a new property in LaunchParams that is set by
TaskLaunchParamsModifier to indicate that the bounds are set.
This allows LaunchParamsController#layoutTask to determine that new
bounds are requested, even if they are 0,0.

Fixes a scenario with split screen where a task that previously had
bounds set, is launched to split screen. Split screen expects the task
to not have bounds set and that the task should inherit the bounds from
the root task. Allowing split to request 0,0 launch bounds through
ActivityOptions fixes the issue with task having bounds set on it.

Bug: 396315875
Test: atest WmTests:LaunchParamsControllerTests
Flag: EXEMPT, bugfix
Change-Id: Idc16473e488d7e4bfda98f8d49e2f6ae68762c97
parent 908799c4
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -133,12 +133,20 @@ class LaunchParamsController {
                mTmpParams);

        // No changes, return.
        if (mTmpParams.isEmpty() || mTmpParams.mBounds.isEmpty()) {
        if (mTmpParams.isEmpty()) {
            return false;
        }

        mService.deferWindowLayout();
        try {
            if (mTmpParams.mBounds.isEmpty()) {
                if (!mTmpParams.mBoundsSet) {
                    return false;
                }
                // reset the task bounds
                task.setBounds(mTmpParams.mBounds);
                return true;
            }
            if (task.getRootTask().inMultiWindowMode()) {
                if (!mTmpParams.mAppBounds.isEmpty()) {
                    task.getRequestedOverrideConfiguration().windowConfiguration.setAppBounds(
@@ -176,6 +184,8 @@ class LaunchParamsController {
        /** The bounds within the parent container. */
        @NonNull
        final Rect mBounds = new Rect();
        /** Whether the bounds have been set. */
        boolean mBoundsSet = false;
        /** The bounds within the parent container respecting insets. Usually empty. */
        @NonNull
        final Rect mAppBounds = new Rect();
@@ -195,6 +205,7 @@ class LaunchParamsController {
        /** Sets values back to default. {@link #isEmpty} will return {@code true} once called. */
        void reset() {
            mBounds.setEmpty();
            mBoundsSet = false;
            mAppBounds.setEmpty();
            mPreferredTaskDisplayArea = null;
            mWindowingMode = WINDOWING_MODE_UNDEFINED;
@@ -204,6 +215,7 @@ class LaunchParamsController {
        /** Copies the values set on the passed in {@link LaunchParams}. */
        void set(LaunchParams params) {
            mBounds.set(params.mBounds);
            mBoundsSet = params.mBoundsSet;
            mAppBounds.set(params.mAppBounds);
            mPreferredTaskDisplayArea = params.mPreferredTaskDisplayArea;
            mWindowingMode = params.mWindowingMode;
@@ -213,6 +225,7 @@ class LaunchParamsController {
        /** Merges the values set on the passed in {@link LaunchParams}. */
        void merge(LaunchParams params) {
            mBounds.set(params.mBounds);
            mBoundsSet = params.mBoundsSet;
            mAppBounds.set(params.mAppBounds);
            mPreferredTaskDisplayArea = params.mPreferredTaskDisplayArea;
            mWindowingMode = params.mWindowingMode;
@@ -225,7 +238,8 @@ class LaunchParamsController {

        /** Returns {@code true} if no values have been explicitly set. */
        boolean isEmpty() {
            return mBounds.isEmpty() && mAppBounds.isEmpty() && mPreferredTaskDisplayArea == null
            return (mBounds.isEmpty() && !mBoundsSet) && mAppBounds.isEmpty()
                    && mPreferredTaskDisplayArea == null
                    && mWindowingMode == WINDOWING_MODE_UNDEFINED && mNeedsSafeRegionBounds == null;
        }

@@ -248,12 +262,14 @@ class LaunchParamsController {
            if (mWindowingMode != that.mWindowingMode) return false;
            if (!mAppBounds.equals(that.mAppBounds)) return false;
            if (!Objects.equals(mNeedsSafeRegionBounds, that.mNeedsSafeRegionBounds)) return false;
            if (mBoundsSet != that.mBoundsSet) return false;
            return !mBounds.isEmpty() ? mBounds.equals(that.mBounds) : that.mBounds.isEmpty();
        }

        @Override
        public int hashCode() {
            int result = !mBounds.isEmpty() ? mBounds.hashCode() : 0;
            result = 31 * result + Boolean.hashCode(mBoundsSet);
            result = 31 * result + mAppBounds.hashCode();
            result = 31 * result + (mPreferredTaskDisplayArea != null
                    ? mPreferredTaskDisplayArea.hashCode() : 0);
+1 −0
Original line number Diff line number Diff line
@@ -225,6 +225,7 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
            // TODO: Investigate whether we can migrate this clause to the
            //  |canApplyBoundsFromActivityOptions| case above.
            outParams.mBounds.set(options.getLaunchBounds());
            outParams.mBoundsSet = true;
            hasInitialBounds = true;
            if (DEBUG) appendLog("multiwindow-activity-options-bounds=" + outParams.mBounds);
        }
+25 −0
Original line number Diff line number Diff line
@@ -504,6 +504,31 @@ public class LaunchParamsControllerTests extends WindowTestsBase {
        assertEquals(expected, task.getRequestedOverrideBounds());
    }

    /**
     * Ensures that {@link LaunchParamsModifier} request for bounds to be cleared during layout
     * is honored if window is in multiwindow mode.
     */
    @Test
    public void testLayoutTaskBoundsChangeMultiWindow_applyRequestedEmptyBounds() {
        final Rect emptyBounds = new Rect();

        final LaunchParams params = new LaunchParams();
        params.mBounds.set(emptyBounds);
        params.mBoundsSet = true;
        final InstrumentedPositioner positioner = new InstrumentedPositioner(RESULT_DONE, params);
        final Task task = new TaskBuilder(mAtm.mTaskSupervisor)
                .setWindowingMode(WINDOWING_MODE_MULTI_WINDOW).build();
        task.setBounds(10, 20, 30, 40);

        mController.registerModifier(positioner);

        assertNotEquals(emptyBounds, task.getBounds());

        layoutTask(task);

        assertEquals(emptyBounds, task.getRequestedOverrideBounds());
    }

    /**
     * Ensures that {@link LaunchParamsModifier} requests specifying bounds during
     * layout are set to last non-fullscreen bounds.