aboutsummaryrefslogtreecommitdiff
path: root/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink
diff options
context:
space:
mode:
authorEnrico Granata <egranata@google.com>2018-05-23 14:41:25 -0700
committerEnrico Granata <egranata@google.com>2018-05-23 14:41:25 -0700
commit9bc6ec968099c014c16c57ceee963e4cf5eef1c0 (patch)
treed5e6158a09058dc3eab6f3949a81b9ad86fbb5b9 /tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink
parent7b25e6ad5fba7f0a0daff1f6831be6ee8e6d25b3 (diff)
downloadCar-9bc6ec968099c014c16c57ceee963e4cf5eef1c0.tar.gz
Hook logging of VHAL HW_KEY_INPUT events in KitchenSink
Bug: 75276159 Test: manual Change-Id: I3e07a3735f51083a03bf3d1db806279d9d0530e0
Diffstat (limited to 'tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink')
-rw-r--r--tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/input/InputTestFragment.java54
1 files changed, 52 insertions, 2 deletions
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/input/InputTestFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/input/InputTestFragment.java
index 4b9ec1d25b..3e136756c2 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/input/InputTestFragment.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/input/InputTestFragment.java
@@ -15,11 +15,18 @@
*/
package com.google.android.car.kitchensink.input;
+import static android.hardware.automotive.vehicle.V2_0.SubscribeFlags.EVENTS_FROM_ANDROID;
+import static android.hardware.automotive.vehicle.V2_0.SubscribeFlags.EVENTS_FROM_CAR;
import static android.hardware.automotive.vehicle.V2_0.VehicleDisplay.INSTRUMENT_CLUSTER;
+import static android.hardware.automotive.vehicle.V2_0.VehicleHwKeyInputAction.ACTION_DOWN;
+import static android.hardware.automotive.vehicle.V2_0.VehicleProperty.HW_KEY_INPUT;
import android.annotation.Nullable;
import android.annotation.StringRes;
import android.hardware.automotive.vehicle.V2_0.IVehicle;
+import android.hardware.automotive.vehicle.V2_0.IVehicleCallback;
+import android.hardware.automotive.vehicle.V2_0.IVehicleCallback.Stub;
+import android.hardware.automotive.vehicle.V2_0.SubscribeOptions;
import android.hardware.automotive.vehicle.V2_0.VehicleArea;
import android.hardware.automotive.vehicle.V2_0.VehicleDisplay;
import android.hardware.automotive.vehicle.V2_0.VehiclePropValue;
@@ -87,10 +94,37 @@ public class InputTestFragment extends Fragment {
@Override
public void onEvent(KeypressEvent keypressEvent) throws RemoteException {
Log.d(TAG, "received event " + keypressEvent);
- mInputEventsList.append(prettyPrint(keypressEvent));
+ synchronized (mInputEventsList) {
+ mInputEventsList.append(prettyPrint(keypressEvent));
+ }
}
};
+ private final IVehicleCallback.Stub mHalKeyEventHandler = new Stub() {
+ private String prettyPrint(VehiclePropValue event) {
+ if (event.prop != HW_KEY_INPUT) return "";
+ if (event.value == null ||
+ event.value.int32Values == null ||
+ event.value.int32Values.size() < 2) return "";
+ return String.format("Event{source = HAL, keycode = %s, key%s}\n",
+ event.value.int32Values.get(1),
+ event.value.int32Values.get(0) == ACTION_DOWN ? "down" : "up");
+ }
+
+ @Override
+ public void onPropertyEvent(ArrayList<VehiclePropValue> propValues) throws RemoteException {
+ synchronized (mInputEventsList) {
+ propValues.forEach(vpv -> mInputEventsList.append(prettyPrint(vpv)));
+ }
+ }
+
+ @Override
+ public void onPropertySet(VehiclePropValue propValue) {}
+
+ @Override
+ public void onPropertySetError(int errorCode, int propId, int areaId) {}
+ };
+
private TextView mInputEventsList;
@Override
@@ -111,6 +145,17 @@ public class InputTestFragment extends Fragment {
if (mEventReaderService != null) {
mEventReaderService.registerCallback(mKeypressEventHandler);
}
+
+ SubscribeOptions subscribeOption = new SubscribeOptions();
+ subscribeOption.propId = HW_KEY_INPUT;
+ subscribeOption.flags = EVENTS_FROM_CAR | EVENTS_FROM_ANDROID;
+ ArrayList<SubscribeOptions> subscribeOptions = new ArrayList<>();
+ subscribeOptions.add(subscribeOption);
+ try {
+ mVehicle.subscribe(mHalKeyEventHandler, subscribeOptions);
+ } catch (RemoteException e) {
+ Log.e(TAG, "failed to connect to VHAL for key events", e);
+ }
}
@Nullable
@@ -178,7 +223,7 @@ public class InputTestFragment extends Fragment {
VehiclePropValue prop = new VehiclePropValue();
prop.prop = sGenerateFakeDataControllingProperty;
prop.value.int32Values.addAll(Lists.newArrayList(
- sKeyPressCommand, VehicleProperty.HW_KEY_INPUT, keyCode, targetDisplay));
+ sKeyPressCommand, HW_KEY_INPUT, keyCode, targetDisplay));
int status;
try {
status = mVehicle.set(prop);
@@ -199,6 +244,11 @@ public class InputTestFragment extends Fragment {
if (mEventReaderService != null) {
mEventReaderService.unregisterCallback(mKeypressEventHandler);
}
+ try {
+ mVehicle.unsubscribe(mHalKeyEventHandler, HW_KEY_INPUT);
+ } catch (RemoteException e) {
+ Log.e(TAG, "failed to remove HAL registration for keypress events", e);
+ }
}
private void addButtonsToPanel(LinearLayout root, List<View> buttons) {