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

Commit cc54a24c authored by Graciela Putri's avatar Graciela Putri Committed by Android (Google) Code Review
Browse files

Merge "Sandbox all usages of parent app bounds for targetSDK < 35" into main

parents 7054862e 465043a7
Loading
Loading
Loading
Loading
+22 −29
Original line number Diff line number Diff line
@@ -661,7 +661,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     */
    private CompatDisplayInsets mCompatDisplayInsets;
    private final TaskFragment.ConfigOverrideHint mResolveConfigHint;
    @VisibleForTesting
    final TaskFragment.ConfigOverrideHint mResolveConfigHint;
    private final boolean mOptOutEdgeToEdge;
@@ -8533,6 +8534,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        mIsEligibleForFixedOrientationLetterbox = false;
        mLetterboxBoundsForFixedOrientationAndAspectRatio = null;
        mLetterboxBoundsForAspectRatio = null;
        mResolveConfigHint.resolveTmpOverrides(mDisplayContent, newParentConfiguration,
                isFixedRotationTransforming());
        // Can't use resolvedConfig.windowConfiguration.getWindowingMode() because it can be
        // different from windowing mode of the task (PiP) during transition from fullscreen to PiP
@@ -8647,10 +8650,15 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        applySizeOverrideIfNeeded(newParentConfiguration, parentWindowingMode, resolvedConfig);
        mResolveConfigHint.resetTmpOverrides();
        logAppCompatState();
    }
    @Nullable Rect getParentAppBoundsOverride() {
        return Rect.copyOrNull(mResolveConfigHint.mTmpParentAppBoundsOverride);
    }
    /**
     * If necessary, override configuration fields related to app bounds.
     * This will happen when the app is targeting SDK earlier than 35.
@@ -8674,8 +8682,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            rotation = mDisplayContent.getRotation();
        }
        if (!mOptOutEdgeToEdge && (!mResolveConfigHint.mUseOverrideInsetsForConfig
                || getCompatDisplayInsets() != null || shouldCreateCompatDisplayInsets()
                || isFloating(parentWindowingMode) || rotation == ROTATION_UNDEFINED)) {
                || getCompatDisplayInsets() != null || isFloating(parentWindowingMode)
                || rotation == ROTATION_UNDEFINED)) {
            // If the insets configuration decoupled logic is not enabled for the app, or the app
            // already has a compat override, or the context doesn't contain enough info to
            // calculate the override, skip the override.
@@ -8713,12 +8721,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        density *= DisplayMetrics.DENSITY_DEFAULT_SCALE;
        if (inOutConfig.screenWidthDp == Configuration.SCREEN_WIDTH_DP_UNDEFINED) {
            final int overrideScreenWidthDp = (int) (outAppBounds.width() / density + 0.5f);
            inOutConfig.screenWidthDp = overrideScreenWidthDp;
            inOutConfig.screenWidthDp = (int) (outAppBounds.width() / density + 0.5f);
        }
        if (inOutConfig.screenHeightDp == Configuration.SCREEN_HEIGHT_DP_UNDEFINED) {
            final int overrideScreenHeightDp = (int) (outAppBounds.height() / density + 0.5f);
            inOutConfig.screenHeightDp = overrideScreenHeightDp;
            inOutConfig.screenHeightDp = (int) (outAppBounds.height() / density + 0.5f);
        }
        if (inOutConfig.smallestScreenWidthDp
                == Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED
@@ -8829,7 +8835,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        final Rect screenResolvedBounds =
                mSizeCompatBounds != null ? mSizeCompatBounds : resolvedBounds;
        final Rect parentAppBounds = newParentConfiguration.windowConfiguration.getAppBounds();
        final Rect parentAppBounds = mResolveConfigHint.mTmpParentAppBoundsOverride;
        final Rect parentBounds = newParentConfiguration.windowConfiguration.getBounds();
        final float screenResolvedBoundsWidth = screenResolvedBounds.width();
        final float parentAppBoundsWidth = parentAppBounds.width();
@@ -9238,7 +9244,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     */
    private void resolveAspectRatioRestriction(Configuration newParentConfiguration) {
        final Configuration resolvedConfig = getResolvedOverrideConfiguration();
        final Rect parentAppBounds = newParentConfiguration.windowConfiguration.getAppBounds();
        final Rect parentAppBounds = mResolveConfigHint.mTmpParentAppBoundsOverride;
        final Rect parentBounds = newParentConfiguration.windowConfiguration.getBounds();
        final Rect resolvedBounds = resolvedConfig.windowConfiguration.getBounds();
        // Use tmp bounds to calculate aspect ratio so we can know whether the activity should use
@@ -9267,19 +9273,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            @NonNull CompatDisplayInsets compatDisplayInsets) {
        final Configuration resolvedConfig = getResolvedOverrideConfiguration();
        final Rect resolvedBounds = resolvedConfig.windowConfiguration.getBounds();
        final Insets insets;
        if (mResolveConfigHint.mUseOverrideInsetsForConfig) {
            // TODO(b/343197837): Add test to verify SCM behaviour with new bound configuration
            // Insets are decoupled from configuration by default from V+, use legacy
            // compatibility behaviour for apps targeting SDK earlier than 35
            // (see applySizeOverrideIfNeeded).
            insets = Insets.of(mDisplayContent.getDisplayPolicy()
                    .getDecorInsetsInfo(mDisplayContent.mDisplayFrames.mRotation,
                            mDisplayContent.mDisplayFrames.mWidth,
                            mDisplayContent.mDisplayFrames.mHeight).mOverrideNonDecorInsets);
        } else {
            insets = Insets.NONE;
        }
        // When an activity needs to be letterboxed because of fixed orientation, use fixed
        // orientation bounds (stored in resolved bounds) instead of parent bounds since the
@@ -9290,22 +9283,22 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        final Rect containerBounds = useResolvedBounds
                ? new Rect(resolvedBounds)
                : newParentConfiguration.windowConfiguration.getBounds();
        final Rect parentAppBounds =
                newParentConfiguration.windowConfiguration.getAppBounds();
        parentAppBounds.inset(insets);
        final Rect containerAppBounds = useResolvedBounds
                ? new Rect(resolvedConfig.windowConfiguration.getAppBounds())
                : parentAppBounds;
                : mResolveConfigHint.mTmpParentAppBoundsOverride;
        final int requestedOrientation = getRequestedConfigurationOrientation();
        final boolean orientationRequested = requestedOrientation != ORIENTATION_UNDEFINED;
        final int parentOrientation = mResolveConfigHint.mUseOverrideInsetsForConfig
                ? mResolveConfigHint.mTmpOverrideConfigOrientation
                : newParentConfiguration.orientation;
        final int orientation = orientationRequested
                ? requestedOrientation
                // We should use the original orientation of the activity when possible to avoid
                // forcing the activity in the opposite orientation.
                : compatDisplayInsets.mOriginalRequestedOrientation != ORIENTATION_UNDEFINED
                        ? compatDisplayInsets.mOriginalRequestedOrientation
                        : newParentConfiguration.orientation;
                        : parentOrientation;
        int rotation = newParentConfiguration.windowConfiguration.getRotation();
        final boolean isFixedToUserRotation = mDisplayContent == null
                || mDisplayContent.getDisplayRotation().isFixedToUserRotation();
@@ -9347,7 +9340,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // Use parent orientation if it cannot be decided by bounds, so the activity can fit inside
        // the parent bounds appropriately.
        if (resolvedConfig.screenWidthDp == resolvedConfig.screenHeightDp) {
            resolvedConfig.orientation = newParentConfiguration.orientation;
            resolvedConfig.orientation = parentOrientation;
        }
        // Below figure is an example that puts an activity which was launched in a larger container
+10 −8
Original line number Diff line number Diff line
@@ -1288,6 +1288,9 @@ final class LetterboxUiController {
        if (!allowHorizontalReachabilityForThinLetterbox()) {
            return false;
        }
        final Rect parentAppBoundsOverride = mActivityRecord.getParentAppBoundsOverride();
        final Rect parentAppBounds = parentAppBoundsOverride != null
                ? parentAppBoundsOverride : parentConfiguration.windowConfiguration.getAppBounds();
        // Use screen resolved bounds which uses resolved bounds or size compat bounds
        // as activity bounds can sometimes be empty
        final Rect opaqueActivityBounds = mActivityRecord.mTransparentPolicy
@@ -1297,10 +1300,8 @@ final class LetterboxUiController {
                && parentConfiguration.windowConfiguration.getWindowingMode()
                        == WINDOWING_MODE_FULLSCREEN
                // Check whether the activity fills the parent vertically.
                && parentConfiguration.windowConfiguration.getAppBounds().height()
                        <= opaqueActivityBounds.height()
                && parentConfiguration.windowConfiguration.getAppBounds().width()
                        > opaqueActivityBounds.width();
                && parentAppBounds.height() <= opaqueActivityBounds.height()
                && parentAppBounds.width() > opaqueActivityBounds.width();
    }

    @VisibleForTesting
@@ -1326,6 +1327,9 @@ final class LetterboxUiController {
        if (!allowVerticalReachabilityForThinLetterbox()) {
            return false;
        }
        final Rect parentAppBoundsOverride = mActivityRecord.getParentAppBoundsOverride();
        final Rect parentAppBounds = parentAppBoundsOverride != null
                ? parentAppBoundsOverride : parentConfiguration.windowConfiguration.getAppBounds();
        // Use screen resolved bounds which uses resolved bounds or size compat bounds
        // as activity bounds can sometimes be empty.
        final Rect opaqueActivityBounds = mActivityRecord.mTransparentPolicy
@@ -1335,10 +1339,8 @@ final class LetterboxUiController {
                && parentConfiguration.windowConfiguration.getWindowingMode()
                        == WINDOWING_MODE_FULLSCREEN
                // Check whether the activity fills the parent horizontally.
                && parentConfiguration.windowConfiguration.getAppBounds().width()
                        <= opaqueActivityBounds.width()
                && parentConfiguration.windowConfiguration.getAppBounds().height()
                        > opaqueActivityBounds.height();
                && parentAppBounds.width() <= opaqueActivityBounds.width()
                && parentAppBounds.height() > opaqueActivityBounds.height();
    }

    @VisibleForTesting
+42 −1
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ import static android.os.Process.INVALID_UID;
import static android.os.Process.SYSTEM_UID;
import static android.os.UserHandle.USER_NULL;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_OPEN_BEHIND;
@@ -87,6 +89,7 @@ import android.content.PermissionChecker;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.IBinder;
@@ -2225,7 +2228,43 @@ class TaskFragment extends WindowContainer<WindowContainer> {
    static class ConfigOverrideHint {
        @Nullable DisplayInfo mTmpOverrideDisplayInfo;
        @Nullable ActivityRecord.CompatDisplayInsets mTmpCompatInsets;
        @Nullable Rect mTmpParentAppBoundsOverride;
        int mTmpOverrideConfigOrientation;
        boolean mUseOverrideInsetsForConfig;

        void resolveTmpOverrides(DisplayContent dc, Configuration parentConfig,
                boolean isFixedRotationTransforming) {
            mTmpParentAppBoundsOverride = new Rect(parentConfig.windowConfiguration.getAppBounds());
            final Insets insets;
            if (mUseOverrideInsetsForConfig && dc != null) {
                // Insets are decoupled from configuration by default from V+, use legacy
                // compatibility behaviour for apps targeting SDK earlier than 35
                // (see applySizeOverrideIfNeeded).
                int rotation = parentConfig.windowConfiguration.getRotation();
                if (rotation == ROTATION_UNDEFINED && !isFixedRotationTransforming) {
                    rotation = dc.getRotation();
                }
                final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
                final int dw = rotated ? dc.mBaseDisplayHeight : dc.mBaseDisplayWidth;
                final int dh = rotated ? dc.mBaseDisplayWidth : dc.mBaseDisplayHeight;
                DisplayPolicy.DecorInsets.Info decorInsets = dc.getDisplayPolicy()
                        .getDecorInsetsInfo(rotation, dw, dh);
                final Rect stableBounds = decorInsets.mOverrideConfigFrame;
                mTmpOverrideConfigOrientation = stableBounds.width() > stableBounds.height()
                                ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT;
                insets = Insets.of(decorInsets.mOverrideNonDecorInsets);
            } else {
                insets = Insets.NONE;
            }
            mTmpParentAppBoundsOverride.inset(insets);
        }

        void resetTmpOverrides() {
            mTmpOverrideDisplayInfo = null;
            mTmpCompatInsets = null;
            mTmpParentAppBoundsOverride = null;
            mTmpOverrideConfigOrientation = ORIENTATION_UNDEFINED;
        }
    }

    void computeConfigResourceOverrides(@NonNull Configuration inOutConfig,
@@ -2311,7 +2350,9 @@ class TaskFragment extends WindowContainer<WindowContainer> {
            if (!customContainerPolicy && windowingMode != WINDOWING_MODE_FREEFORM) {
                final Rect containingAppBounds;
                if (insideParentBounds) {
                    containingAppBounds = parentConfig.windowConfiguration.getAppBounds();
                    containingAppBounds = useOverrideInsetsForConfig
                            ? overrideHint.mTmpParentAppBoundsOverride
                            : parentConfig.windowConfiguration.getAppBounds();
                } else {
                    // Restrict appBounds to display non-decor rather than parent because the
                    // override bounds are beyond the parent. Otherwise, it won't match the
+130 −242

File changed.

Preview size limit exceeded, changes collapsed.