aboutsummaryrefslogtreecommitdiff
path: root/tests/EmbeddedKitchenSinkApp
diff options
context:
space:
mode:
authorEnrico Granata <egranata@google.com>2018-05-07 17:42:21 -0700
committerEnrico Granata <egranata@google.com>2018-05-22 11:30:10 -0700
commit3ac2057bd91eb506a4731338f724897cc8f449ae (patch)
tree4e0f54dd35518b225e951551b7f6be509cc9b350 /tests/EmbeddedKitchenSinkApp
parentb273a47d62c237dbc9069ace6ef834942d192d39 (diff)
downloadCar-3ac2057bd91eb506a4731338f724897cc8f449ae.tar.gz
Service and KitchenSink logic to read the kernel's input event queues
This patch provides a native service that can manually be built, installed to a device, and launched, e.g. sh# /system/bin/com.android.car.keventreader /dev/input/event* The service will monitor the files provided as input (expecting them to be kernel input queues in the format described at, e.g. https://github.com/torvalds/linux/blob/master/include/uapi/linux/input.h), and generate events upon reading EV_KEY events from each such file. The patch also includes a KitchenSink hook to talk to the native service and receive key events from it. Bug: 78258802 Test: manual on Mojave Change-Id: If7f2f1f72e4dc6a26cd9d32b31e90e494d55650b Merged-In: If7f2f1f72e4dc6a26cd9d32b31e90e494d55650b
Diffstat (limited to 'tests/EmbeddedKitchenSinkApp')
-rw-r--r--tests/EmbeddedKitchenSinkApp/Android.mk3
-rw-r--r--tests/EmbeddedKitchenSinkApp/res/layout/input_test.xml17
-rw-r--r--tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/input/InputTestFragment.java38
3 files changed, 57 insertions, 1 deletions
diff --git a/tests/EmbeddedKitchenSinkApp/Android.mk b/tests/EmbeddedKitchenSinkApp/Android.mk
index 3c04fd514c..7a8c1459a6 100644
--- a/tests/EmbeddedKitchenSinkApp/Android.mk
+++ b/tests/EmbeddedKitchenSinkApp/Android.mk
@@ -47,7 +47,8 @@ LOCAL_STATIC_ANDROID_LIBRARIES += \
LOCAL_STATIC_JAVA_LIBRARIES += \
android.hidl.base-V1.0-java \
android.hardware.automotive.vehicle-V2.0-java \
- vehicle-hal-support-lib
+ vehicle-hal-support-lib \
+ com.android.car.keventreader-client
include packages/services/Car/car-support-lib/car-support.mk
diff --git a/tests/EmbeddedKitchenSinkApp/res/layout/input_test.xml b/tests/EmbeddedKitchenSinkApp/res/layout/input_test.xml
index 1d9f3178da..03a90e080f 100644
--- a/tests/EmbeddedKitchenSinkApp/res/layout/input_test.xml
+++ b/tests/EmbeddedKitchenSinkApp/res/layout/input_test.xml
@@ -24,4 +24,21 @@
android:id="@+id/input_buttons">
<!-- Filled at runtime. -->
</LinearLayout>
+ <ScrollView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_marginLeft="15dp"
+ android:layout_marginRight="15dp"
+ android:layout_marginTop="20dp"
+ android:fillViewport="true">
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="bottom"
+ android:scrollbars="vertical"
+ android:textSize="24px"
+ android:typeface="monospace"
+ android:id="@+id/events_list"/>
+ </ScrollView>
</LinearLayout>
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 ff6ef21c55..4b9ec1d25b 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
@@ -30,6 +30,7 @@ import android.hardware.automotive.vehicle.V2_0.VehiclePropertyType;
import android.os.Bundle;
import android.os.RemoteException;
import android.support.v4.app.Fragment;
+import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -40,6 +41,12 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
+import android.support.v4.app.Fragment;
+
+import com.android.car.keventreader.EventReaderService;
+import com.android.car.keventreader.IEventCallback;
+import com.android.car.keventreader.KeypressEvent;
+
import com.google.android.car.kitchensink.R;
import com.google.android.collect.Lists;
@@ -67,6 +74,25 @@ public class InputTestFragment extends Fragment {
private IVehicle mVehicle;
+ private EventReaderService mEventReaderService;
+
+ private final IEventCallback.Stub mKeypressEventHandler = new IEventCallback.Stub() {
+ private String prettyPrint(KeypressEvent event) {
+ return String.format("Event{source = %s, keycode = %s, key%s}\n",
+ event.source,
+ event.keycodeToString(),
+ event.isKeydown ? "down" : "up");
+ }
+
+ @Override
+ public void onEvent(KeypressEvent keypressEvent) throws RemoteException {
+ Log.d(TAG, "received event " + keypressEvent);
+ mInputEventsList.append(prettyPrint(keypressEvent));
+ }
+ };
+
+ private TextView mInputEventsList;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -79,6 +105,12 @@ public class InputTestFragment extends Fragment {
throw new RuntimeException("Failed to connect to IVehicle");
}
Log.d(TAG, "Connected to IVehicle service: " + mVehicle);
+
+ mEventReaderService = EventReaderService.tryGet();
+ Log.d(TAG, "Key Event Reader service: " + mEventReaderService);
+ if (mEventReaderService != null) {
+ mEventReaderService.registerCallback(mKeypressEventHandler);
+ }
}
@Nullable
@@ -87,6 +119,9 @@ public class InputTestFragment extends Fragment {
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.input_test, container, false);
+ mInputEventsList = view.findViewById(R.id.events_list);
+ mInputEventsList.setMovementMethod(new ScrollingMovementMethod());
+
TextView steeringWheelLabel = new TextView(getActivity() /*context*/);
steeringWheelLabel.setText(R.string.steering_wheel);
steeringWheelLabel.setTextSize(getResources().getDimension(R.dimen.car_title2_size));
@@ -161,6 +196,9 @@ public class InputTestFragment extends Fragment {
public void onDestroyView() {
super.onDestroyView();
mButtons.clear();
+ if (mEventReaderService != null) {
+ mEventReaderService.unregisterCallback(mKeypressEventHandler);
+ }
}
private void addButtonsToPanel(LinearLayout root, List<View> buttons) {