Skip to content

Commit

Permalink
ShadowInputManager.getInputDeviceIds() will now return results that c…
Browse files Browse the repository at this point in the history
…orroborate the return values of .getInputDevices().

Before this commit, ShadowInputManager.getInputDeviceIds() would only ever return an empty array even if there were InputDevices present. This change uses the result of ShadowInputManager.getInputDevices() to return an int array of all IDs present for a more realistic result

PiperOrigin-RevId: 589979183
  • Loading branch information
Googler authored and Copybara-Service committed Dec 13, 2023
1 parent 5043dab commit 6254ced
Showing 1 changed file with 15 additions and 1 deletion.
Expand Up @@ -44,7 +44,21 @@ protected boolean[] deviceHasKeys(int id, int[] keyCodes) {
/** Used in {@link InputDevice#getDeviceIds()} */
@Implementation
protected int[] getInputDeviceIds() {
return new int[0];
if (!ReflectionHelpers.hasField(InputManager.class, "mInputDevices")) {
return new int[0];
}

SparseArray<InputDevice> inputDevices = getInputDevices();
if (inputDevices == null) {
return new int[0];
}

int[] ids = new int[inputDevices.size()];
for (int i = 0; i < inputDevices.size(); i++) {
ids[i] = inputDevices.get(i).getId();
}

return ids;
}

@Implementation(maxSdk = TIRAMISU)
Expand Down

0 comments on commit 6254ced

Please sign in to comment.