diff options
| -rw-r--r-- | services/core/java/com/android/server/wm/ActivityRecord.java | 48 | ||||
| -rw-r--r-- | services/core/java/com/android/server/wm/AppCompatAspectRatioPolicy.java | 46 |
2 files changed, 52 insertions, 42 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 0226650ec560..42a47d4a037e 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -8440,8 +8440,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A mTmpConfig.updateFrom(resolvedConfig); newParentConfiguration = mTmpConfig; } - - mAppCompatController.getAspectRatioPolicy().reset(); + final AppCompatAspectRatioPolicy aspectRatioPolicy = + mAppCompatController.getAspectRatioPolicy(); + aspectRatioPolicy.reset(); mIsEligibleForFixedOrientationLetterbox = false; mResolveConfigHint.resolveTmpOverrides(mDisplayContent, newParentConfiguration, isFixedRotationTransforming()); @@ -8472,12 +8473,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // If activity in fullscreen mode is letterboxed because of fixed orientation then bounds // are already calculated in resolveFixedOrientationConfiguration. // Don't apply aspect ratio if app is overridden to fullscreen by device user/manufacturer. - if (!mAppCompatController.getAspectRatioPolicy() - .isLetterboxedForFixedOrientationAndAspectRatio() - && !mAppCompatController.getAspectRatioOverrides() - .hasFullscreenOverride()) { - resolveAspectRatioRestriction(newParentConfiguration); - } + aspectRatioPolicy.resolveAspectRatioRestrictionIfNeeded(newParentConfiguration); final AppCompatDisplayInsets appCompatDisplayInsets = getAppCompatDisplayInsets(); final AppCompatSizeCompatModePolicy scmPolicy = mAppCompatController.getSizeCompatModePolicy(); @@ -8509,8 +8505,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // Fixed orientation letterboxing is possible on both large screen devices // with ignoreOrientationRequest enabled and on phones in split screen even with // ignoreOrientationRequest disabled. - && (mAppCompatController.getAspectRatioPolicy() - .isLetterboxedForFixedOrientationAndAspectRatio() + && (aspectRatioPolicy.isLetterboxedForFixedOrientationAndAspectRatio() // Limiting check for aspect ratio letterboxing to devices with enabled // ignoreOrientationRequest. This avoids affecting phones where apps may // not expect the change of smallestScreenWidthDp after rotation which is @@ -8518,7 +8513,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // accurate on phones shouldn't make the big difference and is expected // to be already well-tested by apps. || (isIgnoreOrientationRequest - && mAppCompatController.getAspectRatioPolicy().isAspectRatioApplied()))) { + && aspectRatioPolicy.isAspectRatioApplied()))) { // TODO(b/264034555): Use mDisplayContent to calculate smallestScreenWidthDp from all // rotations and only re-calculate if parent bounds have non-orientation size change. resolvedConfig.smallestScreenWidthDp = @@ -9007,37 +9002,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A new Rect(resolvedBounds)); } - /** - * Resolves aspect ratio restrictions for an activity. If the bounds are restricted by - * aspect ratio, the position will be adjusted later in {@link #updateResolvedBoundsPosition - * within parent's app bounds to balance the visual appearance. The policy of aspect ratio has - * higher priority than the requested override bounds. - */ - private void resolveAspectRatioRestriction(Configuration newParentConfiguration) { - final Configuration resolvedConfig = getResolvedOverrideConfiguration(); - final Rect parentAppBounds = mResolveConfigHint.mParentAppBoundsOverride; - 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 - // restricted size (resolved bounds may be the requested override bounds). - mTmpBounds.setEmpty(); - final AppCompatAspectRatioPolicy aspectRatioPolicy = mAppCompatController - .getAspectRatioPolicy(); - aspectRatioPolicy.applyAspectRatioForLetterbox(mTmpBounds, parentAppBounds, parentBounds); - // If the out bounds is not empty, it means the activity cannot fill parent's app bounds, - // then they should be aligned later in #updateResolvedBoundsPosition() - if (!mTmpBounds.isEmpty()) { - resolvedBounds.set(mTmpBounds); - } - 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. - mResolveConfigHint.mTmpOverrideDisplayInfo = getFixedRotationTransformDisplayInfo(); - computeConfigByResolveHint(resolvedConfig, newParentConfiguration); - aspectRatioPolicy.setLetterboxBoundsForAspectRatio(new Rect(resolvedBounds)); - } - } - @Override public Rect getBounds() { // TODO(b/268458693): Refactor configuration inheritance in case of translucent activities diff --git a/services/core/java/com/android/server/wm/AppCompatAspectRatioPolicy.java b/services/core/java/com/android/server/wm/AppCompatAspectRatioPolicy.java index 4ecd0bec9880..ab1778a1a32e 100644 --- a/services/core/java/com/android/server/wm/AppCompatAspectRatioPolicy.java +++ b/services/core/java/com/android/server/wm/AppCompatAspectRatioPolicy.java @@ -56,6 +56,8 @@ class AppCompatAspectRatioPolicy { @NonNull private final AppCompatAspectRatioState mAppCompatAspectRatioState; + private final Rect mTmpBounds = new Rect(); + AppCompatAspectRatioPolicy(@NonNull ActivityRecord activityRecord, @NonNull TransparentPolicy transparentPolicy, @NonNull AppCompatOverrides appCompatOverrides) { @@ -222,6 +224,45 @@ class AppCompatAspectRatioPolicy { return getMaxAspectRatio() != 0 || getMinAspectRatio() != 0; } + /** + * Resolves aspect ratio restrictions for an activity. If the bounds are restricted by + * aspect ratio, the position will be adjusted later in {@link #updateResolvedBoundsPosition} + * within parent's app bounds to balance the visual appearance. The policy of aspect ratio has + * higher priority than the requested override bounds. + */ + void resolveAspectRatioRestrictionIfNeeded(@NonNull Configuration newParentConfiguration) { + // If activity in fullscreen mode is letterboxed because of fixed orientation then bounds + // are already calculated in resolveFixedOrientationConfiguration. + // Don't apply aspect ratio if app is overridden to fullscreen by device user/manufacturer. + if (isLetterboxedForFixedOrientationAndAspectRatio() + || getOverrides().hasFullscreenOverride()) { + return; + } + final Configuration resolvedConfig = mActivityRecord.getResolvedOverrideConfiguration(); + final Rect parentAppBounds = + mActivityRecord.mResolveConfigHint.mParentAppBoundsOverride; + 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 restricted size (resolved bounds may be the requested override bounds). + mTmpBounds.setEmpty(); + applyAspectRatioForLetterbox(mTmpBounds, parentAppBounds, parentBounds); + // If the out bounds is not empty, it means the activity cannot fill parent's app + // bounds, then they should be aligned later in #updateResolvedBoundsPosition(). + if (!mTmpBounds.isEmpty()) { + resolvedBounds.set(mTmpBounds); + } + 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. + // TODO(b/384473893): Improve ActivityRecord usage here. + mActivityRecord.mResolveConfigHint.mTmpOverrideDisplayInfo = + mActivityRecord.getFixedRotationTransformDisplayInfo(); + mActivityRecord.computeConfigByResolveHint(resolvedConfig, newParentConfiguration); + setLetterboxBoundsForAspectRatio(new Rect(resolvedBounds)); + } + } + private boolean isParentFullscreenPortrait() { final WindowContainer<?> parent = mActivityRecord.getParent(); return parent != null @@ -364,6 +405,11 @@ class AppCompatAspectRatioPolicy { && !dc.getIgnoreOrientationRequest(); } + @NonNull + private AppCompatAspectRatioOverrides getOverrides() { + return mActivityRecord.mAppCompatController.getAspectRatioOverrides(); + } + private static class AppCompatAspectRatioState { // Whether the aspect ratio restrictions applied to the activity bounds // in applyAspectRatio(). |