Add repeat count to HW_KEY_INPUT
Service will inspect the length of int32Values and use
indentCount if VHAL provided it in HW_KEY_INPUT.
Add unit test for this case.
Bug: 132291593
Test: Unit Test
Change-Id: Iaca27dcb7330973d3aeb47bc825f32a031fb55f1
diff --git a/service/src/com/android/car/hal/InputHalService.java b/service/src/com/android/car/hal/InputHalService.java
index f0993eb..d719510 100644
--- a/service/src/com/android/car/hal/InputHalService.java
+++ b/service/src/com/android/car/hal/InputHalService.java
@@ -140,12 +140,19 @@
KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP;
int code = v.value.int32Values.get(1);
int display = v.value.int32Values.get(2);
+ int indentsCount = v.value.int32Values.size() < 4 ? 1 : v.value.int32Values.get(3);
if (DBG) {
- Log.i(CarLog.TAG_INPUT, "hal event code:" + code + ", action:" + action +
- ", display:" + display);
+ Log.i(CarLog.TAG_INPUT, new StringBuilder()
+ .append("hal event code:").append(code)
+ .append(", action:").append(action)
+ .append(", display: ").append(display)
+ .append(", number of indents: ").append(indentsCount)
+ .toString());
}
-
- dispatchKeyEvent(listener, action, code, display);
+ while (indentsCount > 0) {
+ indentsCount--;
+ dispatchKeyEvent(listener, action, code, display);
+ }
}
}
diff --git a/tests/carservice_unit_test/src/com/android/car/hal/InputHalServiceTest.java b/tests/carservice_unit_test/src/com/android/car/hal/InputHalServiceTest.java
index 32f8e1d..5cce922 100644
--- a/tests/carservice_unit_test/src/com/android/car/hal/InputHalServiceTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/hal/InputHalServiceTest.java
@@ -181,6 +181,28 @@
assertThat(event.getRepeatCount()).isEqualTo(0);
}
+ /**
+ * Test for handling rotary knob event.
+ */
+ @Test
+ public void handlesRepeatedKeyWithIndents() {
+ subscribeListener();
+ KeyEvent event = dispatchSingleEventWithIndents(KeyEvent.KEYCODE_VOLUME_UP, 5);
+ assertThat(event.getAction()).isEqualTo(KeyEvent.ACTION_DOWN);
+ assertThat(event.getKeyCode()).isEqualTo(KeyEvent.KEYCODE_VOLUME_UP);
+ assertThat(event.getEventTime()).isEqualTo(0L);
+ assertThat(event.getDownTime()).isEqualTo(0L);
+ assertThat(event.getRepeatCount()).isEqualTo(4);
+
+ when(mUptimeSupplier.getAsLong()).thenReturn(5L);
+ event = dispatchSingleEventWithIndents(KeyEvent.KEYCODE_VOLUME_UP, 5);
+ assertThat(event.getAction()).isEqualTo(KeyEvent.ACTION_DOWN);
+ assertThat(event.getKeyCode()).isEqualTo(KeyEvent.KEYCODE_VOLUME_UP);
+ assertThat(event.getEventTime()).isEqualTo(5L);
+ assertThat(event.getDownTime()).isEqualTo(5L);
+ assertThat(event.getRepeatCount()).isEqualTo(9);
+ }
+
@Test
public void handlesKeyUp_withoutKeyDown() {
subscribeListener();
@@ -237,4 +259,25 @@
reset(mInputListener);
return captor.getValue();
}
-}
+
+ private VehiclePropValue makeKeyPropValueWithIndents(int code, int indents) {
+ VehiclePropValue v = new VehiclePropValue();
+ v.prop = VehicleProperty.HW_KEY_INPUT;
+ // Only Key.down can have indents.
+ v.value.int32Values.add(VehicleHwKeyInputAction.ACTION_DOWN);
+ v.value.int32Values.add(code);
+ v.value.int32Values.add(DISPLAY);
+ v.value.int32Values.add(indents);
+ return v;
+ }
+
+ private KeyEvent dispatchSingleEventWithIndents(int code, int indents) {
+ ArgumentCaptor<KeyEvent> captor = ArgumentCaptor.forClass(KeyEvent.class);
+ reset(mInputListener);
+ mInputHalService.handleHalEvents(
+ ImmutableList.of(makeKeyPropValueWithIndents(code, indents)));
+ verify(mInputListener).onKeyEvent(captor.capture(), eq(DISPLAY));
+ reset(mInputListener);
+ return captor.getValue();
+ }
+}
\ No newline at end of file