Enforce VirtualTouchscreen dimensions are positive
Adds an IllegalArgumentException to the implementation of createVirtualTouchscreen if the dimension has one or two non positive components. Without this check the native layer silently fails (only a warning is printed in the logs). The creation of the VirtualTouchscreen looks successful because the DeviceCretionException does not get passed past the Binder call. When the first VirtualTouchEvent is sent to the VirtualTouchscreen the sendTouchEvent() method throws an exception because it can't find the underlying input device descriptor. Bug: 259554911 Test: atest FrameworksServicesTests:VirtualDeviceManagerServiceTest Change-Id: I085b8822d0f364b49060404480795626554fc155
This commit is contained in:
@@ -474,6 +474,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,
|
||||
|
||||
@@ -418,6 +418,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