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

Commit b8f0bb9a authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

Respect the absence of FLAG_ROTATES_WITH_CONTENT.

When creating virtual displays without this flag, they should not
rotate when the content changes its requested orientation, but
instead should apply letterbox or pillarbox transformation.

Bug: 292473307
Test: atest DisplayRotationTests
Test: atest LogicalDisplayTest
Test: atest DisplayManagerServiceTest
Change-Id: Ie12d5e93626ebc298ab71e8634e4e50bb70d49da
(cherry picked from commit 19c59050)
Merged-In: Ie12d5e93626ebc298ab71e8634e4e50bb70d49da
parent 3490e6fb
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -374,6 +374,14 @@ public final class Display {
     */
    public static final int FLAG_REAR = 1 << 13;

    /**
     * Display flag: Indicates that the orientation of this display is not fixed and is coupled to
     * the orientation of its content.
     *
     * @hide
     */
    public static final int FLAG_ROTATES_WITH_CONTENT = 1 << 14;

    /**
     * Display flag: Indicates that the contents of the display should not be scaled
     * to fit the physical screen dimensions.  Used for development only to emulate
+3 −0
Original line number Diff line number Diff line
@@ -441,6 +441,9 @@ final class LogicalDisplay {
            if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_ALWAYS_UNLOCKED) != 0) {
                mBaseDisplayInfo.flags |= Display.FLAG_ALWAYS_UNLOCKED;
            }
            if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT) != 0) {
                mBaseDisplayInfo.flags |= Display.FLAG_ROTATES_WITH_CONTENT;
            }
            if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_TOUCH_FEEDBACK_DISABLED) != 0) {
                mBaseDisplayInfo.flags |= Display.FLAG_TOUCH_FEEDBACK_DISABLED;
            }
+7 −0
Original line number Diff line number Diff line
@@ -6492,6 +6492,13 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        return (mDisplayInfo.flags & Display.FLAG_ALWAYS_UNLOCKED) != 0;
    }

    /**
     * @return whether the physical display has a fixed orientation and cannot be rotated.
     */
    boolean isDisplayOrientationFixed() {
        return (mDisplayInfo.flags & Display.FLAG_ROTATES_WITH_CONTENT) == 0;
    }

    /**
     * @return whether AOD is showing on this display
     */
+2 −1
Original line number Diff line number Diff line
@@ -431,7 +431,8 @@ public class DisplayRotation {
        final boolean isTv = mContext.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_LEANBACK);
        mDefaultFixedToUserRotation =
                (isCar || isTv || mService.mIsPc || mDisplayContent.forceDesktopMode())
                (isCar || isTv || mService.mIsPc || mDisplayContent.forceDesktopMode()
                        || mDisplayContent.isDisplayOrientationFixed())
                // For debug purposes the next line turns this feature off with:
                // $ adb shell setprop config.override_forced_orient true
                // $ adb shell wm size reset
+35 −0
Original line number Diff line number Diff line
@@ -476,6 +476,41 @@ public class DisplayManagerServiceTest {
        assertTrue((ddi.flags & DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT) != 0);
    }

    @Test
    public void testCreateVirtualRotatesWithContent() throws RemoteException {
        DisplayManagerService displayManager =
                new DisplayManagerService(mContext, mBasicInjector);
        registerDefaultDisplays(displayManager);

        // This is effectively the DisplayManager service published to ServiceManager.
        DisplayManagerService.BinderService bs = displayManager.new BinderService();

        String uniqueId = "uniqueId --- Rotates with Content Test";
        int width = 600;
        int height = 800;
        int dpi = 320;
        int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT;

        when(mMockAppToken.asBinder()).thenReturn(mMockAppToken);
        final VirtualDisplayConfig.Builder builder = new VirtualDisplayConfig.Builder(
                VIRTUAL_DISPLAY_NAME, width, height, dpi);
        builder.setFlags(flags);
        builder.setUniqueId(uniqueId);
        int displayId = bs.createVirtualDisplay(builder.build(), /* callback= */ mMockAppToken,
                /* projection= */ null, PACKAGE_NAME);
        verify(mMockProjectionService, never()).setContentRecordingSession(any(),
                nullable(IMediaProjection.class));

        displayManager.performTraversalInternal(mock(SurfaceControl.Transaction.class));

        // flush the handler
        displayManager.getDisplayHandler().runWithScissors(() -> {}, /* now= */ 0);

        DisplayDeviceInfo ddi = displayManager.getDisplayDeviceInfoInternal(displayId);
        assertNotNull(ddi);
        assertTrue((ddi.flags & DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT) != 0);
    }

    @Test
    public void testCreateVirtualDisplayOwnFocus() throws RemoteException {
        DisplayManagerService displayManager =
Loading