diff options
| author | 2024-04-17 12:14:35 +0000 | |
|---|---|---|
| committer | 2024-04-17 12:14:35 +0000 | |
| commit | 99c067aa885d38549b764890de47acc1b475c96a (patch) | |
| tree | 4d30c6c4e834588e08b7f4b54b545913bbeccd77 | |
| parent | ed46d368dbf24a2d69454f80aacae7678e15559d (diff) | |
| parent | 609ebc0f368672984d50820e2e5c1745c0d839e4 (diff) | |
Merge "Use legacy insets for compatibility behaviour" into main
6 files changed, 147 insertions, 95 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index bf094ed57545..06003e4b910a 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -658,6 +658,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A */ private CompatDisplayInsets mCompatDisplayInsets; + private final TaskFragment.ConfigOverrideHint mResolveConfigHint; + private static ConstrainDisplayApisConfig sConstrainDisplayApisConfig; boolean pendingVoiceInteractionStart; // Waiting for activity-invoked voice session @@ -2110,6 +2112,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A mLetterboxUiController = new LetterboxUiController(mWmService, this); mCameraCompatControlEnabled = mWmService.mContext.getResources() .getBoolean(R.bool.config_isCameraCompatControlForStretchedIssuesEnabled); + mResolveConfigHint = new TaskFragment.ConfigOverrideHint(); + mResolveConfigHint.mUseLegacyInsetsForStableBounds = + mWmService.mFlags.mInsetsDecoupledConfiguration + && !info.isChangeEnabled(INSETS_DECOUPLED_CONFIGURATION_ENFORCED); mTargetSdk = info.applicationInfo.targetSdkVersion; @@ -8439,7 +8445,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // The role of CompatDisplayInsets is like the override bounds. mCompatDisplayInsets = new CompatDisplayInsets( - mDisplayContent, this, mLetterboxBoundsForFixedOrientationAndAspectRatio); + mDisplayContent, this, mLetterboxBoundsForFixedOrientationAndAspectRatio, + mResolveConfigHint.mUseLegacyInsetsForStableBounds); } private void clearSizeCompatModeAttributes() { @@ -8546,8 +8553,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // If the activity has requested override bounds, the configuration needs to be // computed accordingly. if (!matchParentBounds()) { - getTaskFragment().computeConfigResourceOverrides(resolvedConfig, - newParentConfiguration); + computeConfigByResolveHint(resolvedConfig, newParentConfiguration); } // If activity in fullscreen mode is letterboxed because of fixed orientation then bounds // are already calculated in resolveFixedOrientationConfiguration. @@ -8636,16 +8642,15 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A if (mDisplayContent == null) { return; } - final Rect fullBounds = newParentConfiguration.windowConfiguration.getAppBounds(); + final Rect parentAppBounds = newParentConfiguration.windowConfiguration.getAppBounds(); int rotation = newParentConfiguration.windowConfiguration.getRotation(); if (rotation == ROTATION_UNDEFINED && !isFixedRotationTransforming()) { rotation = mDisplayContent.getRotation(); } - if (!mWmService.mFlags.mInsetsDecoupledConfiguration - || info.isChangeEnabled(INSETS_DECOUPLED_CONFIGURATION_ENFORCED) + if (!mResolveConfigHint.mUseLegacyInsetsForStableBounds || getCompatDisplayInsets() != null - || isFloating(parentWindowingMode) || fullBounds == null - || fullBounds.isEmpty() || rotation == ROTATION_UNDEFINED) { + || isFloating(parentWindowingMode) || parentAppBounds == null + || parentAppBounds.isEmpty() || 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. @@ -8653,15 +8658,20 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } // Override starts here. - final Rect stableInsets = mDisplayContent.getDisplayPolicy().getDecorInsetsInfo( - rotation, fullBounds.width(), fullBounds.height()).mOverrideConfigInsets; + 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(fullBounds); + inOutConfig.windowConfiguration.setAppBounds(parentAppBounds); outAppBounds = inOutConfig.windowConfiguration.getAppBounds(); - outAppBounds.inset(stableInsets); + outAppBounds.inset(nonDecorInsets); } float density = inOutConfig.densityDpi; if (density == Configuration.DENSITY_DPI_UNDEFINED) { @@ -8685,11 +8695,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // For the case of PIP transition and multi-window environment, the // smallestScreenWidthDp is handled already. Override only if the app is in // fullscreen. - final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); DisplayInfo info = new DisplayInfo(); mDisplayContent.getDisplay().getDisplayInfo(info); - mDisplayContent.computeSizeRanges(info, rotated, info.logicalWidth, - info.logicalHeight, mDisplayContent.getDisplayMetrics().density, + mDisplayContent.computeSizeRanges(info, rotated, dw, dh, + mDisplayContent.getDisplayMetrics().density, inOutConfig, true /* overrideConfig */); } @@ -8702,14 +8711,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } } - /** - * @return The orientation to use to understand if reachability is enabled. - */ - @Configuration.Orientation - int getOrientationForReachability() { - return mLetterboxUiController.hasInheritedLetterboxBehavior() - ? mLetterboxUiController.getInheritedOrientation() - : getRequestedConfigurationOrientation(); + private void computeConfigByResolveHint(@NonNull Configuration resolvedConfig, + @NonNull Configuration parentConfig) { + task.computeConfigResourceOverrides(resolvedConfig, parentConfig, mResolveConfigHint); + // Reset the temp info which should only take effect for the specified computation. + mResolveConfigHint.mTmpCompatInsets = null; + mResolveConfigHint.mTmpOverrideDisplayInfo = null; } /** @@ -8852,7 +8859,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } // Since bounds has changed, the configuration needs to be computed accordingly. - getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration); + computeConfigByResolveHint(resolvedConfig, newParentConfiguration); // The position of configuration bounds were calculated in screen space because that is // easier to resolve the relative position in parent container. However, if the activity is @@ -8946,17 +8953,18 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * to compute the stable bounds. * @param outStableBounds will store the stable bounds, which are the bounds with insets * applied, if orientation is not respected when insets are applied. - * Otherwise outStableBounds will be empty. Stable bounds should be used - * to compute letterboxed bounds if orientation is not respected when - * insets are applied. + * Stable bounds should be used to compute letterboxed bounds if + * orientation is not respected when insets are applied. + * @param outNonDecorBounds will store the non decor bounds, which are the bounds with non + * decor insets applied, like display cutout and nav bar. */ - private boolean orientationRespectedWithInsets(Rect parentBounds, Rect outStableBounds) { + private boolean orientationRespectedWithInsets(Rect parentBounds, Rect outStableBounds, + Rect outNonDecorBounds) { outStableBounds.setEmpty(); if (mDisplayContent == null) { return true; } - if (mWmService.mFlags.mInsetsDecoupledConfiguration - && info.isChangeEnabled(INSETS_DECOUPLED_CONFIGURATION_ENFORCED)) { + if (!mResolveConfigHint.mUseLegacyInsetsForStableBounds) { // No insets should be considered any more. return true; } @@ -8973,8 +8981,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A ? getFixedRotationTransformDisplayInfo() : mDisplayContent.getDisplayInfo(); final Task task = getTask(); - task.calculateInsetFrames(mTmpBounds /* outNonDecorBounds */, - outStableBounds /* outStableBounds */, parentBounds /* bounds */, di); + task.calculateInsetFrames(outNonDecorBounds /* outNonDecorBounds */, + outStableBounds /* outStableBounds */, parentBounds /* bounds */, di, + mResolveConfigHint.mUseLegacyInsetsForStableBounds); final int orientationWithInsets = outStableBounds.height() >= outStableBounds.width() ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; // If orientation does not match the orientation with insets applied, then a @@ -8984,9 +8993,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // have the desired orientation. final boolean orientationRespectedWithInsets = orientation == orientationWithInsets || orientationWithInsets == requestedOrientation; - if (orientationRespectedWithInsets) { - outStableBounds.setEmpty(); - } return orientationRespectedWithInsets; } @@ -9012,9 +9018,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A private void resolveFixedOrientationConfiguration(@NonNull Configuration newParentConfig) { final Rect parentBounds = newParentConfig.windowConfiguration.getBounds(); final Rect stableBounds = new Rect(); + final Rect outNonDecorBounds = mTmpBounds; // If orientation is respected when insets are applied, then stableBounds will be empty. boolean orientationRespectedWithInsets = - orientationRespectedWithInsets(parentBounds, stableBounds); + orientationRespectedWithInsets(parentBounds, stableBounds, outNonDecorBounds); if (orientationRespectedWithInsets && handlesOrientationChangeFromDescendant( getOverrideOrientation())) { // No need to letterbox because of fixed orientation. Display will handle @@ -9031,7 +9038,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A final Rect resolvedBounds = getResolvedOverrideConfiguration().windowConfiguration.getBounds(); - final int parentOrientation = newParentConfig.orientation; + final int stableBoundsOrientation = stableBounds.width() > stableBounds.height() + ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT; + final int parentOrientation = mResolveConfigHint.mUseLegacyInsetsForStableBounds + ? stableBoundsOrientation : newParentConfig.orientation; // If the activity requires a different orientation (either by override or activityInfo), // make it fit the available bounds by scaling down its bounds. @@ -9054,10 +9064,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return; } + final Rect parentAppBounds = mResolveConfigHint.mUseLegacyInsetsForStableBounds + ? 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. final Rect parentBoundsWithInsets = orientationRespectedWithInsets - ? newParentConfig.windowConfiguration.getAppBounds() : stableBounds; + ? parentAppBounds : stableBounds; final Rect containingBounds = new Rect(); final Rect containingBoundsWithInsets = new Rect(); // Need to shrink the containing bounds into a square because the parent orientation @@ -9134,8 +9146,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // Calculate app bounds using fixed orientation bounds because they will be needed later // for comparison with size compat app bounds in {@link resolveSizeCompatModeConfiguration}. - getTaskFragment().computeConfigResourceOverrides(getResolvedOverrideConfiguration(), - newParentConfig, compatDisplayInsets); + mResolveConfigHint.mTmpCompatInsets = compatDisplayInsets; + computeConfigByResolveHint(getResolvedOverrideConfiguration(), newParentConfig); mLetterboxBoundsForFixedOrientationAndAspectRatio = new Rect(resolvedBounds); } @@ -9176,8 +9188,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A if (!resolvedBounds.isEmpty() && !resolvedBounds.equals(parentBounds)) { // Compute the configuration based on the resolved bounds. If aspect ratio doesn't // restrict, the bounds should be the requested override bounds. - getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration, - getFixedRotationTransformDisplayInfo()); + mResolveConfigHint.mTmpOverrideDisplayInfo = getFixedRotationTransformDisplayInfo(); + computeConfigByResolveHint(resolvedConfig, newParentConfiguration); } } @@ -9241,8 +9253,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // Use resolvedBounds to compute other override configurations such as appBounds. The bounds // are calculated in compat container space. The actual position on screen will be applied // later, so the calculation is simpler that doesn't need to involve offset from parent. - getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration, - compatDisplayInsets); + mResolveConfigHint.mTmpCompatInsets = compatDisplayInsets; + computeConfigByResolveHint(resolvedConfig, newParentConfiguration); // Use current screen layout as source because the size of app is independent to parent. resolvedConfig.screenLayout = computeScreenLayout( getConfiguration().screenLayout, resolvedConfig.screenWidthDp, @@ -10759,7 +10771,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A /** Constructs the environment to simulate the bounds behavior of the given container. */ CompatDisplayInsets(DisplayContent display, ActivityRecord container, - @Nullable Rect fixedOrientationBounds) { + @Nullable Rect fixedOrientationBounds, boolean useOverrideInsets) { mOriginalRotation = display.getRotation(); mIsFloating = container.getWindowConfiguration().tasksAreFloating(); mOriginalRequestedOrientation = container.getRequestedConfigurationOrientation(); @@ -10811,8 +10823,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A final int dh = rotated ? display.mBaseDisplayWidth : display.mBaseDisplayHeight; final DisplayPolicy.DecorInsets.Info decorInfo = policy.getDecorInsetsInfo(rotation, dw, dh); - mNonDecorInsets[rotation].set(decorInfo.mNonDecorInsets); - mStableInsets[rotation].set(decorInfo.mConfigInsets); + if (useOverrideInsets) { + mStableInsets[rotation].set(decorInfo.mOverrideConfigInsets); + mNonDecorInsets[rotation].set(decorInfo.mOverrideNonDecorInsets); + } else { + mStableInsets[rotation].set(decorInfo.mConfigInsets); + mNonDecorInsets[rotation].set(decorInfo.mNonDecorInsets); + } if (unfilledContainerBounds == null) { continue; diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index 5e0d4f9a33f9..4544572d2702 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -1939,6 +1939,11 @@ public class DisplayPolicy { */ final Rect mOverrideConfigInsets = new Rect(); + /** + * Override value of mNonDecorInsets for app compatibility purpose. + */ + final Rect mOverrideNonDecorInsets = new Rect(); + /** The display frame available after excluding {@link #mNonDecorInsets}. */ final Rect mNonDecorFrame = new Rect(); @@ -1954,6 +1959,11 @@ public class DisplayPolicy { */ final Rect mOverrideConfigFrame = new Rect(); + /** + * Override value of mNonDecorFrame for app compatibility purpose. + */ + final Rect mOverrideNonDecorFrame = new Rect(); + private boolean mNeedUpdate = true; InsetsState update(DisplayContent dc, int rotation, int w, int h) { @@ -1973,17 +1983,26 @@ public class DisplayPolicy { ? configInsets : insetsState.calculateInsets(displayFrame, dc.mWmService.mOverrideConfigTypes, true /* ignoreVisibility */); + final Insets overrideDecorInsets = dc.mWmService.mDecorTypes + == dc.mWmService.mOverrideDecorTypes + ? decor + : insetsState.calculateInsets(displayFrame, + dc.mWmService.mOverrideDecorTypes, true /* ignoreVisibility */); mNonDecorInsets.set(decor.left, decor.top, decor.right, decor.bottom); mConfigInsets.set(configInsets.left, configInsets.top, configInsets.right, configInsets.bottom); mOverrideConfigInsets.set(overrideConfigInsets.left, overrideConfigInsets.top, overrideConfigInsets.right, overrideConfigInsets.bottom); + mOverrideNonDecorInsets.set(overrideDecorInsets.left, overrideDecorInsets.top, + overrideDecorInsets.right, overrideDecorInsets.bottom); mNonDecorFrame.set(displayFrame); mNonDecorFrame.inset(mNonDecorInsets); mConfigFrame.set(displayFrame); mConfigFrame.inset(mConfigInsets); mOverrideConfigFrame.set(displayFrame); mOverrideConfigFrame.inset(mOverrideConfigInsets); + mOverrideNonDecorFrame.set(displayFrame); + mOverrideNonDecorFrame.inset(mOverrideNonDecorInsets); mNeedUpdate = false; return insetsState; } @@ -1992,9 +2011,11 @@ public class DisplayPolicy { mNonDecorInsets.set(other.mNonDecorInsets); mConfigInsets.set(other.mConfigInsets); mOverrideConfigInsets.set(other.mOverrideConfigInsets); + mOverrideNonDecorInsets.set(other.mOverrideNonDecorInsets); mNonDecorFrame.set(other.mNonDecorFrame); mConfigFrame.set(other.mConfigFrame); mOverrideConfigFrame.set(other.mOverrideConfigFrame); + mOverrideNonDecorFrame.set(other.mOverrideNonDecorFrame); mNeedUpdate = false; } diff --git a/services/core/java/com/android/server/wm/TaskFragment.java b/services/core/java/com/android/server/wm/TaskFragment.java index 218fb7f6b817..804201088c59 100644 --- a/services/core/java/com/android/server/wm/TaskFragment.java +++ b/services/core/java/com/android/server/wm/TaskFragment.java @@ -2188,38 +2188,20 @@ class TaskFragment extends WindowContainer<WindowContainer> { return getTask() != null ? getTask().mTaskId : INVALID_TASK_ID; } - void computeConfigResourceOverrides(@NonNull Configuration inOutConfig, - @NonNull Configuration parentConfig) { - computeConfigResourceOverrides(inOutConfig, parentConfig, null /* overrideDisplayInfo */, - null /* compatInsets */); + static class ConfigOverrideHint { + @Nullable DisplayInfo mTmpOverrideDisplayInfo; + @Nullable ActivityRecord.CompatDisplayInsets mTmpCompatInsets; + boolean mUseLegacyInsetsForStableBounds; } void computeConfigResourceOverrides(@NonNull Configuration inOutConfig, - @NonNull Configuration parentConfig, @Nullable DisplayInfo overrideDisplayInfo) { - if (overrideDisplayInfo != null) { - // Make sure the screen related configs can be computed by the provided display info. - inOutConfig.screenLayout = Configuration.SCREENLAYOUT_UNDEFINED; - invalidateAppBoundsConfig(inOutConfig); - } - computeConfigResourceOverrides(inOutConfig, parentConfig, overrideDisplayInfo, - null /* compatInsets */); - } - - void computeConfigResourceOverrides(@NonNull Configuration inOutConfig, - @NonNull Configuration parentConfig, - @Nullable ActivityRecord.CompatDisplayInsets compatInsets) { - if (compatInsets != null) { - // Make sure the app bounds can be computed by the compat insets. - invalidateAppBoundsConfig(inOutConfig); - } - computeConfigResourceOverrides(inOutConfig, parentConfig, null /* overrideDisplayInfo */, - compatInsets); + @NonNull Configuration parentConfig) { + computeConfigResourceOverrides(inOutConfig, parentConfig, null /* configOverrideHint */); } /** * Forces the app bounds related configuration can be computed by - * {@link #computeConfigResourceOverrides(Configuration, Configuration, DisplayInfo, - * ActivityRecord.CompatDisplayInsets)}. + * {@link #computeConfigResourceOverrides(Configuration, Configuration, ConfigOverrideHint)}. */ private static void invalidateAppBoundsConfig(@NonNull Configuration inOutConfig) { final Rect appBounds = inOutConfig.windowConfiguration.getAppBounds(); @@ -2239,8 +2221,24 @@ class TaskFragment extends WindowContainer<WindowContainer> { * just be inherited from the parent configuration. **/ void computeConfigResourceOverrides(@NonNull Configuration inOutConfig, - @NonNull Configuration parentConfig, @Nullable DisplayInfo overrideDisplayInfo, - @Nullable ActivityRecord.CompatDisplayInsets compatInsets) { + @NonNull Configuration parentConfig, @Nullable ConfigOverrideHint overrideHint) { + DisplayInfo overrideDisplayInfo = null; + ActivityRecord.CompatDisplayInsets compatInsets = null; + boolean useLegacyInsetsForStableBounds = false; + if (overrideHint != null) { + overrideDisplayInfo = overrideHint.mTmpOverrideDisplayInfo; + compatInsets = overrideHint.mTmpCompatInsets; + useLegacyInsetsForStableBounds = overrideHint.mUseLegacyInsetsForStableBounds; + if (overrideDisplayInfo != null) { + // Make sure the screen related configs can be computed by the provided + // display info. + inOutConfig.screenLayout = Configuration.SCREENLAYOUT_UNDEFINED; + } + if (overrideDisplayInfo != null || compatInsets != null) { + // Make sure the app bounds can be computed by the compat insets. + invalidateAppBoundsConfig(inOutConfig); + } + } int windowingMode = inOutConfig.windowConfiguration.getWindowingMode(); if (windowingMode == WINDOWING_MODE_UNDEFINED) { windowingMode = parentConfig.windowConfiguration.getWindowingMode(); @@ -2309,7 +2307,8 @@ class TaskFragment extends WindowContainer<WindowContainer> { // area, i.e. the screen area without the system bars. // The non decor inset are areas that could never be removed in Honeycomb. See // {@link WindowManagerPolicy#getNonDecorInsetsLw}. - calculateInsetFrames(mTmpNonDecorBounds, mTmpStableBounds, mTmpFullBounds, di); + calculateInsetFrames(mTmpNonDecorBounds, mTmpStableBounds, mTmpFullBounds, di, + useLegacyInsetsForStableBounds); } else { // Apply the given non-decor and stable insets to calculate the corresponding bounds // for screen size of configuration. @@ -2407,9 +2406,11 @@ class TaskFragment extends WindowContainer<WindowContainer> { * @param outNonDecorBounds where to place bounds with non-decor insets applied. * @param outStableBounds where to place bounds with stable insets applied. * @param bounds the bounds to inset. + * @param useLegacyInsetsForStableBounds {@code true} if we need to use the legacy insets frame + * for apps targeting U or before when calculating stable bounds. */ void calculateInsetFrames(Rect outNonDecorBounds, Rect outStableBounds, Rect bounds, - DisplayInfo displayInfo) { + DisplayInfo displayInfo, boolean useLegacyInsetsForStableBounds) { outNonDecorBounds.set(bounds); outStableBounds.set(bounds); if (mDisplayContent == null) { @@ -2420,8 +2421,13 @@ class TaskFragment extends WindowContainer<WindowContainer> { final DisplayPolicy policy = mDisplayContent.getDisplayPolicy(); final DisplayPolicy.DecorInsets.Info info = policy.getDecorInsetsInfo( displayInfo.rotation, displayInfo.logicalWidth, displayInfo.logicalHeight); - intersectWithInsetsIfFits(outNonDecorBounds, mTmpBounds, info.mNonDecorInsets); - intersectWithInsetsIfFits(outStableBounds, mTmpBounds, info.mConfigInsets); + if (!useLegacyInsetsForStableBounds) { + intersectWithInsetsIfFits(outStableBounds, mTmpBounds, info.mConfigInsets); + intersectWithInsetsIfFits(outNonDecorBounds, mTmpBounds, info.mNonDecorInsets); + } else { + intersectWithInsetsIfFits(outStableBounds, mTmpBounds, info.mOverrideConfigInsets); + intersectWithInsetsIfFits(outNonDecorBounds, mTmpBounds, info.mOverrideNonDecorInsets); + } } /** diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 143605ac7320..1496ae02427f 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -570,6 +570,8 @@ public class WindowManagerService extends IWindowManager.Stub final int mOverrideConfigTypes; + final int mOverrideDecorTypes; + final boolean mLimitedAlphaCompositing; final int mMaxUiWidth; @@ -1255,10 +1257,13 @@ public class WindowManagerService extends IWindowManager.Stub if (isScreenSizeDecoupledFromStatusBarAndCutout && !mFlags.mInsetsDecoupledConfiguration) { // If the global new behavior is not there, but the partial decouple flag is on. mOverrideConfigTypes = 0; + mOverrideDecorTypes = 0; } else { mOverrideConfigTypes = WindowInsets.Type.displayCutout() | WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars(); + mOverrideDecorTypes = WindowInsets.Type.displayCutout() + | WindowInsets.Type.navigationBars(); } mLetterboxConfiguration = new LetterboxConfiguration( diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index 2e80bc721c7f..aa780edffc60 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -130,7 +130,6 @@ import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; @@ -4179,13 +4178,8 @@ public class SizeCompatTests extends WindowTestsBase { } @Test - @Ignore // TODO(b/330888878): fix test in main - public void testPortraitCloseToSquareDisplayWithTaskbar_notLetterboxed() { - if (Flags.insetsDecoupledConfiguration()) { - // TODO (b/151861875): Re-enable it. This is disabled temporarily because the config - // bounds no longer contains display cutout. - return; - } + @DisableCompatChanges({ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED}) + public void testPortraitCloseToSquareDisplayWithTaskbar_letterboxed() { // Set up portrait close to square display setUpDisplaySizeWithApp(2200, 2280); final DisplayContent display = mActivity.mDisplayContent; @@ -4198,16 +4192,21 @@ public class SizeCompatTests extends WindowTestsBase { .setInsetsSize(Insets.of(0, 0, 0, 150)) }; display.getDisplayPolicy().addWindowLw(navbar, navbar.mAttrs); - assertTrue(navbar.providesDisplayDecorInsets() - && display.getDisplayPolicy().updateDecorInsetsInfo()); + assertTrue(display.getDisplayPolicy().updateDecorInsetsInfo()); display.sendNewConfiguration(); - prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT); + final ActivityRecord activity = new ActivityBuilder(mAtm) + .setTask(mTask) + .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT) + .setComponent(ComponentName.createRelative(mContext, + SizeCompatTests.class.getName())) + .setUid(android.os.Process.myUid()) + .build(); - // Activity is fullscreen even though orientation is not respected with insets, because - // the display still matches or is less than the activity aspect ratio - assertEquals(display.getBounds(), mActivity.getBounds()); - assertFalse(mActivity.isLetterboxedForFixedOrientationAndAspectRatio()); + final Rect bounds = activity.getBounds(); + // Activity should be letterboxed and should have portrait app bounds + assertTrue(activity.isLetterboxedForFixedOrientationAndAspectRatio()); + assertTrue(bounds.height() > bounds.width()); } @Test @@ -4229,6 +4228,7 @@ public class SizeCompatTests extends WindowTestsBase { // can be aligned inside parentAppBounds assertEquals(mActivity.getBounds(), new Rect(0, 0, 1000, 2200)); } + @Test public void testApplyAspectRatio_activityCannotAlignWithParentAppVertical() { if (Flags.insetsDecoupledConfiguration()) { diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java index 1ca808f4153a..225e85e03b26 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java @@ -833,8 +833,11 @@ public class TaskTests extends WindowTestsBase { final ActivityRecord activity = new ActivityBuilder(mAtm).setTask(task).build(); final ActivityRecord.CompatDisplayInsets compatInsets = new ActivityRecord.CompatDisplayInsets( - display, activity, /* fixedOrientationBounds= */ null); - task.computeConfigResourceOverrides(inOutConfig, parentConfig, compatInsets); + display, activity, /* letterboxedContainerBounds */ null, + /* useOverrideInsets */ false); + final TaskFragment.ConfigOverrideHint overrideHint = new TaskFragment.ConfigOverrideHint(); + overrideHint.mTmpCompatInsets = compatInsets; + task.computeConfigResourceOverrides(inOutConfig, parentConfig, overrideHint); assertEquals(largerLandscapeBounds, inOutConfig.windowConfiguration.getAppBounds()); final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE; |