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

Commit 9277009d authored by Yunfan Chen's avatar Yunfan Chen Committed by Peter Kalauskas
Browse files

Revert "Integrate insets compat override with other overrides"

This reverts commit 097af2f3.

Reason for revert: b/341386374
Bug: 341386374
Bug: 341558206
Bug: 341318600

Change-Id: Icd0db6984e466a0a3cd46ccaf1ea53d83b376c74
parent 91c55ede
Loading
Loading
Loading
Loading
+59 −11
Original line number Diff line number Diff line
@@ -339,6 +339,7 @@ import android.service.contentcapture.ActivityEvent;
import android.service.dreams.DreamActivity;
import android.service.voice.IVoiceInteractionSession;
import android.util.ArraySet;
import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.Log;
import android.util.MergedConfiguration;
@@ -2140,14 +2141,14 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (mWmService.mFlags.mInsetsDecoupledConfiguration) {
            // When the stable configuration is the default behavior, override for the legacy apps
            // without forward override flag.
            mResolveConfigHint.mUseOverrideInsetsForConfig =
            mResolveConfigHint.mUseOverrideInsetsForStableBounds =
                    !info.isChangeEnabled(INSETS_DECOUPLED_CONFIGURATION_ENFORCED)
                            && !info.isChangeEnabled(
                                    OVERRIDE_ENABLE_INSETS_DECOUPLED_CONFIGURATION);
        } else {
            // When the stable configuration is not the default behavior, forward overriding the
            // listed apps.
            mResolveConfigHint.mUseOverrideInsetsForConfig =
            mResolveConfigHint.mUseOverrideInsetsForStableBounds =
                    info.isChangeEnabled(OVERRIDE_ENABLE_INSETS_DECOUPLED_CONFIGURATION);
        }
@@ -8512,7 +8513,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        mCompatDisplayInsets =
                new CompatDisplayInsets(
                        mDisplayContent, this, letterboxedContainerBounds,
                        mResolveConfigHint.mUseOverrideInsetsForConfig);
                        mResolveConfigHint.mUseOverrideInsetsForStableBounds);
    }
    private void clearSizeCompatModeAttributes() {
@@ -8592,6 +8593,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        final int parentWindowingMode =
                newParentConfiguration.windowConfiguration.getWindowingMode();
        applySizeOverrideIfNeeded(newParentConfiguration, parentWindowingMode, resolvedConfig);
        // Bubble activities should always fill their parent and should not be letterboxed.
        final boolean isFixedOrientationLetterboxAllowed = !getLaunchedFromBubble()
                && (parentWindowingMode == WINDOWING_MODE_MULTI_WINDOW
@@ -8691,8 +8694,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            resolvedConfig.windowConfiguration.setMaxBounds(mTmpBounds);
        }
        applySizeOverrideIfNeeded(newParentConfiguration, parentWindowingMode, resolvedConfig);
        logAppCompatState();
    }
