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

Commit 879d24f4 authored by Alex Sakhartchouk's avatar Alex Sakhartchouk
Browse files

Allow VR Virtual display to rotate with content.

VR Virtual display was getting letterboxing for apps that
had a fixed orientation in the manifest.

Bug: 62670868
Test: Run orientation locked app, observe requested orientation in VR
testCreateVirtualDisplayRotatesWithContent to verify propagation.
Change-Id: I10eb4f6e54404aa7b66471ab5dc929a4baa49432
parent 820a5063
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -256,6 +256,15 @@ public final class DisplayManager {
     */
    public static final int VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH = 1 << 6;

    /**
     * Virtual display flag: Indicates that the orientation of this display device is coupled to
     * the rotation of its associated logical display.
     *
     * @see #createVirtualDisplay
     * @hide
     */
    public static final int VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT = 1 << 7;

    /** @hide */
    public DisplayManager(Context context) {
        mContext = context;
+12 −0
Original line number Diff line number Diff line
@@ -1221,6 +1221,18 @@ public final class DisplayManagerService extends SystemService {
        }
    }

    @VisibleForTesting
    DisplayDeviceInfo getDisplayDeviceInfoInternal(int displayId) {
        synchronized (mSyncRoot) {
            LogicalDisplay display = mLogicalDisplays.get(displayId);
            if (display != null) {
                DisplayDevice displayDevice = display.getPrimaryDisplayDeviceLocked();
                return displayDevice.getDisplayDeviceInfoLocked();
            }
            return null;
        }
    }

    private final class DisplayManagerHandler extends Handler {
        public DisplayManagerHandler(Looper looper) {
            super(looper, null, true /*async*/);
+5 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESE
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE;
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH;
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT;

import android.content.Context;
import android.hardware.display.IVirtualDisplayCallback;
@@ -359,6 +360,10 @@ public class VirtualDisplayAdapter extends DisplayAdapter {
                if ((mFlags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
                    mInfo.flags |= DisplayDeviceInfo.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD;
                }
                if ((mFlags & VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT) != 0) {
                    mInfo.flags |= DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT;
                }

                mInfo.type = Display.TYPE_VIRTUAL;
                mInfo.touch = ((mFlags & VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH) == 0) ?
                        DisplayDeviceInfo.TOUCH_NONE : DisplayDeviceInfo.TOUCH_VIRTUAL;
+1 −0
Original line number Diff line number Diff line
@@ -266,6 +266,7 @@ class Vr2dDisplay {
            }

            int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH;
            flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT;
            mVirtualDisplay = mDisplayManager.createVirtualDisplay(null /* projection */,
                    DISPLAY_NAME, mVirtualDisplayWidth, mVirtualDisplayHeight, mVirtualDisplayDpi,
                    null /* surface */, flags, null /* callback */, null /* handler */,
+27 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.view.SurfaceControl;
import android.view.WindowManagerInternal;

import com.android.server.LocalServices;
import com.android.server.display.DisplayDeviceInfo;
import com.android.server.display.DisplayManagerService.SyncRoot;
import com.android.server.display.VirtualDisplayAdapter.SurfaceControlDisplayFactory;

@@ -115,4 +116,30 @@ public class DisplayManagerServiceTest extends AndroidTestCase {
        assertEquals(uniqueIdPrefix + uniqueId, dv.uniqueId);
        assertEquals(displayId, dv.displayId);
    }

    public void testCreateVirtualDisplayRotatesWithContent() throws Exception {
        // This is effectively the DisplayManager service published to ServiceManager.
        DisplayManagerService.BinderService bs = mDisplayManager.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);
        int displayId = bs.createVirtualDisplay(mMockAppToken /* callback */,
                null /* projection */, "com.android.frameworks.servicestests",
                "Test Virtual Display", width, height, dpi, null /* surface */, flags /* flags */,
                uniqueId);

        mDisplayManager.performTraversalInTransactionFromWindowManagerInternal();

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

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