From 4dd2f7f838f37d399295765cc9e7d02e2ef8762f Mon Sep 17 00:00:00 2001 From: Chris Ye Date: Fri, 19 Feb 2021 16:17:15 -0800 Subject: [PATCH] Add SET_REPORT data output to hid commandline tool. Linux HID driver could use SET_REPORT to communicate with HID low level driver, capture the SET_REPORT output data in hid command line tool. Bug: 161633625 Test: Manual tests. Change-Id: Iea30b57078660c516f1b2756552884eebbc15e0e --- cmds/hid/jni/com_android_commands_hid_Device.cpp | 10 ++++++---- cmds/hid/jni/com_android_commands_hid_Device.h | 2 +- cmds/hid/src/com/android/commands/hid/Device.java | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmds/hid/jni/com_android_commands_hid_Device.cpp b/cmds/hid/jni/com_android_commands_hid_Device.cpp index 437a87e8df54b..422c2be44251b 100644 --- a/cmds/hid/jni/com_android_commands_hid_Device.cpp +++ b/cmds/hid/jni/com_android_commands_hid_Device.cpp @@ -113,9 +113,10 @@ void DeviceCallback::onDeviceGetReport(uint32_t requestId, uint8_t reportId) { checkAndClearException(env, "onDeviceGetReport"); } -void DeviceCallback::onDeviceOutput(uint8_t rType, const std::vector& data) { +void DeviceCallback::onDeviceOutput(uint8_t eventId, uint8_t rType, + const std::vector& data) { JNIEnv* env = getJNIEnv(); - env->CallVoidMethod(mCallbackObject, gDeviceCallbackClassInfo.onDeviceOutput, rType, + env->CallVoidMethod(mCallbackObject, gDeviceCallbackClassInfo.onDeviceOutput, eventId, rType, toJbyteArray(env, data).get()); checkAndClearException(env, "onDeviceOutput"); } @@ -261,6 +262,7 @@ int Device::handleEvents(int events) { ALOGD("Received SET_REPORT: id=%" PRIu32 " rnum=%" PRIu8 " data=%s", set_report.id, set_report.rnum, toString(data).c_str()); } + mDeviceCallback->onDeviceOutput(UHID_SET_REPORT, set_report.rtype, data); break; } case UHID_OUTPUT: { @@ -269,7 +271,7 @@ int Device::handleEvents(int events) { if (DEBUG_OUTPUT) { ALOGD("UHID_OUTPUT rtype=%" PRIu8 " data=%s", output.rtype, toString(data).c_str()); } - mDeviceCallback->onDeviceOutput(output.rtype, data); + mDeviceCallback->onDeviceOutput(UHID_OUTPUT, output.rtype, data); break; } default: { @@ -365,7 +367,7 @@ int register_com_android_commands_hid_Device(JNIEnv* env) { uhid::gDeviceCallbackClassInfo.onDeviceGetReport = env->GetMethodID(clazz, "onDeviceGetReport", "(II)V"); uhid::gDeviceCallbackClassInfo.onDeviceOutput = - env->GetMethodID(clazz, "onDeviceOutput", "(B[B)V"); + env->GetMethodID(clazz, "onDeviceOutput", "(BB[B)V"); uhid::gDeviceCallbackClassInfo.onDeviceError = env->GetMethodID(clazz, "onDeviceError", "()V"); if (uhid::gDeviceCallbackClassInfo.onDeviceOpen == NULL || diff --git a/cmds/hid/jni/com_android_commands_hid_Device.h b/cmds/hid/jni/com_android_commands_hid_Device.h index 5483b40831a0d..bb73132cc20d6 100644 --- a/cmds/hid/jni/com_android_commands_hid_Device.h +++ b/cmds/hid/jni/com_android_commands_hid_Device.h @@ -31,7 +31,7 @@ public: void onDeviceOpen(); void onDeviceGetReport(uint32_t requestId, uint8_t reportId); - void onDeviceOutput(uint8_t rType, const std::vector& data); + void onDeviceOutput(uint8_t eventId, uint8_t rType, const std::vector& data); void onDeviceError(); private: diff --git a/cmds/hid/src/com/android/commands/hid/Device.java b/cmds/hid/src/com/android/commands/hid/Device.java index 20b4bd86baec8..37d0b1c6bfa1e 100644 --- a/cmds/hid/src/com/android/commands/hid/Device.java +++ b/cmds/hid/src/com/android/commands/hid/Device.java @@ -46,7 +46,8 @@ public class Device { // Sync with linux uhid_event_type::UHID_OUTPUT private static final byte UHID_EVENT_TYPE_UHID_OUTPUT = 6; - + // Sync with linux uhid_event_type::UHID_SET_REPORT + private static final byte UHID_EVENT_TYPE_SET_REPORT = 13; private final int mId; private final HandlerThread mThread; private final DeviceHandler mHandler; @@ -199,10 +200,10 @@ public class Device { } // native callback - public void onDeviceOutput(byte rtype, byte[] data) { + public void onDeviceOutput(byte eventId, byte rtype, byte[] data) { JSONObject json = new JSONObject(); try { - json.put("eventId", UHID_EVENT_TYPE_UHID_OUTPUT); + json.put("eventId", eventId); json.put("deviceId", mId); json.put("reportType", rtype); JSONArray dataArray = new JSONArray();