Merge "Enforce VirtualTouchscreen dimensions are positive"
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user