diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 6df46ed2532b7..e795877764128 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -6643,8 +6643,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A final Configuration resolvedConfig = getResolvedOverrideConfiguration(); final Rect resolvedBounds = resolvedConfig.windowConfiguration.getBounds(); final int requestedOrientation = getRequestedConfigurationOrientation(); - final boolean orientationRequested = requestedOrientation != ORIENTATION_UNDEFINED - && !mDisplayContent.ignoreRotationForApps(); + final boolean orientationRequested = requestedOrientation != ORIENTATION_UNDEFINED; final int orientation = orientationRequested ? requestedOrientation : newParentConfiguration.orientation; diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 77e573624b8ab..5efe10736a755 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -28,7 +28,6 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; -import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.content.res.Configuration.ORIENTATION_UNDEFINED; @@ -366,13 +365,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp @VisibleForTesting final float mCloseToSquareMaxAspectRatio; - /** - * If this is true, we would not rotate the display for apps. The rotation would be either the - * sensor rotation or the user rotation, controlled by - * {@link WindowManagerPolicy.UserRotationMode}. - */ - private boolean mIgnoreRotationForApps; - /** * Keep track of wallpaper visibility to notify changes. */ @@ -1757,26 +1749,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, calculateDisplayCutoutForRotation(mDisplayInfo.rotation)); - - // Not much of use to rotate the display for apps since it's close to square. - mIgnoreRotationForApps = isNonDecorDisplayCloseToSquare(Surface.ROTATION_0, width, height); - } - - /** @return {@code true} if the orientation requested from application will be ignored. */ - boolean ignoreRotationForApps() { - return mIgnoreRotationForApps; - } - - private boolean isNonDecorDisplayCloseToSquare(int rotation, int width, int height) { - final DisplayCutout displayCutout = - calculateDisplayCutoutForRotation(rotation).getDisplayCutout(); - final int uiMode = mWmService.mPolicy.getUiMode(); - final int w = mDisplayPolicy.getNonDecorDisplayWidth( - width, height, rotation, uiMode, displayCutout); - final int h = mDisplayPolicy.getNonDecorDisplayHeight( - width, height, rotation, uiMode, displayCutout); - final float aspectRatio = Math.max(w, h) / (float) Math.min(w, h); - return aspectRatio <= mCloseToSquareMaxAspectRatio; } /** @@ -2342,10 +2314,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp int getOrientation() { mLastOrientationSource = null; - if (mIgnoreRotationForApps) { - return SCREEN_ORIENTATION_USER; - } - if (mWmService.mDisplayFrozen) { if (mWmService.mPolicy.isKeyguardLocked()) { // Use the last orientation the while the display is frozen with the keyguard diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java index 7f904265de156..2791234031daf 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -24,7 +24,6 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; -import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER; import static android.os.Build.VERSION_CODES.P; import static android.os.Build.VERSION_CODES.Q; import static android.view.Display.DEFAULT_DISPLAY; @@ -762,13 +761,14 @@ public class DisplayContentTests extends WindowTestsBase { window.mAttrs.screenOrientation, dc.getOrientation()); // ---------------------------- - // Test close-to-square display + // Test close-to-square display - should be handled in the same way // ---------------------------- dc.mBaseDisplayHeight = dc.mBaseDisplayWidth; dc.configureDisplayPolicy(); - assertEquals("Screen orientation must be SCREEN_ORIENTATION_USER.", - SCREEN_ORIENTATION_USER, dc.getOrientation()); + assertEquals( + "Screen orientation must be defined by the window even on close-to-square display.", + window.mAttrs.screenOrientation, dc.getOrientation()); } @Test 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 29081d3892250..edcf0d4f55011 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -138,8 +138,6 @@ public class SizeCompatTests extends WindowTestsBase { public void testFixedAspectRatioBoundsWithDecorInSquareDisplay() { final int notchHeight = 100; setUpApp(new TestDisplayContent.Builder(mAtm, 600, 800).setNotch(notchHeight).build()); - // Rotation is ignored so because the display size is close to square (700/600<1.333). - assertTrue(mActivity.mDisplayContent.ignoreRotationForApps()); final Rect displayBounds = mActivity.mDisplayContent.getWindowConfiguration().getBounds(); final float aspectRatio = 1.2f; @@ -163,23 +161,14 @@ public class SizeCompatTests extends WindowTestsBase { mActivity.setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE); assertFitted(); - // After the orientation of activity is changed, even display is not rotated, the aspect - // ratio should be the same (bounds=[0, 0 - 600, 600], appBounds=[0, 100 - 600, 600]). + // After the orientation of activity is changed, the display is rotated, the aspect + // ratio should be the same (bounds=[100, 0 - 800, 583], appBounds=[100, 0 - 800, 583]). assertEquals(appBounds.width(), appBounds.height() * aspectRatio, 0.5f /* delta */); - // The notch is still on top. - assertEquals(mActivity.getBounds().height(), appBounds.height() + notchHeight); + // The notch is no longer on top. + assertEquals(appBounds, mActivity.getBounds()); mActivity.setRequestedOrientation(SCREEN_ORIENTATION_PORTRAIT); assertFitted(); - - // Close-to-square display can rotate without being restricted by the requested orientation. - // The notch becomes on the left side. The activity is horizontal centered in 100 ~ 800. - // So the bounds and appBounds will be [200, 0 - 700, 600] (500x600) that is still fitted. - // Left = 100 + (800 - 100 - 500) / 2 = 200. - rotateDisplay(mActivity.mDisplayContent, ROTATION_90); - assertFitted(); - assertEquals(appBounds.left, - notchHeight + (displayBounds.width() - notchHeight - appBounds.width()) / 2); } @Test