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

Commit 40aa32b3 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge changes Ib0099b0f,I4c4de052 into main

* changes:
  [1/n] Enforce Shell desktop cascading in Launch Params
  [0/n] Create bug fix flag for Shell initial bounds regression
parents 71f32e71 3e4cf0cf
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -488,6 +488,8 @@ public class ActivityOptions extends ComponentOptions {
    private static final String KEY_ALLOW_PASS_THROUGH_ON_TOUCH_OUTSIDE =
            "android.activity.allowPassThroughOnTouchOutside";

    private static final String KEY_FLEXIBLE_LAUNCH_SIZE = "android.activity.flexibleLaunchSize";

    /**
     * @see #setLaunchCookie
     * @hide
@@ -588,6 +590,7 @@ public class ActivityOptions extends ComponentOptions {
    @BackgroundActivityStartMode
    private int mPendingIntentCreatorBackgroundActivityStartMode =
            MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED;
    private boolean mFlexibleLaunchSize = false;
    private boolean mDisableStartingWindow;
    private boolean mAllowPassThroughOnTouchOutside;

@@ -1451,6 +1454,7 @@ public class ActivityOptions extends ComponentOptions {
        mPendingIntentCreatorBackgroundActivityStartMode = opts.getInt(
                KEY_PENDING_INTENT_CREATOR_BACKGROUND_ACTIVITY_START_MODE,
                MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED);
        mFlexibleLaunchSize = opts.getBoolean(KEY_FLEXIBLE_LAUNCH_SIZE, /* defaultValue = */ false);
        mDisableStartingWindow = opts.getBoolean(KEY_DISABLE_STARTING_WINDOW);
        mAllowPassThroughOnTouchOutside = opts.getBoolean(KEY_ALLOW_PASS_THROUGH_ON_TOUCH_OUTSIDE);
        mAnimationAbortListener = IRemoteCallback.Stub.asInterface(
@@ -2345,6 +2349,24 @@ public class ActivityOptions extends ComponentOptions {
        return mPendingIntentCreatorBackgroundActivityStartMode;
    }

    /**
     * Sets whether the size of the launch bounds is flexible, meaning it can be overridden to a
     * different size during the launch params calculation.
     * @hide
     */
    public ActivityOptions setFlexibleLaunchSize(boolean isFlexible) {
        mFlexibleLaunchSize = isFlexible;
        return this;
    }

    /**
     * Gets whether the size of the launch bounds is flexible.
     * @hide
     */
    public boolean getFlexibleLaunchSize() {
        return mFlexibleLaunchSize;
    }

    /**
     * Update the current values in this ActivityOptions from those supplied
     * in <var>otherOptions</var>.  Any values
@@ -2601,6 +2623,9 @@ public class ActivityOptions extends ComponentOptions {
            b.putInt(KEY_PENDING_INTENT_CREATOR_BACKGROUND_ACTIVITY_START_MODE,
                    mPendingIntentCreatorBackgroundActivityStartMode);
        }
        if (mFlexibleLaunchSize) {
            b.putBoolean(KEY_FLEXIBLE_LAUNCH_SIZE, mFlexibleLaunchSize);
        }
        if (mDisableStartingWindow) {
            b.putBoolean(KEY_DISABLE_STARTING_WINDOW, mDisableStartingWindow);
        }
+2 −0
Original line number Diff line number Diff line
@@ -114,6 +114,8 @@ public enum DesktopModeFlags {
    ENABLE_RESIZING_METRICS(Flags::enableResizingMetrics, true),
    ENABLE_RESTORE_TO_PREVIOUS_SIZE_FROM_DESKTOP_IMMERSIVE(
            Flags::enableRestoreToPreviousSizeFromDesktopImmersive, true),
    ENABLE_SHELL_INITIAL_BOUNDS_REGRESSION_BUG_FIX(
            Flags::enableShellInitialBoundsRegressionBugFix, false),
    ENABLE_START_LAUNCH_TRANSITION_FROM_TASKBAR_BUGFIX(
            Flags::enableStartLaunchTransitionFromTaskbarBugfix, true),
    ENABLE_TASKBAR_OVERFLOW(Flags::enableTaskbarOverflow, false),
+12 −0
Original line number Diff line number Diff line
@@ -37,6 +37,18 @@ flag {
    }
}

flag {
    name: "enable_shell_initial_bounds_regression_bug_fix"
    namespace: "lse_desktop_experience"
    description: "Enables fix for Shell initial bounds regression, forcing core to calculate /n"
                 "initial bounds in desktop launch params while respecting cascading position /n"
                 "passed by Shell."
    bug: "396075922"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "enable_windowing_dynamic_initial_bounds"
    namespace: "lse_desktop_experience"
+4 −0
Original line number Diff line number Diff line
@@ -1246,6 +1246,10 @@ class DesktopTasksController(
                pendingIntentBackgroundActivityStartMode =
                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS
                launchBounds = bounds
                if (DesktopModeFlags.ENABLE_SHELL_INITIAL_BOUNDS_REGRESSION_BUG_FIX.isTrue) {
                    // Sets launch bounds size as flexible so core can recalculate.
                    flexibleLaunchSize = true
                }
            }

        wct.sendPendingIntent(pendingIntent, intent, ops.toBundle())
+87 −9
Original line number Diff line number Diff line
@@ -51,6 +51,13 @@ public final class DesktopModeBoundsCalculator {
    public static final int DESKTOP_MODE_LANDSCAPE_APP_PADDING = SystemProperties
            .getInt("persist.wm.debug.desktop_mode_landscape_app_padding", 25);

    /**
     * Proportion of window height top offset with respect to bottom offset, used for central task
     * positioning. Should be kept in sync with constant in
     * {@link com.android.wm.shell.desktopmode.DesktopTaskPosition}
     */
    public static final float WINDOW_HEIGHT_PROPORTION = 0.375f;

    /**
     * Updates launch bounds for an activity with respect to its activity options, window layout,
     * android manifest and task configuration.
@@ -63,7 +70,16 @@ public final class DesktopModeBoundsCalculator {
        final Rect stableBounds = new Rect();
        task.getDisplayArea().getStableRect(stableBounds);

        if (options != null && options.getLaunchBounds() != null) {
        // If the options bounds size is flexible, update size with calculated desired size.
        final boolean updateOptionBoundsSize = options != null
                && options.getFlexibleLaunchSize();
        // If cascading is also enabled, the position of the options bounds must be respected
        // during the size update.
        final boolean shouldRespectOptionPosition =
                updateOptionBoundsSize && DesktopModeFlags.ENABLE_CASCADING_WINDOWS.isTrue();

        if (options != null && options.getLaunchBounds() != null
                && !updateOptionBoundsSize) {
            outBounds.set(options.getLaunchBounds());
            logger.accept("inherit-from-options=" + outBounds);
        } else if (layout != null) {
@@ -76,26 +92,34 @@ public final class DesktopModeBoundsCalculator {
                        stableBounds);
                logger.accept("layout specifies sizes, inheriting size and applying gravity");
            } else if (verticalGravity > 0 || horizontalGravity > 0) {
                outBounds.set(calculateInitialBounds(task, activity, stableBounds));
                outBounds.set(calculateInitialBounds(task, activity, stableBounds, options,
                        shouldRespectOptionPosition));
                applyLayoutGravity(verticalGravity, horizontalGravity, outBounds,
                        stableBounds);
                logger.accept("layout specifies gravity, applying desired bounds and gravity");
                logger.accept("respecting option bounds cascaded position="
                        + shouldRespectOptionPosition);
            }
        } else {
            outBounds.set(calculateInitialBounds(task, activity, stableBounds));
            outBounds.set(calculateInitialBounds(task, activity, stableBounds, options,
                    shouldRespectOptionPosition));
            logger.accept("layout not specified, applying desired bounds");
            logger.accept("respecting option bounds cascaded position="
                    + shouldRespectOptionPosition);
        }
    }

    /**
     * Calculates the initial bounds required for an application to fill a scale of the display
     * bounds without any letterboxing. This is done by taking into account the applications
     * fullscreen size, aspect ratio, orientation and resizability to calculate an area this is
     * compatible with the applications previous configuration.
     * fullscreen size, aspect ratio, orientation and resizability to calculate an area that is
     * compatible with the applications previous configuration. These bounds are then cascaded to
     * either the center or to a cascading position supplied by Shell via the option bounds.
     */
    @NonNull
    private static Rect calculateInitialBounds(@NonNull Task task,
            @NonNull ActivityRecord activity, @NonNull Rect stableBounds
            @NonNull ActivityRecord activity, @NonNull Rect stableBounds,
            @Nullable ActivityOptions options, boolean shouldRespectOptionPosition
    ) {
        // Display bounds not taking into account insets.
        final TaskDisplayArea displayArea = task.getDisplayArea();
@@ -172,6 +196,9 @@ public final class DesktopModeBoundsCalculator {
            }
            default -> idealSize;
        };
        if (shouldRespectOptionPosition) {
            return respectShellCascading(initialSize, stableBounds, options.getLaunchBounds());
        }
        return centerInScreen(initialSize, screenBounds);
    }

