Merge "Revert "Bind an input device via descriptor"" into main
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 1383096..443a6c0e 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -1769,16 +1769,14 @@
}
public final class InputManager {
- method @FlaggedApi("com.android.input.flags.device_associations") @RequiresPermission("android.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY") public void addUniqueIdAssociationByDescriptor(@NonNull String, @NonNull String);
- method @FlaggedApi("com.android.input.flags.device_associations") @RequiresPermission("android.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY") public void addUniqueIdAssociationByPort(@NonNull String, @NonNull String);
+ method public void addUniqueIdAssociation(@NonNull String, @NonNull String);
method @RequiresPermission(android.Manifest.permission.REMAP_MODIFIER_KEYS) public void clearAllModifierKeyRemappings();
method @NonNull public java.util.List<java.lang.String> getKeyboardLayoutDescriptors();
method @NonNull public String getKeyboardLayoutTypeForLayoutDescriptor(@NonNull String);
method @NonNull @RequiresPermission(android.Manifest.permission.REMAP_MODIFIER_KEYS) public java.util.Map<java.lang.Integer,java.lang.Integer> getModifierKeyRemapping();
method public int getMousePointerSpeed();
method @RequiresPermission(android.Manifest.permission.REMAP_MODIFIER_KEYS) public void remapModifierKey(int, int);
- method @FlaggedApi("com.android.input.flags.device_associations") @RequiresPermission("android.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY") public void removeUniqueIdAssociationByDescriptor(@NonNull String);
- method @FlaggedApi("com.android.input.flags.device_associations") @RequiresPermission("android.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY") public void removeUniqueIdAssociationByPort(@NonNull String);
+ method public void removeUniqueIdAssociation(@NonNull String);
field public static final long BLOCK_UNTRUSTED_TOUCHES = 158002302L; // 0x96aec7eL
}
diff --git a/core/api/test-lint-baseline.txt b/core/api/test-lint-baseline.txt
index e6265ae..685ea63 100644
--- a/core/api/test-lint-baseline.txt
+++ b/core/api/test-lint-baseline.txt
@@ -977,16 +977,8 @@
Method 'setHdmiCecVersion' documentation mentions permissions already declared by @RequiresPermission
RequiresPermission: android.hardware.input.InputManager#addUniqueIdAssociation(String, String):
Method 'addUniqueIdAssociation' documentation mentions permissions without declaring @RequiresPermission
-RequiresPermission: android.hardware.input.InputManager#addUniqueIdAssociationByDescriptor(String, String):
- Method 'addUniqueIdAssociationByDescriptor' documentation mentions permissions already declared by @RequiresPermission
-RequiresPermission: android.hardware.input.InputManager#addUniqueIdAssociationByPort(String, String):
- Method 'addUniqueIdAssociationByPort' documentation mentions permissions already declared by @RequiresPermission
RequiresPermission: android.hardware.input.InputManager#removeUniqueIdAssociation(String):
Method 'removeUniqueIdAssociation' documentation mentions permissions without declaring @RequiresPermission
-RequiresPermission: android.hardware.input.InputManager#removeUniqueIdAssociationByDescriptor(String):
- Method 'removeUniqueIdAssociationByDescriptor' documentation mentions permissions already declared by @RequiresPermission
-RequiresPermission: android.hardware.input.InputManager#removeUniqueIdAssociationByPort(String):
- Method 'removeUniqueIdAssociationByPort' documentation mentions permissions already declared by @RequiresPermission
RequiresPermission: android.hardware.location.GeofenceHardware#addGeofence(int, int, android.hardware.location.GeofenceHardwareRequest, android.hardware.location.GeofenceHardwareCallback):
Method 'addGeofence' documentation mentions permissions without declaring @RequiresPermission
RequiresPermission: android.hardware.location.GeofenceHardware#getMonitoringTypes():
diff --git a/core/java/android/hardware/input/IInputManager.aidl b/core/java/android/hardware/input/IInputManager.aidl
index 2d474d6..1c37aa2 100644
--- a/core/java/android/hardware/input/IInputManager.aidl
+++ b/core/java/android/hardware/input/IInputManager.aidl
@@ -165,17 +165,10 @@
// static association for the cleared input port will be restored.
void removePortAssociation(in String inputPort);
- // Add a runtime association between the input device and display, using device's descriptor.
- void addUniqueIdAssociationByDescriptor(in String inputDeviceDescriptor,
- in String displayUniqueId);
- // Remove the runtime association between the input device and display, using device's
- // descriptor.
- void removeUniqueIdAssociationByDescriptor(in String inputDeviceDescriptor);
-
- // Add a runtime association between the input device and display, using device's port.
- void addUniqueIdAssociationByPort(in String inputPort, in String displayUniqueId);
- // Remove the runtime association between the input device and display, using device's port.
- void removeUniqueIdAssociationByPort(in String inputPort);
+ // Add a runtime association between the input device and display.
+ void addUniqueIdAssociation(in String inputPort, in String displayUniqueId);
+ // Remove the runtime association between the input device and display.
+ void removeUniqueIdAssociation(in String inputPort);
InputSensorInfo[] getSensorList(int deviceId);
diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java
index 4dda2c7..f949158 100644
--- a/core/java/android/hardware/input/InputManager.java
+++ b/core/java/android/hardware/input/InputManager.java
@@ -17,7 +17,6 @@
package android.hardware.input;
import static com.android.input.flags.Flags.FLAG_INPUT_DEVICE_VIEW_BEHAVIOR_API;
-import static com.android.input.flags.Flags.FLAG_DEVICE_ASSOCIATIONS;
import static com.android.hardware.input.Flags.keyboardLayoutPreviewFlag;
import android.Manifest;
@@ -1055,14 +1054,13 @@
/**
* Add a runtime association between the input port and the display port. This overrides any
* static associations.
- * @param inputPort the port of the input device
- * @param displayPort the physical port of the associated display
+ * @param inputPort The port of the input device.
+ * @param displayPort The physical port of the associated display.
* <p>
* Requires {@link android.Manifest.permission#ASSOCIATE_INPUT_DEVICE_TO_DISPLAY}.
* </p>
* @hide
*/
- @RequiresPermission(android.Manifest.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY)
public void addPortAssociation(@NonNull String inputPort, int displayPort) {
try {
mIm.addPortAssociation(inputPort, displayPort);
@@ -1074,13 +1072,12 @@
/**
* Remove the runtime association between the input port and the display port. Any existing
* static association for the cleared input port will be restored.
- * @param inputPort the port of the input device to be cleared
+ * @param inputPort The port of the input device to be cleared.
* <p>
* Requires {@link android.Manifest.permission#ASSOCIATE_INPUT_DEVICE_TO_DISPLAY}.
* </p>
* @hide
*/
- @RequiresPermission(android.Manifest.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY)
public void removePortAssociation(@NonNull String inputPort) {
try {
mIm.removePortAssociation(inputPort);
@@ -1092,74 +1089,30 @@
/**
* Add a runtime association between the input port and display, by unique id. Input ports are
* expected to be unique.
- * @param inputPort the port of the input device
- * @param displayUniqueId the unique id of the associated display
+ * @param inputPort The port of the input device.
+ * @param displayUniqueId The unique id of the associated display.
* <p>
* Requires {@link android.Manifest.permission#ASSOCIATE_INPUT_DEVICE_TO_DISPLAY}.
* </p>
* @hide
*/
- @FlaggedApi(FLAG_DEVICE_ASSOCIATIONS)
- @RequiresPermission(android.Manifest.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY)
@TestApi
- public void addUniqueIdAssociationByPort(@NonNull String inputPort,
+ public void addUniqueIdAssociation(@NonNull String inputPort,
@NonNull String displayUniqueId) {
- mGlobal.addUniqueIdAssociationByPort(inputPort, displayUniqueId);
+ mGlobal.addUniqueIdAssociation(inputPort, displayUniqueId);
}
/**
* Removes a runtime association between the input device and display.
- * @param inputPort the port of the input device
+ * @param inputPort The port of the input device.
* <p>
* Requires {@link android.Manifest.permission#ASSOCIATE_INPUT_DEVICE_TO_DISPLAY}.
* </p>
* @hide
*/
- @FlaggedApi(FLAG_DEVICE_ASSOCIATIONS)
- @RequiresPermission(android.Manifest.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY)
@TestApi
- public void removeUniqueIdAssociationByPort(@NonNull String inputPort) {
- mGlobal.removeUniqueIdAssociationByPort(inputPort);
- }
-
- /**
- * Add a runtime association between the input device name and display, by descriptor. Input
- * device descriptors are expected to be unique per physical device, though one physical
- * device can have multiple virtual input devices that possess the same descriptor.
- * E.g. a keyboard with built in trackpad will be 2 different input devices with the same
- * descriptor.
- * @param inputDeviceDescriptor the descriptor of the input device
- * @param displayUniqueId the unique id of the associated display
- * <p>
- * Requires {@link android.Manifest.permissions.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY}.
- * </p>
- * @hide
- */
- @FlaggedApi(FLAG_DEVICE_ASSOCIATIONS)
- @RequiresPermission(android.Manifest.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY)
- @TestApi
- public void addUniqueIdAssociationByDescriptor(@NonNull String inputDeviceDescriptor,
- @NonNull String displayUniqueId) {
- mGlobal.addUniqueIdAssociationByDescriptor(inputDeviceDescriptor, displayUniqueId);
- }
-
- /**
- * Removes a runtime association between the input device and display.
- }
-
- /**
- * Removes a runtime association between the input device and display.
- * @param inputDeviceDescriptor the descriptor of the input device
- * <p>
- * Requires {@link android.Manifest.permissions.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY}.
- * </p>
- * @hide
- */
- @FlaggedApi(FLAG_DEVICE_ASSOCIATIONS)
- @RequiresPermission(android.Manifest.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY)
- @TestApi
- public void removeUniqueIdAssociationByDescriptor(@NonNull String inputDeviceDescriptor) {
- mGlobal.removeUniqueIdAssociationByDescriptor(inputDeviceDescriptor);
+ public void removeUniqueIdAssociation(@NonNull String inputPort) {
+ mGlobal.removeUniqueIdAssociation(inputPort);
}
/**
diff --git a/core/java/android/hardware/input/InputManagerGlobal.java b/core/java/android/hardware/input/InputManagerGlobal.java
index 1d253d9..7b29666 100644
--- a/core/java/android/hardware/input/InputManagerGlobal.java
+++ b/core/java/android/hardware/input/InputManagerGlobal.java
@@ -1467,46 +1467,22 @@
}
/**
- * @see InputManager#addUniqueIdAssociationByPort(String, String)
+ * @see InputManager#addUniqueIdAssociation(String, String)
*/
- public void addUniqueIdAssociationByPort(@NonNull String inputPort,
- @NonNull String displayUniqueId) {
+ public void addUniqueIdAssociation(@NonNull String inputPort, @NonNull String displayUniqueId) {
try {
- mIm.addUniqueIdAssociationByPort(inputPort, displayUniqueId);
+ mIm.addUniqueIdAssociation(inputPort, displayUniqueId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
- * @see InputManager#removeUniqueIdAssociationByPort(String)
+ * @see InputManager#removeUniqueIdAssociation(String)
*/
- public void removeUniqueIdAssociationByPort(@NonNull String inputPort) {
+ public void removeUniqueIdAssociation(@NonNull String inputPort) {
try {
- mIm.removeUniqueIdAssociationByPort(inputPort);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- }
- }
-
- /**
- * @see InputManager#addUniqueIdAssociationByDescriptor(String, String)
- */
- public void addUniqueIdAssociationByDescriptor(@NonNull String inputDeviceDescriptor,
- @NonNull String displayUniqueId) {
- try {
- mIm.addUniqueIdAssociationByDescriptor(inputDeviceDescriptor, displayUniqueId);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- }
- }
-
- /**
- * @see InputManager#removeUniqueIdAssociationByDescriptor(String)
- */
- public void removeUniqueIdAssociationByDescriptor(@NonNull String inputDeviceDescriptor) {
- try {
- mIm.removeUniqueIdAssociationByDescriptor(inputDeviceDescriptor);
+ mIm.removeUniqueIdAssociation(inputPort);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
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 3c25835..9b72288 100644
--- a/services/companion/java/com/android/server/companion/virtual/InputController.java
+++ b/services/companion/java/com/android/server/companion/virtual/InputController.java
@@ -226,7 +226,7 @@
token.unlinkToDeath(inputDeviceDescriptor.getDeathRecipient(), /* flags= */ 0);
mNativeWrapper.closeUinput(inputDeviceDescriptor.getNativePointer());
String phys = inputDeviceDescriptor.getPhys();
- InputManagerGlobal.getInstance().removeUniqueIdAssociationByDescriptor(phys);
+ InputManagerGlobal.getInstance().removeUniqueIdAssociation(phys);
// Type associations are added in the case of navigation touchpads. Those should be removed
// once the input device gets closed.
if (inputDeviceDescriptor.getType() == InputDeviceDescriptor.TYPE_NAVIGATION_TOUCHPAD) {
@@ -319,9 +319,9 @@
return formatSimple("virtual%s:%d", type, sNextPhysId.getAndIncrement());
}
- private void setUniqueIdAssociationByPort(int displayId, String phys) {
+ private void setUniqueIdAssociation(int displayId, String phys) {
final String displayUniqueId = mDisplayManagerInternal.getDisplayInfo(displayId).uniqueId;
- InputManagerGlobal.getInstance().addUniqueIdAssociationByPort(phys, displayUniqueId);
+ InputManagerGlobal.getInstance().addUniqueIdAssociation(phys, displayUniqueId);
}
boolean sendDpadKeyEvent(@NonNull IBinder token, @NonNull VirtualKeyEvent event) {
@@ -809,7 +809,7 @@
final int inputDeviceId;
- setUniqueIdAssociationByPort(displayId, phys);
+ setUniqueIdAssociation(displayId, phys);
try (WaitForDevice waiter = new WaitForDevice(deviceName, vendorId, productId, displayId)) {
ptr = deviceOpener.get();
// See INVALID_PTR in libs/input/VirtualInputDevice.cpp.
@@ -835,7 +835,7 @@
throw e;
}
} catch (DeviceCreationException e) {
- InputManagerGlobal.getInstance().removeUniqueIdAssociationByPort(phys);
+ InputManagerGlobal.getInstance().removeUniqueIdAssociation(phys);
throw e;
}
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index 73df594..f32c11d 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -250,19 +250,8 @@
private final Object mAssociationsLock = new Object();
@GuardedBy("mAssociationsLock")
private final Map<String, Integer> mRuntimeAssociations = new ArrayMap<>();
-
- // The associations of input devices to displays by port. Maps from {InputDevice#mName} (String)
- // to {DisplayInfo#uniqueId} (String) so that events from the Input Device go to a
- // specific display.
@GuardedBy("mAssociationsLock")
- private final Map<String, String> mUniqueIdAssociationsByPort = new ArrayMap<>();
-
- // The associations of input devices to displays by descriptor. Maps from
- // {InputDevice#mDescriptor} to {DisplayInfo#uniqueId} (String) so that events from the
- // input device go to a specific display.
- @GuardedBy("mAssociationsLock")
- private final Map<String, String> mUniqueIdAssociationsByDescriptor = new ArrayMap<>();
-
+ private final Map<String, String> mUniqueIdAssociations = new ArrayMap<>();
// The map from input port (String) to the keyboard layout identifiers (comma separated string
// containing language tag and layout type) associated with the corresponding keyboard device.
// Currently only accessed by InputReader.
@@ -1752,8 +1741,8 @@
/**
* Add a runtime association between the input port and the display port. This overrides any
* static associations.
- * @param inputPort the port of the input device
- * @param displayPort the physical port of the associated display
+ * @param inputPort The port of the input device.
+ * @param displayPort The physical port of the associated display.
*/
@Override // Binder call
public void addPortAssociation(@NonNull String inputPort, int displayPort) {
@@ -1774,7 +1763,7 @@
/**
* Remove the runtime association between the input port and the display port. Any existing
* static association for the cleared input port will be restored.
- * @param inputPort the port of the input device to be cleared
+ * @param inputPort The port of the input device to be cleared.
*/
@Override // Binder call
public void removePortAssociation(@NonNull String inputPort) {
@@ -1793,11 +1782,10 @@
}
@Override // Binder call
- public void addUniqueIdAssociationByPort(@NonNull String inputPort,
- @NonNull String displayUniqueId) {
+ public void addUniqueIdAssociation(@NonNull String inputPort, @NonNull String displayUniqueId) {
if (!checkCallingPermission(
android.Manifest.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY,
- "addUniqueIdAssociationByPort()")) {
+ "addUniqueIdAssociation()")) {
throw new SecurityException(
"Requires ASSOCIATE_INPUT_DEVICE_TO_DISPLAY permission");
}
@@ -1805,65 +1793,22 @@
Objects.requireNonNull(inputPort);
Objects.requireNonNull(displayUniqueId);
synchronized (mAssociationsLock) {
- mUniqueIdAssociationsByPort.put(inputPort, displayUniqueId);
+ mUniqueIdAssociations.put(inputPort, displayUniqueId);
}
mNative.changeUniqueIdAssociation();
}
@Override // Binder call
- public void removeUniqueIdAssociationByPort(@NonNull String inputPort) {
+ public void removeUniqueIdAssociation(@NonNull String inputPort) {
if (!checkCallingPermission(
android.Manifest.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY,
- "removeUniqueIdAssociationByPort()")) {
+ "removeUniqueIdAssociation()")) {
throw new SecurityException("Requires ASSOCIATE_INPUT_DEVICE_TO_DISPLAY permission");
}
Objects.requireNonNull(inputPort);
synchronized (mAssociationsLock) {
- mUniqueIdAssociationsByPort.remove(inputPort);
- }
- mNative.changeUniqueIdAssociation();
- }
-
- /**
- * Adds a runtime association between the input device descriptor and the display unique id.
- * @param inputDeviceDescriptor the descriptor of the input device
- * @param displayUniqueId the unique ID of the display
- */
- @Override // Binder call
- public void addUniqueIdAssociationByDescriptor(@NonNull String inputDeviceDescriptor,
- @NonNull String displayUniqueId) {
- if (!checkCallingPermission(
- android.Manifest.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY,
- "addUniqueIdAssociationByDescriptor()")) {
- throw new SecurityException(
- "Requires ASSOCIATE_INPUT_DEVICE_TO_DISPLAY permission");
- }
-
- Objects.requireNonNull(inputDeviceDescriptor);
- Objects.requireNonNull(displayUniqueId);
- synchronized (mAssociationsLock) {
- mUniqueIdAssociationsByDescriptor.put(inputDeviceDescriptor, displayUniqueId);
- }
- mNative.changeUniqueIdAssociation();
- }
-
- /**
- * Removes the runtime association between the input device and the display.
- * @param inputDeviceDescriptor the descriptor of the input device
- */
- @Override // Binder call
- public void removeUniqueIdAssociationByDescriptor(@NonNull String inputDeviceDescriptor) {
- if (!checkCallingPermission(
- android.Manifest.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY,
- "removeUniqueIdAssociationByDescriptor()")) {
- throw new SecurityException(
- "Requires ASSOCIATE_INPUT_DEVICE_TO_DISPLAY permission");
- }
-
- Objects.requireNonNull(inputDeviceDescriptor);
- synchronized (mAssociationsLock) {
- mUniqueIdAssociationsByDescriptor.remove(inputDeviceDescriptor);
+ mUniqueIdAssociations.remove(inputPort);
}
mNative.changeUniqueIdAssociation();
}
@@ -2238,20 +2183,13 @@
pw.println(" display: " + v);
});
}
- if (!mUniqueIdAssociationsByPort.isEmpty()) {
+ if (!mUniqueIdAssociations.isEmpty()) {
pw.println("Unique Id Associations:");
- mUniqueIdAssociationsByPort.forEach((k, v) -> {
+ mUniqueIdAssociations.forEach((k, v) -> {
pw.print(" port: " + k);
pw.println(" uniqueId: " + v);
});
}
- if (!mUniqueIdAssociationsByDescriptor.isEmpty()) {
- pw.println("Unique Id Associations:");
- mUniqueIdAssociationsByDescriptor.forEach((k, v) -> {
- pw.print(" descriptor: " + k);
- pw.println(" uniqueId: " + v);
- });
- }
if (!mDeviceTypeAssociations.isEmpty()) {
pw.println("Type Associations:");
mDeviceTypeAssociations.forEach((k, v) -> {
@@ -2684,21 +2622,10 @@
// Native callback
@SuppressWarnings("unused")
- private String[] getInputUniqueIdAssociationsByPort() {
+ private String[] getInputUniqueIdAssociations() {
final Map<String, String> associations;
synchronized (mAssociationsLock) {
- associations = new HashMap<>(mUniqueIdAssociationsByPort);
- }
-
- return flatten(associations);
- }
-
- // Native callback
- @SuppressWarnings("unused")
- private String[] getInputUniqueIdAssociationsByDescriptor() {
- final Map<String, String> associations;
- synchronized (mAssociationsLock) {
- associations = new HashMap<>(mUniqueIdAssociationsByDescriptor);
+ associations = new HashMap<>(mUniqueIdAssociations);
}
return flatten(associations);
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
index 2f880ba..88c47f3 100644
--- a/services/core/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -128,8 +128,7 @@
jmethodID getVirtualKeyQuietTimeMillis;
jmethodID getExcludedDeviceNames;
jmethodID getInputPortAssociations;
- jmethodID getInputUniqueIdAssociationsByPort;
- jmethodID getInputUniqueIdAssociationsByDescriptor;
+ jmethodID getInputUniqueIdAssociations;
jmethodID getDeviceTypeAssociations;
jmethodID getKeyboardLayoutAssociations;
jmethodID getHoverTapTimeout;
@@ -635,13 +634,10 @@
env->DeleteLocalRef(portAssociations);
}
- outConfig->uniqueIdAssociationsByPort = readMapFromInterleavedJavaArray<
- std::string>(gServiceClassInfo.getInputUniqueIdAssociationsByPort,
- "getInputUniqueIdAssociationsByPort");
-
- outConfig->uniqueIdAssociationsByDescriptor = readMapFromInterleavedJavaArray<
- std::string>(gServiceClassInfo.getInputUniqueIdAssociationsByDescriptor,
- "getInputUniqueIdAssociationsByDescriptor");
+ outConfig->uniqueIdAssociations =
+ readMapFromInterleavedJavaArray<std::string>(gServiceClassInfo
+ .getInputUniqueIdAssociations,
+ "getInputUniqueIdAssociations");
outConfig->deviceTypeAssociations =
readMapFromInterleavedJavaArray<std::string>(gServiceClassInfo
@@ -3094,11 +3090,8 @@
GET_METHOD_ID(gServiceClassInfo.getInputPortAssociations, clazz,
"getInputPortAssociations", "()[Ljava/lang/String;");
- GET_METHOD_ID(gServiceClassInfo.getInputUniqueIdAssociationsByPort, clazz,
- "getInputUniqueIdAssociationsByPort", "()[Ljava/lang/String;");
-
- GET_METHOD_ID(gServiceClassInfo.getInputUniqueIdAssociationsByDescriptor, clazz,
- "getInputUniqueIdAssociationsByDescriptor", "()[Ljava/lang/String;");
+ GET_METHOD_ID(gServiceClassInfo.getInputUniqueIdAssociations, clazz,
+ "getInputUniqueIdAssociations", "()[Ljava/lang/String;");
GET_METHOD_ID(gServiceClassInfo.getDeviceTypeAssociations, clazz, "getDeviceTypeAssociations",
"()[Ljava/lang/String;");
diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/InputManagerMockHelper.java b/services/tests/servicestests/src/com/android/server/companion/virtual/InputManagerMockHelper.java
index 00c8ed1..74e854e4 100644
--- a/services/tests/servicestests/src/com/android/server/companion/virtual/InputManagerMockHelper.java
+++ b/services/tests/servicestests/src/com/android/server/companion/virtual/InputManagerMockHelper.java
@@ -53,7 +53,7 @@
private IInputDevicesChangedListener mDevicesChangedListener;
private final Map<String /* uniqueId */, Integer /* displayId */> mDisplayIdMapping =
new HashMap<>();
- private final Map<String /* phys */, String /* uniqueId */> mUniqueIdAssociationByPort =
+ private final Map<String /* phys */, String /* uniqueId */> mUniqueIdAssociation =
new HashMap<>();
InputManagerMockHelper(TestableLooper testableLooper,
@@ -79,11 +79,10 @@
when(mIInputManagerMock.getInputDeviceIds()).thenReturn(new int[0]);
doAnswer(inv -> mDevices.get(inv.getArgument(0)))
.when(mIInputManagerMock).getInputDevice(anyInt());
- doAnswer(inv -> mUniqueIdAssociationByPort.put(inv.getArgument(0),
- inv.getArgument(1))).when(mIInputManagerMock).addUniqueIdAssociationByPort(
- anyString(), anyString());
- doAnswer(inv -> mUniqueIdAssociationByPort.remove(inv.getArgument(0))).when(
- mIInputManagerMock).removeUniqueIdAssociationByPort(anyString());
+ doAnswer(inv -> mUniqueIdAssociation.put(inv.getArgument(0), inv.getArgument(1))).when(
+ mIInputManagerMock).addUniqueIdAssociation(anyString(), anyString());
+ doAnswer(inv -> mUniqueIdAssociation.remove(inv.getArgument(0))).when(
+ mIInputManagerMock).removeUniqueIdAssociation(anyString());
// Set a new instance of InputManager for testing that uses the IInputManager mock as the
// interface to the server.
@@ -113,7 +112,7 @@
.setDescriptor(phys)
.setExternal(true)
.setAssociatedDisplayId(
- mDisplayIdMapping.getOrDefault(mUniqueIdAssociationByPort.get(phys),
+ mDisplayIdMapping.getOrDefault(mUniqueIdAssociation.get(phys),
Display.INVALID_DISPLAY))
.build();
diff --git a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt
index 8d2b927..f6f766a 100644
--- a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt
+++ b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt
@@ -19,26 +19,17 @@
import android.content.Context
import android.content.ContextWrapper
-import android.hardware.display.DisplayManager
import android.hardware.display.DisplayViewport
-import android.hardware.display.VirtualDisplay
import android.hardware.input.InputManager
import android.hardware.input.InputManagerGlobal
-import android.os.InputEventInjectionSync
-import android.os.SystemClock
import android.os.test.TestLooper
import android.platform.test.annotations.Presubmit
import android.platform.test.annotations.RequiresFlagsDisabled
import android.platform.test.flag.junit.DeviceFlagsValueProvider
import android.provider.Settings
-import android.view.View.OnKeyListener
-import android.view.Display
-import android.view.InputDevice
-import android.view.KeyEvent
-import android.view.PointerIcon
-import android.view.SurfaceHolder
-import android.view.SurfaceView
import android.test.mock.MockContentResolver
+import android.view.Display
+import android.view.PointerIcon
import androidx.test.platform.app.InstrumentationRegistry
import com.android.internal.util.test.FakeSettingsProvider
import com.google.common.truth.Truth.assertThat
@@ -57,7 +48,6 @@
import org.mockito.Mockito.`when`
import org.mockito.Mockito.clearInvocations
import org.mockito.Mockito.doAnswer
-import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.times
@@ -422,174 +412,6 @@
verify(wmCallbacks).notifyPointerDisplayIdChanged(overrideDisplayId, 0f, 0f)
thread.join(100 /*millis*/)
}
-
- private fun createVirtualDisplays(count: Int): List<VirtualDisplay> {
- val displayManager: DisplayManager = context.getSystemService(
- DisplayManager::class.java
- ) as DisplayManager
- val virtualDisplays = mutableListOf<VirtualDisplay>()
- for (i in 0 until count) {
- virtualDisplays.add(displayManager.createVirtualDisplay(
- /* displayName= */ "testVirtualDisplay$i",
- /* width= */ 100,
- /* height= */ 100,
- /* densityDpi= */ 100,
- /* surface= */ null,
- /* flags= */ 0
- ))
- }
- return virtualDisplays
- }
-
- // Helper function that creates a KeyEvent with Keycode A with the given action
- private fun createKeycodeAEvent(inputDevice: InputDevice, action: Int): KeyEvent {
- val eventTime = SystemClock.uptimeMillis()
- return KeyEvent(
- /* downTime= */ eventTime,
- /* eventTime= */ eventTime,
- /* action= */ action,
- /* code= */ KeyEvent.KEYCODE_A,
- /* repeat= */ 0,
- /* metaState= */ 0,
- /* deviceId= */ inputDevice.id,
- /* scanCode= */ 0,
- /* flags= */ KeyEvent.FLAG_FROM_SYSTEM,
- /* source= */ InputDevice.SOURCE_KEYBOARD
- )
- }
-
- private fun createInputDevice(): InputDevice {
- return InputDevice.Builder()
- .setId(123)
- .setName("abc")
- .setDescriptor("def")
- .setSources(InputDevice.SOURCE_KEYBOARD)
- .build()
- }
-
- @Test
- fun addUniqueIdAssociationByDescriptor_verifyAssociations() {
- // Overall goal is to have 2 displays and verify that events from the InputDevice are
- // sent only to the view that is on the associated display.
- // So, associate the InputDevice with display 1, then send and verify KeyEvents.
- // Then remove associations, then associate the InputDevice with display 2, then send
- // and verify commands.
-
- // Make 2 virtual displays with some mock SurfaceViews
- val mockSurfaceView1 = mock(SurfaceView::class.java)
- val mockSurfaceView2 = mock(SurfaceView::class.java)
- val mockSurfaceHolder1 = mock(SurfaceHolder::class.java)
- `when`(mockSurfaceView1.holder).thenReturn(mockSurfaceHolder1)
- val mockSurfaceHolder2 = mock(SurfaceHolder::class.java)
- `when`(mockSurfaceView2.holder).thenReturn(mockSurfaceHolder2)
-
- val virtualDisplays = createVirtualDisplays(2)
-
- // Simulate an InputDevice
- val inputDevice = createInputDevice()
-
- // Associate input device with display
- service.addUniqueIdAssociationByDescriptor(
- inputDevice.descriptor,
- virtualDisplays[0].display.displayId.toString()
- )
-
- // Simulate 2 different KeyEvents
- val downEvent = createKeycodeAEvent(inputDevice, KeyEvent.ACTION_DOWN)
- val upEvent = createKeycodeAEvent(inputDevice, KeyEvent.ACTION_UP)
-
- // Create a mock OnKeyListener object
- val mockOnKeyListener = mock(OnKeyListener::class.java)
-
- // Verify that the event went to Display 1 not Display 2
- service.injectInputEvent(downEvent, InputEventInjectionSync.NONE)
-
- // Call the onKey method on the mock OnKeyListener object
- mockOnKeyListener.onKey(mockSurfaceView1, /* keyCode= */ KeyEvent.KEYCODE_A, downEvent)
- mockOnKeyListener.onKey(mockSurfaceView2, /* keyCode= */ KeyEvent.KEYCODE_A, upEvent)
-
- // Verify that the onKey method was called with the expected arguments
- verify(mockOnKeyListener).onKey(mockSurfaceView1, KeyEvent.KEYCODE_A, downEvent)
- verify(mockOnKeyListener, never()).onKey(mockSurfaceView2, KeyEvent.KEYCODE_A, downEvent)
-
- // Remove association
- service.removeUniqueIdAssociationByDescriptor(inputDevice.descriptor)
-
- // Associate with Display 2
- service.addUniqueIdAssociationByDescriptor(
- inputDevice.descriptor,
- virtualDisplays[1].display.displayId.toString()
- )
-
- // Simulate a KeyEvent
- service.injectInputEvent(upEvent, InputEventInjectionSync.NONE)
-
- // Verify that the event went to Display 2 not Display 1
- verify(mockOnKeyListener).onKey(mockSurfaceView2, KeyEvent.KEYCODE_A, upEvent)
- verify(mockOnKeyListener, never()).onKey(mockSurfaceView1, KeyEvent.KEYCODE_A, upEvent)
- }
-
- @Test
- fun addUniqueIdAssociationByPort_verifyAssociations() {
- // Overall goal is to have 2 displays and verify that events from the InputDevice are
- // sent only to the view that is on the associated display.
- // So, associate the InputDevice with display 1, then send and verify KeyEvents.
- // Then remove associations, then associate the InputDevice with display 2, then send
- // and verify commands.
-
- // Make 2 virtual displays with some mock SurfaceViews
- val mockSurfaceView1 = mock(SurfaceView::class.java)
- val mockSurfaceView2 = mock(SurfaceView::class.java)
- val mockSurfaceHolder1 = mock(SurfaceHolder::class.java)
- `when`(mockSurfaceView1.holder).thenReturn(mockSurfaceHolder1)
- val mockSurfaceHolder2 = mock(SurfaceHolder::class.java)
- `when`(mockSurfaceView2.holder).thenReturn(mockSurfaceHolder2)
-
- val virtualDisplays = createVirtualDisplays(2)
-
- // Simulate an InputDevice
- val inputDevice = createInputDevice()
-
- // Associate input device with display
- service.addUniqueIdAssociationByPort(
- inputDevice.name,
- virtualDisplays[0].display.displayId.toString()
- )
-
- // Simulate 2 different KeyEvents
- val downEvent = createKeycodeAEvent(inputDevice, KeyEvent.ACTION_DOWN)
- val upEvent = createKeycodeAEvent(inputDevice, KeyEvent.ACTION_UP)
-
- // Create a mock OnKeyListener object
- val mockOnKeyListener = mock(OnKeyListener::class.java)
-
- // Verify that the event went to Display 1 not Display 2
- service.injectInputEvent(downEvent, InputEventInjectionSync.NONE)
-
- // Call the onKey method on the mock OnKeyListener object
- mockOnKeyListener.onKey(mockSurfaceView1, /* keyCode= */ KeyEvent.KEYCODE_A, downEvent)
- mockOnKeyListener.onKey(mockSurfaceView2, /* keyCode= */ KeyEvent.KEYCODE_A, upEvent)
-
- // Verify that the onKey method was called with the expected arguments
- verify(mockOnKeyListener).onKey(mockSurfaceView1, KeyEvent.KEYCODE_A, downEvent)
- verify(mockOnKeyListener, never()).onKey(mockSurfaceView2, KeyEvent.KEYCODE_A, downEvent)
-
- // Remove association
- service.removeUniqueIdAssociationByPort(inputDevice.name)
-
- // Associate with Display 2
- service.addUniqueIdAssociationByPort(
- inputDevice.name,
- virtualDisplays[1].display.displayId.toString()
- )
-
- // Simulate a KeyEvent
- service.injectInputEvent(upEvent, InputEventInjectionSync.NONE)
-
- // Verify that the event went to Display 2 not Display 1
- verify(mockOnKeyListener).onKey(mockSurfaceView2, KeyEvent.KEYCODE_A, upEvent)
- verify(mockOnKeyListener, never()).onKey(mockSurfaceView1, KeyEvent.KEYCODE_A, upEvent)
- }
}
private fun <T> whenever(methodCall: T): OngoingStubbing<T> = `when`(methodCall)