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

Commit dc2529d3 authored by Sandro Meier's avatar Sandro Meier Committed by Android (Google) Code Review
Browse files

Merge "Enforce VirtualTouchscreen dimensions are positive"

parents c1861f63 48cf98cb
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -480,6 +480,13 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
                                + "this virtual device");
            }
        }

        if (screenSize.x <= 0 || screenSize.y <= 0) {
            throw new IllegalArgumentException(
                    "Cannot create a virtual touchscreen, screen dimensions must be positive. Got: "
                            + screenSize);
        }

        final long token = Binder.clearCallingIdentity();
        try {
            mInputController.createTouchscreen(deviceName, vendorId, productId,
+29 −0
Original line number Diff line number Diff line
@@ -471,6 +471,35 @@ public class VirtualDeviceManagerServiceTest {
                        VENDOR_ID, PRODUCT_ID, BINDER, new Point(WIDTH, HEIGHT)));
    }

    @Test
    public void createVirtualTouchscreen_zeroDisplayDimension_failsIllegalArgumentException() {
        mDeviceImpl.mVirtualDisplayIds.add(DISPLAY_ID);
        Point size = new Point(0, 0);
        assertThrows(IllegalArgumentException.class,
                () -> mDeviceImpl.createVirtualTouchscreen(DISPLAY_ID, DEVICE_NAME, VENDOR_ID,
                        PRODUCT_ID, BINDER, size));
    }

    @Test
    public void createVirtualTouchscreen_negativeDisplayDimension_failsIllegalArgumentException() {
        mDeviceImpl.mVirtualDisplayIds.add(DISPLAY_ID);
        Point size = new Point(-100, -100);
        assertThrows(IllegalArgumentException.class,
                () -> mDeviceImpl.createVirtualTouchscreen(DISPLAY_ID, DEVICE_NAME, VENDOR_ID,
                        PRODUCT_ID, BINDER, size));
    }

    @Test
    public void createVirtualTouchscreen_positiveDisplayDimension_successful() {
        mDeviceImpl.mVirtualDisplayIds.add(DISPLAY_ID);
        Point size = new Point(600, 800);
        mDeviceImpl.createVirtualTouchscreen(DISPLAY_ID, DEVICE_NAME, VENDOR_ID, PRODUCT_ID, BINDER,
                size);
        assertWithMessage(
                "Virtual touchscreen should create input device descriptor on successful creation.")
                .that(mInputController.mInputDeviceDescriptors).isNotEmpty();
    }

    @Test
    public void onAudioSessionStarting_noDisplay_failsSecurityException() {
        assertThrows(SecurityException.class,