@@ -266,14 +293,65 @@ public final class DesktopModeBoundsCalculator {
     * Adjusts bounds to be positioned in the middle of the screen.
     */
    @NonNull
    private static Rect centerInScreen(@NonNull Size desiredSize,
    static Rect centerInScreen(@NonNull Size desiredSize,
            @NonNull Rect screenBounds) {
        // TODO(b/325240051): Position apps with bottom heavy offset
        final int heightOffset = (screenBounds.height() - desiredSize.getHeight()) / 2;
        final int heightOffset = (int)
                ((screenBounds.height() - desiredSize.getHeight()) * WINDOW_HEIGHT_PROPORTION);
        final int widthOffset = (screenBounds.width() - desiredSize.getWidth()) / 2;
        final Rect resultBounds = new Rect(0, 0,
                desiredSize.getWidth(), desiredSize.getHeight());
        resultBounds.offset(screenBounds.left + widthOffset, screenBounds.top + heightOffset);
        return resultBounds;
    }

    /**
     * Calculates final initial bounds based on the task's desired size and the cascading anchor
     * point extracted from the option bounds. Cascading behaviour should be kept in sync with
     * logic in {@link com.android.wm.shell.desktopmode.DesktopTaskPosition}.
     */
    @NonNull
    private static Rect respectShellCascading(@NonNull Size desiredSize, @NonNull Rect stableBounds,
            @NonNull Rect optionBounds) {
        final boolean leftAligned = stableBounds.left == optionBounds.left;
        final boolean rightAligned = stableBounds.right == optionBounds.right;
        final boolean topAligned = stableBounds.top == optionBounds.top;
        final boolean bottomAligned = stableBounds.bottom == optionBounds.bottom;
        if (leftAligned && topAligned) {
            // Bounds cascaded to top left, respect top left position anchor point.
            return new Rect(
                    optionBounds.left,
                    optionBounds.top,
                    optionBounds.left + desiredSize.getWidth(),
                    optionBounds.top + desiredSize.getHeight()
            );
        }
        if (leftAligned && bottomAligned) {
            // Bounds cascaded to bottom left, respect bottom left position anchor point.
            return new Rect(
                    optionBounds.left,
                    optionBounds.bottom - desiredSize.getHeight(),
                    optionBounds.left + desiredSize.getWidth(),
                    optionBounds.bottom
            );
        }
        if (rightAligned && topAligned) {
            // Bounds cascaded to top right, respect top right position anchor point.
            return new Rect(
                    optionBounds.right - desiredSize.getWidth(),
                    optionBounds.top,
                    optionBounds.right,
                    optionBounds.top + desiredSize.getHeight()
            );
        }
        if (rightAligned && bottomAligned) {
            // Bounds cascaded to bottom right, respect bottom right position anchor point.
            return new Rect(
                    optionBounds.right - desiredSize.getWidth(),
                    optionBounds.bottom - desiredSize.getHeight(),
                    optionBounds.right,
                    optionBounds.bottom);
        }
        // Bounds not cascaded to any corner, default to center position.
        return centerInScreen(desiredSize, stableBounds);
    }
}
Loading