diff --git a/services/companion/java/com/android/server/companion/virtual/InputController.java b/services/companion/java/com/android/server/companion/virtual/InputController.java index d5cc58f3cd0cb..df5e37c947cc8 100644 --- a/services/companion/java/com/android/server/companion/virtual/InputController.java +++ b/services/companion/java/com/android/server/companion/virtual/InputController.java @@ -46,6 +46,7 @@ import com.android.server.input.InputManagerInternal; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.nio.charset.StandardCharsets; import java.util.Iterator; import java.util.Map; import java.util.Objects; @@ -79,6 +80,14 @@ class InputController { @interface PhysType { } + /** + * The maximum length of a device name (in bytes in UTF-8 encoding). + * + * This limitation comes directly from uinput. + * See also UINPUT_MAX_NAME_SIZE in linux/uinput.h + */ + private static final int DEVICE_NAME_MAX_LENGTH = 80; + final Object mLock; /* Token -> file descriptor associations. */ @@ -312,6 +321,34 @@ class InputController { } } + /** + * Validates a device name by checking length and whether a device with the same name + * already exists. Throws exceptions if the validation fails. + * @param deviceName The name of the device to be validated + * @throws DeviceCreationException if {@code deviceName} is not valid. + */ + private void validateDeviceName(String deviceName) throws DeviceCreationException { + // Comparison is greater or equal because the device name must fit into a const char* + // including the \0-terminator. Therefore the actual number of bytes that can be used + // for device name is DEVICE_NAME_MAX_LENGTH - 1 + if (deviceName.getBytes(StandardCharsets.UTF_8).length >= DEVICE_NAME_MAX_LENGTH) { + throw new DeviceCreationException( + "Input device name exceeds maximum length of " + DEVICE_NAME_MAX_LENGTH + + "bytes: " + deviceName); + } + + synchronized (mLock) { + InputDeviceDescriptor[] values = mInputDeviceDescriptors.values().toArray( + new InputDeviceDescriptor[0]); + for (InputDeviceDescriptor value : values) { + if (value.mName.equals(deviceName)) { + throw new DeviceCreationException( + "Input device name already in use: " + deviceName); + } + } + } + } + private static String createPhys(@PhysType String type) { return String.format("virtual%s:%d", type, sNextPhysId.getAndIncrement()); } @@ -451,10 +488,10 @@ class InputController { @VisibleForTesting void addDeviceForTesting(IBinder deviceToken, int fd, int type, int displayId, String phys, - int inputDeviceId) { + String deviceName, int inputDeviceId) { synchronized (mLock) { mInputDeviceDescriptors.put(deviceToken, new InputDeviceDescriptor(fd, () -> { - }, type, displayId, phys, inputDeviceId)); + }, type, displayId, phys, deviceName, inputDeviceId)); } } @@ -565,6 +602,9 @@ class InputController { private final @Type int mType; private final int mDisplayId; private final String mPhys; + // The name given to this device by the client. Enforced to be unique within + // InputController. + private final String mName; // The input device id that was associated to the device by the InputReader on device // creation. private final int mInputDeviceId; @@ -572,12 +612,13 @@ class InputController { private final long mCreationOrderNumber; InputDeviceDescriptor(int fd, IBinder.DeathRecipient deathRecipient, @Type int type, - int displayId, String phys, int inputDeviceId) { + int displayId, String phys, String name, int inputDeviceId) { mFd = fd; mDeathRecipient = deathRecipient; mType = type; mDisplayId = displayId; mPhys = phys; + mName = name; mInputDeviceId = inputDeviceId; mCreationOrderNumber = sNextCreationOrderNumber.getAndIncrement(); } @@ -733,6 +774,7 @@ class InputController { "Virtual device creation should happen on an auxiliary thread (e.g. binder " + "thread) and not from the handler's thread."); } + validateDeviceName(deviceName); final int fd; final BinderDeathRecipient binderDeathRecipient; @@ -769,7 +811,7 @@ class InputController { synchronized (mLock) { mInputDeviceDescriptors.put(deviceToken, new InputDeviceDescriptor(fd, binderDeathRecipient, type, displayId, phys, - inputDeviceId)); + deviceName, inputDeviceId)); } } diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java b/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java index c1ee88c200960..760ed9be6234f 100644 --- a/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java +++ b/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java @@ -18,12 +18,12 @@ package com.android.server.companion.virtual; import static com.google.common.truth.Truth.assertWithMessage; +import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.startsWith; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.hardware.display.DisplayManagerInternal; @@ -133,14 +133,14 @@ public class InputControllerTest { @Test public void unregisterInputDevice_anotherMouseExists_setPointerDisplayIdOverride() { final IBinder deviceToken = new Binder(); - mInputController.createMouse("name", /*vendorId= */ 1, /*productId= */ 1, deviceToken, + mInputController.createMouse("mouse1", /*vendorId= */ 1, /*productId= */ 1, deviceToken, /* displayId= */ 1); - verify(mNativeWrapperMock).openUinputMouse(eq("name"), eq(1), eq(1), anyString()); + verify(mNativeWrapperMock).openUinputMouse(eq("mouse1"), eq(1), eq(1), anyString()); verify(mInputManagerInternalMock).setVirtualMousePointerDisplayId(eq(1)); final IBinder deviceToken2 = new Binder(); - mInputController.createMouse("name", /*vendorId= */ 1, /*productId= */ 1, deviceToken2, + mInputController.createMouse("mouse2", /*vendorId= */ 1, /*productId= */ 1, deviceToken2, /* displayId= */ 2); - verify(mNativeWrapperMock, times(2)).openUinputMouse(eq("name"), eq(1), eq(1), anyString()); + verify(mNativeWrapperMock).openUinputMouse(eq("mouse2"), eq(1), eq(1), anyString()); verify(mInputManagerInternalMock).setVirtualMousePointerDisplayId(eq(2)); mInputController.unregisterInputDevice(deviceToken); verify(mInputManagerInternalMock).setVirtualMousePointerDisplayId(eq(1)); @@ -193,4 +193,68 @@ public class InputControllerTest { mInputController.unregisterInputDevice(deviceToken); verify(mInputManagerInternalMock).removeKeyboardLayoutAssociation(anyString()); } + + @Test + public void createInputDevice_tooLongNameRaisesException() { + final IBinder deviceToken = new Binder("device"); + // The underlying uinput implementation only supports device names up to 80 bytes. This + // string is all ASCII characters, therefore if we have more than 80 ASCII characters we + // will have more than 80 bytes. + String deviceName = + "This.is.a.very.long.device.name.that.exceeds.the.maximum.length.of.80.bytes" + + ".by.a.couple.bytes"; + + assertThrows(RuntimeException.class, () -> { + mInputController.createDpad(deviceName, /*vendorId= */3, /*productId=*/3, deviceToken, + 1); + }); + } + + @Test + public void createInputDevice_tooLongDeviceNameRaisesException() { + final IBinder deviceToken = new Binder("device"); + // The underlying uinput implementation only supports device names up to 80 bytes (including + // a 0-byte terminator). + // This string is 79 characters and 80 bytes (including the 0-byte terminator) + String deviceName = + "This.is.a.very.long.device.name.that.exceeds.the.maximum.length01234567890123456"; + + assertThrows(RuntimeException.class, () -> { + mInputController.createDpad(deviceName, /*vendorId= */3, /*productId=*/3, deviceToken, + 1); + }); + } + + @Test + public void createInputDevice_stringWithLessThanMaxCharsButMoreThanMaxBytesRaisesException() { + final IBinder deviceToken = new Binder("device1"); + + // Has only 39 characters but is 109 bytes as utf-8 + String device_name = + "░▄▄▄▄░\n" + + "▀▀▄██►\n" + + "▀▀███►\n" + + "░▀███►░█►\n" + + "▒▄████▀▀"; + + assertThrows(RuntimeException.class, () -> { + mInputController.createDpad(device_name, /*vendorId= */5, /*productId=*/5, + deviceToken, 1); + }); + } + + @Test + public void createInputDevice_duplicateNamesAreNotAllowed() { + final IBinder deviceToken1 = new Binder("deviceToken1"); + final IBinder deviceToken2 = new Binder("deviceToken2"); + + final String sharedDeviceName = "DeviceName"; + + mInputController.createDpad(sharedDeviceName, /*vendorId= */4, /*productId=*/4, + deviceToken1, 1); + assertThrows("Device names need to be unique", RuntimeException.class, () -> { + mInputController.createDpad(sharedDeviceName, /*vendorId= */5, /*productId=*/5, + deviceToken2, 2); + }); + } } diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java index dad7977a8bb3d..aa98f417bac34 100644 --- a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java @@ -135,7 +135,9 @@ public class VirtualDeviceManagerServiceTest { private static final String VENDING_PACKAGE_NAME = "com.android.vending"; private static final String GOOGLE_DIALER_PACKAGE_NAME = "com.google.android.dialer"; private static final String GOOGLE_MAPS_PACKAGE_NAME = "com.google.android.apps.maps"; - private static final String DEVICE_NAME = "device name"; + private static final String DEVICE_NAME_1 = "device name 1"; + private static final String DEVICE_NAME_2 = "device name 2"; + private static final String DEVICE_NAME_3 = "device name 3"; private static final int DISPLAY_ID_1 = 2; private static final int DISPLAY_ID_2 = 3; private static final int DEVICE_OWNER_UID_1 = 50; @@ -160,14 +162,14 @@ public class VirtualDeviceManagerServiceTest { new VirtualDpadConfig.Builder() .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_1) .setAssociatedDisplayId(DISPLAY_ID_1) .build(); private static final VirtualKeyboardConfig KEYBOARD_CONFIG = new VirtualKeyboardConfig.Builder() .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_1) .setAssociatedDisplayId(DISPLAY_ID_1) .setLanguageTag(VirtualKeyboardConfig.DEFAULT_LANGUAGE_TAG) .setLayoutType(VirtualKeyboardConfig.DEFAULT_LAYOUT_TYPE) @@ -176,21 +178,21 @@ public class VirtualDeviceManagerServiceTest { new VirtualMouseConfig.Builder() .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_1) .setAssociatedDisplayId(DISPLAY_ID_1) .build(); private static final VirtualTouchscreenConfig TOUCHSCREEN_CONFIG = new VirtualTouchscreenConfig.Builder(WIDTH, HEIGHT) .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_1) .setAssociatedDisplayId(DISPLAY_ID_1) .build(); private static final VirtualNavigationTouchpadConfig NAVIGATION_TOUCHPAD_CONFIG = new VirtualNavigationTouchpadConfig.Builder(WIDTH, HEIGHT) .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_1) .setAssociatedDisplayId(DISPLAY_ID_1) .build(); private static final String TEST_SITE = "http://test"; @@ -549,7 +551,7 @@ public class VirtualDeviceManagerServiceTest { new VirtualKeyboardConfig.Builder() .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_1) .setAssociatedDisplayId(DISPLAY_ID_1) .setLanguageTag("zh-CN") .build(); @@ -557,7 +559,7 @@ public class VirtualDeviceManagerServiceTest { new VirtualKeyboardConfig.Builder() .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_2) .setAssociatedDisplayId(DISPLAY_ID_2) .setLanguageTag("fr-FR") .build(); @@ -784,7 +786,7 @@ public class VirtualDeviceManagerServiceTest { /* touchscrenWidth= */ 600, /* touchscreenHeight= */ 800) .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_1) .setAssociatedDisplayId(DISPLAY_ID_1) .build(); mDeviceImpl.createVirtualTouchscreen(positiveConfig, BINDER); @@ -822,7 +824,7 @@ public class VirtualDeviceManagerServiceTest { /* touchpadHeight= */ 50, /* touchpadWidth= */ 50) .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_1) .setAssociatedDisplayId(DISPLAY_ID_1) .build(); mDeviceImpl.createVirtualNavigationTouchpad(positiveConfig, BINDER); @@ -893,7 +895,7 @@ public class VirtualDeviceManagerServiceTest { () -> mDeviceImpl.createVirtualSensor( BINDER, new VirtualSensorConfig.Builder( - Sensor.TYPE_ACCELEROMETER, DEVICE_NAME).build())); + Sensor.TYPE_ACCELEROMETER, DEVICE_NAME_1).build())); } } @@ -920,7 +922,7 @@ public class VirtualDeviceManagerServiceTest { mDeviceImpl.createVirtualDpad(DPAD_CONFIG, BINDER); assertWithMessage("Virtual dpad should register fd when the display matches").that( mInputController.getInputDeviceDescriptors()).isNotEmpty(); - verify(mNativeWrapperMock).openUinputDpad(eq(DEVICE_NAME), eq(VENDOR_ID), eq(PRODUCT_ID), + verify(mNativeWrapperMock).openUinputDpad(eq(DEVICE_NAME_1), eq(VENDOR_ID), eq(PRODUCT_ID), anyString()); } @@ -930,7 +932,7 @@ public class VirtualDeviceManagerServiceTest { mDeviceImpl.createVirtualKeyboard(KEYBOARD_CONFIG, BINDER); assertWithMessage("Virtual keyboard should register fd when the display matches").that( mInputController.getInputDeviceDescriptors()).isNotEmpty(); - verify(mNativeWrapperMock).openUinputKeyboard(eq(DEVICE_NAME), eq(VENDOR_ID), + verify(mNativeWrapperMock).openUinputKeyboard(eq(DEVICE_NAME_1), eq(VENDOR_ID), eq(PRODUCT_ID), anyString()); } @@ -941,7 +943,7 @@ public class VirtualDeviceManagerServiceTest { assertWithMessage("Virtual keyboard should register fd when the display matches") .that(mInputController.getInputDeviceDescriptors()) .isNotEmpty(); - verify(mNativeWrapperMock).openUinputKeyboard(eq(DEVICE_NAME), eq(VENDOR_ID), + verify(mNativeWrapperMock).openUinputKeyboard(eq(DEVICE_NAME_1), eq(VENDOR_ID), eq(PRODUCT_ID), anyString()); assertThat(mDeviceImpl.getDeviceLocaleList()).isEqualTo( LocaleList.forLanguageTags(KEYBOARD_CONFIG.getLanguageTag())); @@ -953,7 +955,7 @@ public class VirtualDeviceManagerServiceTest { new VirtualKeyboardConfig.Builder() .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_1) .setAssociatedDisplayId(DISPLAY_ID_1) .build(); @@ -962,7 +964,7 @@ public class VirtualDeviceManagerServiceTest { assertWithMessage("Virtual keyboard should register fd when the display matches") .that(mInputController.getInputDeviceDescriptors()) .isNotEmpty(); - verify(mNativeWrapperMock).openUinputKeyboard(eq(DEVICE_NAME), eq(VENDOR_ID), + verify(mNativeWrapperMock).openUinputKeyboard(eq(DEVICE_NAME_1), eq(VENDOR_ID), eq(PRODUCT_ID), anyString()); assertThat(mDeviceImpl.getDeviceLocaleList()).isEqualTo( LocaleList.forLanguageTags(VirtualKeyboardConfig.DEFAULT_LANGUAGE_TAG)); @@ -982,7 +984,7 @@ public class VirtualDeviceManagerServiceTest { mDeviceImpl.createVirtualMouse(MOUSE_CONFIG, BINDER); assertWithMessage("Virtual mouse should register fd when the display matches").that( mInputController.getInputDeviceDescriptors()).isNotEmpty(); - verify(mNativeWrapperMock).openUinputMouse(eq(DEVICE_NAME), eq(VENDOR_ID), eq(PRODUCT_ID), + verify(mNativeWrapperMock).openUinputMouse(eq(DEVICE_NAME_1), eq(VENDOR_ID), eq(PRODUCT_ID), anyString()); } @@ -992,7 +994,7 @@ public class VirtualDeviceManagerServiceTest { mDeviceImpl.createVirtualTouchscreen(TOUCHSCREEN_CONFIG, BINDER); assertWithMessage("Virtual touchscreen should register fd when the display matches").that( mInputController.getInputDeviceDescriptors()).isNotEmpty(); - verify(mNativeWrapperMock).openUinputTouchscreen(eq(DEVICE_NAME), eq(VENDOR_ID), + verify(mNativeWrapperMock).openUinputTouchscreen(eq(DEVICE_NAME_1), eq(VENDOR_ID), eq(PRODUCT_ID), anyString(), eq(HEIGHT), eq(WIDTH)); } @@ -1003,15 +1005,16 @@ public class VirtualDeviceManagerServiceTest { assertWithMessage("Virtual navigation touchpad should register fd when the display matches") .that( mInputController.getInputDeviceDescriptors()).isNotEmpty(); - verify(mNativeWrapperMock).openUinputTouchscreen(eq(DEVICE_NAME), eq(VENDOR_ID), + verify(mNativeWrapperMock).openUinputTouchscreen(eq(DEVICE_NAME_1), eq(VENDOR_ID), eq(PRODUCT_ID), anyString(), eq(HEIGHT), eq(WIDTH)); } @Test public void createVirtualKeyboard_inputDeviceId_obtainFromInputController() { final int fd = 1; - mInputController.addDeviceForTesting(BINDER, fd, /* type= */ 1, /* displayId= */ 1, PHYS, - INPUT_DEVICE_ID); + mInputController.addDeviceForTesting(BINDER, fd, + InputController.InputDeviceDescriptor.TYPE_KEYBOARD, DISPLAY_ID_1, PHYS, + DEVICE_NAME_1, INPUT_DEVICE_ID); assertWithMessage( "InputController should return device id from InputDeviceDescriptor").that( mInputController.getInputDeviceId(BINDER)).isEqualTo(INPUT_DEVICE_ID); @@ -1052,7 +1055,7 @@ public class VirtualDeviceManagerServiceTest { @Test public void close_cleanSensorController() { mSensorController.addSensorForTesting( - BINDER, SENSOR_HANDLE, Sensor.TYPE_ACCELEROMETER, DEVICE_NAME); + BINDER, SENSOR_HANDLE, Sensor.TYPE_ACCELEROMETER, DEVICE_NAME_1); mDeviceImpl.close(); @@ -1085,8 +1088,9 @@ public class VirtualDeviceManagerServiceTest { final int fd = 1; final int keyCode = KeyEvent.KEYCODE_A; final int action = VirtualKeyEvent.ACTION_UP; - mInputController.addDeviceForTesting(BINDER, fd, /* type= */1, /* displayId= */ 1, PHYS, - INPUT_DEVICE_ID); + mInputController.addDeviceForTesting(BINDER, fd, + InputController.InputDeviceDescriptor.TYPE_KEYBOARD, DISPLAY_ID_1, PHYS, + DEVICE_NAME_1, INPUT_DEVICE_ID); mDeviceImpl.sendKeyEvent(BINDER, new VirtualKeyEvent.Builder() .setKeyCode(keyCode) @@ -1112,9 +1116,10 @@ public class VirtualDeviceManagerServiceTest { final int fd = 1; final int buttonCode = VirtualMouseButtonEvent.BUTTON_BACK; final int action = VirtualMouseButtonEvent.ACTION_BUTTON_PRESS; - mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS, - INPUT_DEVICE_ID); - doReturn(1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId(); + mInputController.addDeviceForTesting(BINDER, fd, + InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, + DEVICE_NAME_1, INPUT_DEVICE_ID); + doReturn(DISPLAY_ID_1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId(); mDeviceImpl.sendButtonEvent(BINDER, new VirtualMouseButtonEvent.Builder() .setButtonCode(buttonCode) .setAction(action).build()); @@ -1126,7 +1131,8 @@ public class VirtualDeviceManagerServiceTest { final int fd = 1; final int buttonCode = VirtualMouseButtonEvent.BUTTON_BACK; final int action = VirtualMouseButtonEvent.ACTION_BUTTON_PRESS; - mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS, + mInputController.addDeviceForTesting(BINDER, fd, + InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, DEVICE_NAME_1, INPUT_DEVICE_ID); assertThrows( IllegalStateException.class, @@ -1151,9 +1157,10 @@ public class VirtualDeviceManagerServiceTest { final int fd = 1; final float x = -0.2f; final float y = 0.7f; - mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS, + mInputController.addDeviceForTesting(BINDER, fd, + InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, DEVICE_NAME_1, INPUT_DEVICE_ID); - doReturn(1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId(); + doReturn(DISPLAY_ID_1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId(); mDeviceImpl.sendRelativeEvent(BINDER, new VirtualMouseRelativeEvent.Builder() .setRelativeX(x).setRelativeY(y).build()); verify(mNativeWrapperMock).writeRelativeEvent(fd, x, y); @@ -1164,7 +1171,8 @@ public class VirtualDeviceManagerServiceTest { final int fd = 1; final float x = -0.2f; final float y = 0.7f; - mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS, + mInputController.addDeviceForTesting(BINDER, fd, + InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, DEVICE_NAME_1, INPUT_DEVICE_ID); assertThrows( IllegalStateException.class, @@ -1190,9 +1198,10 @@ public class VirtualDeviceManagerServiceTest { final int fd = 1; final float x = 0.5f; final float y = 1f; - mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS, + mInputController.addDeviceForTesting(BINDER, fd, + InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, DEVICE_NAME_1, INPUT_DEVICE_ID); - doReturn(1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId(); + doReturn(DISPLAY_ID_1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId(); mDeviceImpl.sendScrollEvent(BINDER, new VirtualMouseScrollEvent.Builder() .setXAxisMovement(x) .setYAxisMovement(y).build()); @@ -1204,7 +1213,8 @@ public class VirtualDeviceManagerServiceTest { final int fd = 1; final float x = 0.5f; final float y = 1f; - mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS, + mInputController.addDeviceForTesting(BINDER, fd, + InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, DEVICE_NAME_1, INPUT_DEVICE_ID); assertThrows( IllegalStateException.class, @@ -1236,8 +1246,9 @@ public class VirtualDeviceManagerServiceTest { final float x = 100.5f; final float y = 200.5f; final int action = VirtualTouchEvent.ACTION_UP; - mInputController.addDeviceForTesting(BINDER, fd, /* type= */3, /* displayId= */ 1, PHYS, - INPUT_DEVICE_ID); + mInputController.addDeviceForTesting(BINDER, fd, + InputController.InputDeviceDescriptor.TYPE_TOUCHSCREEN, DISPLAY_ID_1, PHYS, + DEVICE_NAME_1, INPUT_DEVICE_ID); mDeviceImpl.sendTouchEvent(BINDER, new VirtualTouchEvent.Builder() .setX(x) .setY(y) @@ -1259,8 +1270,9 @@ public class VirtualDeviceManagerServiceTest { final int action = VirtualTouchEvent.ACTION_UP; final float pressure = 1.0f; final float majorAxisSize = 10.0f; - mInputController.addDeviceForTesting(BINDER, fd, /* type= */3, /* displayId= */ 1, PHYS, - INPUT_DEVICE_ID); + mInputController.addDeviceForTesting(BINDER, fd, + InputController.InputDeviceDescriptor.TYPE_TOUCHSCREEN, DISPLAY_ID_1, PHYS, + DEVICE_NAME_1, INPUT_DEVICE_ID); mDeviceImpl.sendTouchEvent(BINDER, new VirtualTouchEvent.Builder() .setX(x) .setY(y) @@ -1281,19 +1293,19 @@ public class VirtualDeviceManagerServiceTest { mDeviceImpl.mVirtualDisplayIds.add(3); VirtualMouseConfig config1 = new VirtualMouseConfig.Builder() .setAssociatedDisplayId(1) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_1) .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) .build(); VirtualMouseConfig config2 = new VirtualMouseConfig.Builder() .setAssociatedDisplayId(2) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_2) .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) .build(); VirtualMouseConfig config3 = new VirtualMouseConfig.Builder() .setAssociatedDisplayId(3) - .setInputDeviceName(DEVICE_NAME) + .setInputDeviceName(DEVICE_NAME_3) .setVendorId(VENDOR_ID) .setProductId(PRODUCT_ID) .build();