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

Commit ea86a621 authored by Rachit Jain's avatar Rachit Jain Committed by Android (Google) Code Review
Browse files

Merge "Expose safe region letterboxing information to shell" into main

parents 92d2ed23 459f492b
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -106,6 +106,8 @@ public class AppCompatTaskInfo implements Parcelable {
    private static final int FLAG_ENABLE_RESTART_MENU_FOR_DISPLAY_MOVE = FLAG_BASE << 10;
    /** Top activity flag for whether activity opted out of edge to edge. */
    public static final int FLAG_OPT_OUT_EDGE_TO_EDGE = FLAG_BASE << 11;
    /** Top activity flag for whether activity is letterboxed for a safe region. */
    public static final int FLAG_SAFE_REGION_LETTERBOXED = FLAG_BASE << 12;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag = true, value = {
@@ -121,7 +123,8 @@ public class AppCompatTaskInfo implements Parcelable {
            FLAG_FULLSCREEN_OVERRIDE_USER,
            FLAG_HAS_MIN_ASPECT_RATIO_OVERRIDE,
            FLAG_ENABLE_RESTART_MENU_FOR_DISPLAY_MOVE,
            FLAG_OPT_OUT_EDGE_TO_EDGE
            FLAG_OPT_OUT_EDGE_TO_EDGE,
            FLAG_SAFE_REGION_LETTERBOXED
    })
    public @interface TopActivityFlag {}

@@ -141,7 +144,7 @@ public class AppCompatTaskInfo implements Parcelable {
    @TopActivityFlag
    private static final int FLAGS_COMPAT_UI_INTERESTED = FLAGS_ORGANIZER_INTERESTED
            | FLAG_IN_SIZE_COMPAT | FLAG_ELIGIBLE_FOR_LETTERBOX_EDU | FLAG_LETTERBOX_EDU_ENABLED
            | FLAG_ENABLE_RESTART_MENU_FOR_DISPLAY_MOVE;
            | FLAG_ENABLE_RESTART_MENU_FOR_DISPLAY_MOVE | FLAG_SAFE_REGION_LETTERBOXED;

    private AppCompatTaskInfo() {
        // Do nothing
@@ -323,6 +326,21 @@ public class AppCompatTaskInfo implements Parcelable {
        setTopActivityFlag(FLAG_ENABLE_RESTART_MENU_FOR_DISPLAY_MOVE, enable);
    }

    /**
     * @return {@code true} if the top activity bounds are letterboxed for a safe region.
     */
    public boolean isTopActivitySafeRegionLetterboxed() {
        return isTopActivityFlagEnabled(FLAG_SAFE_REGION_LETTERBOXED);
    }

    /**
     * Sets the top activity flag for whether the top activity bounds are letterboxed for a safe
     * region.
     */
    public void setTopActivitySafeRegionLetterboxed(boolean enable) {
        setTopActivityFlag(FLAG_SAFE_REGION_LETTERBOXED, enable);
    }

    /**
     * @return {@code true} if the top activity bounds are letterboxed.
     */
+9 −0
Original line number Diff line number Diff line
@@ -7656,6 +7656,15 @@ final class ActivityRecord extends WindowToken {
        mResolveConfigHint.mTmpOverrideDisplayInfo = null;
    }

    /**
     * Returns whether activity bounds are letterboxed and are sandboxed to within the safe region
     * bounds.
     */
    boolean areSafeRegionBoundsApplied() {
        return areBoundsLetterboxed()
                && mAppCompatController.getSafeRegionPolicy().getLatestSafeRegionBounds() != null;
    }

    /**
     * Returns whether activity bounds are letterboxed.
     *
+8 −13
Original line number Diff line number Diff line
@@ -81,14 +81,15 @@ class AppCompatSafeRegionPolicy {

    /**
     * Computes the latest safe region bounds in
     * {@link ActivityRecord#resolveOverrideConfiguration(Configuration)} since the activity has not
     * been attached to the parent container when the ActivityRecord is instantiated. Note that the
     * latest safe region bounds will be empty if activity has not allowed safe region letterboxing.
     * {@link ActivityRecord#resolveOverrideConfiguration(Configuration)} since the activity has
     * not been attached to the parent container when the ActivityRecord is instantiated. Note that
     * the latest safe region bounds will be empty if activity has not allowed safe region
     * letterboxing or if the activity does not need safe region bounds.
     *
     * @return latest safe region bounds as set on an ancestor window container.
     */
    public Rect getLatestSafeRegionBounds() {
        if (!allowSafeRegionLetterboxing()) {
        if (!allowSafeRegionLetterboxing() || !getNeedsSafeRegionBounds()) {
            mLatestSafeRegionBounds.setEmpty();
            return null;
        }
@@ -107,18 +108,11 @@ class AppCompatSafeRegionPolicy {
     */
    public void resolveSafeRegionBoundsConfigurationIfNeeded(@NonNull Configuration resolvedConfig,
            @NonNull Configuration newParentConfig) {
        if (mLatestSafeRegionBounds.isEmpty()) {
            return;
        }
        // If activity can not be letterboxed for a safe region only or it has not been attached
        // to a WindowContainer yet.
        if (!isLetterboxedForSafeRegionOnlyAllowed() || mActivityRecord.getParent() == null) {
            return;
        }
        // TODO(b/403628576): Remove once activity embedding activities support letterboxing
        if (mActivityRecord.getOrganizedTaskFragment() != null) {
            return;
        }
        resolvedConfig.windowConfiguration.setBounds(mLatestSafeRegionBounds);
        mActivityRecord.computeConfigByResolveHint(resolvedConfig, newParentConfig);
    }
@@ -134,8 +128,9 @@ class AppCompatSafeRegionPolicy {
     * container.
     */
    boolean isLetterboxedForSafeRegionOnlyAllowed() {
        return !mActivityRecord.areBoundsLetterboxed() && getNeedsSafeRegionBounds()
                && getLatestSafeRegionBounds() != null;
        return !mActivityRecord.areBoundsLetterboxed() && getLatestSafeRegionBounds() != null
                // TODO(b/403628576): Remove once activity embedding activities support letterboxing
                && mActivityRecord.getOrganizedTaskFragment() == null;
    }

    /**
+7 −0
Original line number Diff line number Diff line
@@ -174,6 +174,13 @@ final class AppCompatUtils {
        appCompatTaskInfo.setRestartMenuEnabledForDisplayMove(top.mAppCompatController
                .getDisplayCompatModePolicy().isRestartMenuEnabledForDisplayMove());

        // Whether the activity is using safe region letterboxing bounds. This happens when the
        // activity is in compat mode and is being sandboxed within the safe region bounds or if
        // the safe region bounds are applied directly on the activity.
        appCompatTaskInfo.setTopActivitySafeRegionLetterboxed(top.areSafeRegionBoundsApplied()
                || top.mAppCompatController.getSafeRegionPolicy()
                    .isLetterboxedForSafeRegionOnlyAllowed());

        final AppCompatAspectRatioOverrides aspectRatioOverrides =
                top.mAppCompatController.getAspectRatioOverrides();
        appCompatTaskInfo.setUserFullscreenOverrideEnabled(