Merge "Add onDeviceSetReport to HID command tool" into sc-dev am: e43039e0dd
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13669696 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I25e58753fa2cb7cc015b6078f4536c1e9fbe9fc1
This commit is contained in:
@@ -48,6 +48,7 @@ static const char* UHID_PATH = "/dev/uhid";
|
|||||||
static struct {
|
static struct {
|
||||||
jmethodID onDeviceOpen;
|
jmethodID onDeviceOpen;
|
||||||
jmethodID onDeviceGetReport;
|
jmethodID onDeviceGetReport;
|
||||||
|
jmethodID onDeviceSetReport;
|
||||||
jmethodID onDeviceOutput;
|
jmethodID onDeviceOutput;
|
||||||
jmethodID onDeviceError;
|
jmethodID onDeviceError;
|
||||||
} gDeviceCallbackClassInfo;
|
} gDeviceCallbackClassInfo;
|
||||||
@@ -113,10 +114,18 @@ void DeviceCallback::onDeviceGetReport(uint32_t requestId, uint8_t reportId) {
|
|||||||
checkAndClearException(env, "onDeviceGetReport");
|
checkAndClearException(env, "onDeviceGetReport");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceCallback::onDeviceOutput(uint8_t eventId, uint8_t rType,
|
void DeviceCallback::onDeviceSetReport(uint8_t rType,
|
||||||
const std::vector<uint8_t>& data) {
|
const std::vector<uint8_t>& data) {
|
||||||
JNIEnv* env = getJNIEnv();
|
JNIEnv* env = getJNIEnv();
|
||||||
env->CallVoidMethod(mCallbackObject, gDeviceCallbackClassInfo.onDeviceOutput, eventId, rType,
|
env->CallVoidMethod(mCallbackObject, gDeviceCallbackClassInfo.onDeviceSetReport, rType,
|
||||||
|
toJbyteArray(env, data).get());
|
||||||
|
checkAndClearException(env, "onDeviceSetReport");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceCallback::onDeviceOutput(uint8_t rType,
|
||||||
|
const std::vector<uint8_t>& data) {
|
||||||
|
JNIEnv* env = getJNIEnv();
|
||||||
|
env->CallVoidMethod(mCallbackObject, gDeviceCallbackClassInfo.onDeviceOutput, rType,
|
||||||
toJbyteArray(env, data).get());
|
toJbyteArray(env, data).get());
|
||||||
checkAndClearException(env, "onDeviceOutput");
|
checkAndClearException(env, "onDeviceOutput");
|
||||||
}
|
}
|
||||||
@@ -262,7 +271,7 @@ int Device::handleEvents(int events) {
|
|||||||
ALOGD("Received SET_REPORT: id=%" PRIu32 " rnum=%" PRIu8 " data=%s", set_report.id,
|
ALOGD("Received SET_REPORT: id=%" PRIu32 " rnum=%" PRIu8 " data=%s", set_report.id,
|
||||||
set_report.rnum, toString(data).c_str());
|
set_report.rnum, toString(data).c_str());
|
||||||
}
|
}
|
||||||
mDeviceCallback->onDeviceOutput(UHID_SET_REPORT, set_report.rtype, data);
|
mDeviceCallback->onDeviceSetReport(set_report.rtype, data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UHID_OUTPUT: {
|
case UHID_OUTPUT: {
|
||||||
@@ -271,7 +280,7 @@ int Device::handleEvents(int events) {
|
|||||||
if (DEBUG_OUTPUT) {
|
if (DEBUG_OUTPUT) {
|
||||||
ALOGD("UHID_OUTPUT rtype=%" PRIu8 " data=%s", output.rtype, toString(data).c_str());
|
ALOGD("UHID_OUTPUT rtype=%" PRIu8 " data=%s", output.rtype, toString(data).c_str());
|
||||||
}
|
}
|
||||||
mDeviceCallback->onDeviceOutput(UHID_OUTPUT, output.rtype, data);
|
mDeviceCallback->onDeviceOutput(output.rtype, data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -366,8 +375,10 @@ int register_com_android_commands_hid_Device(JNIEnv* env) {
|
|||||||
env->GetMethodID(clazz, "onDeviceOpen", "()V");
|
env->GetMethodID(clazz, "onDeviceOpen", "()V");
|
||||||
uhid::gDeviceCallbackClassInfo.onDeviceGetReport =
|
uhid::gDeviceCallbackClassInfo.onDeviceGetReport =
|
||||||
env->GetMethodID(clazz, "onDeviceGetReport", "(II)V");
|
env->GetMethodID(clazz, "onDeviceGetReport", "(II)V");
|
||||||
|
uhid::gDeviceCallbackClassInfo.onDeviceSetReport =
|
||||||
|
env->GetMethodID(clazz, "onDeviceSetReport", "(B[B)V");
|
||||||
uhid::gDeviceCallbackClassInfo.onDeviceOutput =
|
uhid::gDeviceCallbackClassInfo.onDeviceOutput =
|
||||||
env->GetMethodID(clazz, "onDeviceOutput", "(BB[B)V");
|
env->GetMethodID(clazz, "onDeviceOutput", "(B[B)V");
|
||||||
uhid::gDeviceCallbackClassInfo.onDeviceError =
|
uhid::gDeviceCallbackClassInfo.onDeviceError =
|
||||||
env->GetMethodID(clazz, "onDeviceError", "()V");
|
env->GetMethodID(clazz, "onDeviceError", "()V");
|
||||||
if (uhid::gDeviceCallbackClassInfo.onDeviceOpen == NULL ||
|
if (uhid::gDeviceCallbackClassInfo.onDeviceOpen == NULL ||
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ public:
|
|||||||
|
|
||||||
void onDeviceOpen();
|
void onDeviceOpen();
|
||||||
void onDeviceGetReport(uint32_t requestId, uint8_t reportId);
|
void onDeviceGetReport(uint32_t requestId, uint8_t reportId);
|
||||||
void onDeviceOutput(uint8_t eventId, uint8_t rType, const std::vector<uint8_t>& data);
|
void onDeviceSetReport(uint8_t rType, const std::vector<uint8_t>& data);
|
||||||
|
void onDeviceOutput(uint8_t rType, const std::vector<uint8_t>& data);
|
||||||
void onDeviceError();
|
void onDeviceError();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -199,8 +199,8 @@ public class Device {
|
|||||||
mHandler.sendMessageAtTime(msg, mTimeToSend);
|
mHandler.sendMessageAtTime(msg, mTimeToSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
// native callback
|
// Send out the report to HID command output
|
||||||
public void onDeviceOutput(byte eventId, byte rtype, byte[] data) {
|
private void sendReportOutput(byte eventId, byte rtype, byte[] data) {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
try {
|
try {
|
||||||
json.put("eventId", eventId);
|
json.put("eventId", eventId);
|
||||||
@@ -221,6 +221,18 @@ public class Device {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// native callback
|
||||||
|
public void onDeviceSetReport(byte rtype, byte[] data) {
|
||||||
|
// We don't need to reply for the SET_REPORT but just send it to HID output for test
|
||||||
|
// verification.
|
||||||
|
sendReportOutput(UHID_EVENT_TYPE_SET_REPORT, rtype, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// native callback
|
||||||
|
public void onDeviceOutput(byte rtype, byte[] data) {
|
||||||
|
sendReportOutput(UHID_EVENT_TYPE_UHID_OUTPUT, rtype, data);
|
||||||
if (mOutputs == null) {
|
if (mOutputs == null) {
|
||||||
Log.e(TAG, "Received OUTPUT request, but 'outputs' section is not found");
|
Log.e(TAG, "Received OUTPUT request, but 'outputs' section is not found");
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user