@@ -8711,11 +8712,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (mDisplayContent == null) {
            return;
        }
        final Rect parentBounds = newParentConfiguration.windowConfiguration.getBounds();
        int rotation = newParentConfiguration.windowConfiguration.getRotation();
        if (rotation == ROTATION_UNDEFINED && !isFixedRotationTransforming()) {
            rotation = mDisplayContent.getRotation();
        }
        if (!mOptOutEdgeToEdge && (!mResolveConfigHint.mUseOverrideInsetsForConfig
        if (!mOptOutEdgeToEdge && (!mResolveConfigHint.mUseOverrideInsetsForStableBounds
                || getCompatDisplayInsets() != null || isFloating(parentWindowingMode)
                || rotation == ROTATION_UNDEFINED)) {
            // If the insets configuration decoupled logic is not enabled for the app, or the app
@@ -8734,7 +8736,53 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        // Override starts here.
        computeConfigByResolveHint(inOutConfig, newParentConfiguration);
        final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
        final int dw = rotated ? mDisplayContent.mBaseDisplayHeight
                : mDisplayContent.mBaseDisplayWidth;
        final int dh = rotated ? mDisplayContent.mBaseDisplayWidth
                : mDisplayContent.mBaseDisplayHeight;
        final  Rect nonDecorInsets = mDisplayContent.getDisplayPolicy()
                .getDecorInsetsInfo(rotation, dw, dh).mOverrideNonDecorInsets;
        // This should be the only place override the configuration for ActivityRecord. Override
        // the value if not calculated yet.
        Rect outAppBounds = inOutConfig.windowConfiguration.getAppBounds();
        if (outAppBounds == null || outAppBounds.isEmpty()) {
            inOutConfig.windowConfiguration.setAppBounds(parentBounds);
            outAppBounds = inOutConfig.windowConfiguration.getAppBounds();
            outAppBounds.inset(nonDecorInsets);
        }
        float density = inOutConfig.densityDpi;
        if (density == Configuration.DENSITY_DPI_UNDEFINED) {
            density = newParentConfiguration.densityDpi;
        }
        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;
        }
        if (inOutConfig.screenHeightDp == Configuration.SCREEN_HEIGHT_DP_UNDEFINED) {
            final int overrideScreenHeightDp = (int) (outAppBounds.height() / density + 0.5f);
            inOutConfig.screenHeightDp = overrideScreenHeightDp;
        }
        if (inOutConfig.smallestScreenWidthDp
                == Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED
                && parentWindowingMode == WINDOWING_MODE_FULLSCREEN) {
            // For the case of PIP transition and multi-window environment, the
            // smallestScreenWidthDp is handled already. Override only if the app is in
            // fullscreen.
            final DisplayInfo info = new DisplayInfo(mDisplayContent.getDisplayInfo());
            mDisplayContent.computeSizeRanges(info, rotated, dw, dh,
                    mDisplayContent.getDisplayMetrics().density,
                    inOutConfig, true /* overrideConfig */);
        }
        // It's possible that screen size will be considered in different orientation with or
        // without considering the system bar insets. Override orientation as well.
        if (inOutConfig.orientation == ORIENTATION_UNDEFINED) {
            inOutConfig.orientation =
                    (inOutConfig.screenWidthDp <= inOutConfig.screenHeightDp)
                            ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
        }
    }
    private void computeConfigByResolveHint(@NonNull Configuration resolvedConfig,
@@ -8990,7 +9038,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (mDisplayContent == null) {
            return true;
        }
        if (!mResolveConfigHint.mUseOverrideInsetsForConfig) {
        if (!mResolveConfigHint.mUseOverrideInsetsForStableBounds) {
            // No insets should be considered any more.
            return true;
        }
@@ -9009,7 +9057,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        final Task task = getTask();
        task.calculateInsetFrames(outNonDecorBounds /* outNonDecorBounds */,
                outStableBounds /* outStableBounds */, parentBounds /* bounds */, di,
                mResolveConfigHint.mUseOverrideInsetsForConfig);
                mResolveConfigHint.mUseOverrideInsetsForStableBounds);
        final int orientationWithInsets = outStableBounds.height() >= outStableBounds.width()
                ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
        // If orientation does not match the orientation with insets applied, then a
@@ -9066,7 +9114,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                getResolvedOverrideConfiguration().windowConfiguration.getBounds();
        final int stableBoundsOrientation = stableBounds.width() > stableBounds.height()
                ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT;
        final int parentOrientation = mResolveConfigHint.mUseOverrideInsetsForConfig
        final int parentOrientation = mResolveConfigHint.mUseOverrideInsetsForStableBounds
                ? stableBoundsOrientation : newParentConfig.orientation;
        // If the activity requires a different orientation (either by override or activityInfo),
@@ -9091,7 +9139,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            return;
        }
        final Rect parentAppBounds = mResolveConfigHint.mUseOverrideInsetsForConfig
        final Rect parentAppBounds = mResolveConfigHint.mUseOverrideInsetsForStableBounds
                ? outNonDecorBounds : newParentConfig.windowConfiguration.getAppBounds();
        // TODO(b/182268157): Explore using only one type of parentBoundsWithInsets, either app
        // bounds or stable bounds to unify aspect ratio logic.
+5 −26
Original line number Diff line number Diff line
@@ -40,8 +40,6 @@ 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;
@@ -2224,7 +2222,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
    static class ConfigOverrideHint {
        @Nullable DisplayInfo mTmpOverrideDisplayInfo;
        @Nullable ActivityRecord.CompatDisplayInsets mTmpCompatInsets;
        boolean mUseOverrideInsetsForConfig;
        boolean mUseOverrideInsetsForStableBounds;
    }

    void computeConfigResourceOverrides(@NonNull Configuration inOutConfig,
@@ -2257,11 +2255,11 @@ class TaskFragment extends WindowContainer<WindowContainer> {
            @NonNull Configuration parentConfig, @Nullable ConfigOverrideHint overrideHint) {
        DisplayInfo overrideDisplayInfo = null;
        ActivityRecord.CompatDisplayInsets compatInsets = null;
        boolean useOverrideInsetsForConfig = false;
        boolean useOverrideInsetsForStableBounds = false;
        if (overrideHint != null) {
            overrideDisplayInfo = overrideHint.mTmpOverrideDisplayInfo;
            compatInsets = overrideHint.mTmpCompatInsets;
            useOverrideInsetsForConfig = overrideHint.mUseOverrideInsetsForConfig;
            useOverrideInsetsForStableBounds = overrideHint.mUseOverrideInsetsForStableBounds;
            if (overrideDisplayInfo != null) {
                // Make sure the screen related configs can be computed by the provided
                // display info.
@@ -2325,7 +2323,6 @@ class TaskFragment extends WindowContainer<WindowContainer> {
            }
        }

        boolean insetsOverrideApplied = false;
        if (inOutConfig.screenWidthDp == Configuration.SCREEN_WIDTH_DP_UNDEFINED
                || inOutConfig.screenHeightDp == Configuration.SCREEN_HEIGHT_DP_UNDEFINED) {
            if (!customContainerPolicy && WindowConfiguration.isFloating(windowingMode)) {
@@ -2342,7 +2339,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                // The non decor inset are areas that could never be removed in Honeycomb. See
                // {@link WindowManagerPolicy#getNonDecorInsetsLw}.
                calculateInsetFrames(mTmpNonDecorBounds, mTmpStableBounds, mTmpFullBounds, di,
                        useOverrideInsetsForConfig);
                        useOverrideInsetsForStableBounds);
            } else {
                // Apply the given non-decor and stable insets to calculate the corresponding bounds
                // for screen size of configuration.
@@ -2359,21 +2356,8 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                    intersectWithInsetsIfFits(mTmpStableBounds, mTmpBounds,
                            compatInsets.mStableInsets[rotation]);
                    outAppBounds.set(mTmpNonDecorBounds);
                } else if (useOverrideInsetsForConfig) {
                    final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
                    final int dw = rotated ? mDisplayContent.mBaseDisplayHeight
                            : mDisplayContent.mBaseDisplayWidth;
                    final int dh = rotated ? mDisplayContent.mBaseDisplayWidth
                            : mDisplayContent.mBaseDisplayHeight;
                    final DisplayPolicy.DecorInsets.Info decorInsets = mDisplayContent
                            .getDisplayPolicy().getDecorInsetsInfo(rotation, dw, dh);
                    mTmpStableBounds.set(outAppBounds);
                    mTmpStableBounds.inset(decorInsets.mOverrideConfigInsets);
                    outAppBounds.inset(decorInsets.mOverrideNonDecorInsets);
                    mTmpNonDecorBounds.set(outAppBounds);
                    // Record the override apply to avoid duplicated check.
                    insetsOverrideApplied = true;
                } else {
                    // Set to app bounds because it excludes decor insets.
                    mTmpNonDecorBounds.set(outAppBounds);
                    mTmpStableBounds.set(outAppBounds);
                }
@@ -2415,11 +2399,6 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                    // from the parent task would result in applications loaded wrong resource.
                    inOutConfig.smallestScreenWidthDp =
                            Math.min(inOutConfig.screenWidthDp, inOutConfig.screenHeightDp);
                } else if (insetsOverrideApplied) {
                    // The smallest width should also consider insets. If the insets are overridden,
                    // use the overridden value.
                    inOutConfig.smallestScreenWidthDp =
                            Math.min(inOutConfig.screenWidthDp, inOutConfig.screenHeightDp);
                }
                // otherwise, it will just inherit
            }