diff options
-rw-r--r-- | cmds/hid/jni/com_android_commands_hid_Device.cpp | 28 | ||||
-rw-r--r-- | cmds/hid/jni/com_android_commands_hid_Device.h | 5 | ||||
-rw-r--r-- | cmds/hid/src/com/android/commands/hid/Device.java | 10 | ||||
-rw-r--r-- | cmds/hid/src/com/android/commands/hid/Event.java | 17 | ||||
-rw-r--r-- | cmds/hid/src/com/android/commands/hid/Hid.java | 13 |
5 files changed, 56 insertions, 17 deletions
diff --git a/cmds/hid/jni/com_android_commands_hid_Device.cpp b/cmds/hid/jni/com_android_commands_hid_Device.cpp index 8b8d361edbd4..a142450ac0c6 100644 --- a/cmds/hid/jni/com_android_commands_hid_Device.cpp +++ b/cmds/hid/jni/com_android_commands_hid_Device.cpp @@ -134,8 +134,9 @@ JNIEnv* DeviceCallback::getJNIEnv() { return env; } -std::unique_ptr<Device> Device::open(int32_t id, const char* name, int32_t vid, int32_t pid, - uint16_t bus, const std::vector<uint8_t>& descriptor, +std::unique_ptr<Device> Device::open(int32_t id, const char* name, const char* uniq, int32_t vid, + int32_t pid, uint16_t bus, + const std::vector<uint8_t>& descriptor, std::unique_ptr<DeviceCallback> callback) { size_t size = descriptor.size(); if (size > HID_MAX_DESCRIPTOR_SIZE) { @@ -152,8 +153,7 @@ std::unique_ptr<Device> Device::open(int32_t id, const char* name, int32_t vid, struct uhid_event ev = {}; ev.type = UHID_CREATE2; strlcpy(reinterpret_cast<char*>(ev.u.create2.name), name, sizeof(ev.u.create2.name)); - std::string uniq = android::base::StringPrintf("Id: %d", id); - strlcpy(reinterpret_cast<char*>(ev.u.create2.uniq), uniq.c_str(), sizeof(ev.u.create2.uniq)); + strlcpy(reinterpret_cast<char*>(ev.u.create2.uniq), uniq, sizeof(ev.u.create2.uniq)); memcpy(&ev.u.create2.rd_data, descriptor.data(), size * sizeof(ev.u.create2.rd_data[0])); ev.u.create2.rd_size = size; ev.u.create2.bus = bus; @@ -314,19 +314,31 @@ std::vector<uint8_t> getData(JNIEnv* env, jbyteArray javaArray) { return data; } -static jlong openDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jint id, jint vid, - jint pid, jint bus, jbyteArray rawDescriptor, jobject callback) { +static jlong openDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jstring rawUniq, jint id, + jint vid, jint pid, jint bus, jbyteArray rawDescriptor, jobject callback) { ScopedUtfChars name(env, rawName); if (name.c_str() == nullptr) { return 0; } + std::string uniq; + if (rawUniq != nullptr) { + uniq = ScopedUtfChars(env, rawUniq); + } else { + uniq = android::base::StringPrintf("Id: %d", id); + } + + if (uniq.c_str() == nullptr) { + return 0; + } + std::vector<uint8_t> desc = getData(env, rawDescriptor); std::unique_ptr<uhid::DeviceCallback> cb(new uhid::DeviceCallback(env, callback)); std::unique_ptr<uhid::Device> d = - uhid::Device::open(id, reinterpret_cast<const char*>(name.c_str()), vid, pid, bus, desc, + uhid::Device::open(id, reinterpret_cast<const char*>(name.c_str()), + reinterpret_cast<const char*>(uniq.c_str()), vid, pid, bus, desc, std::move(cb)); return reinterpret_cast<jlong>(d.release()); } @@ -370,7 +382,7 @@ static void closeDevice(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) { static JNINativeMethod sMethods[] = { {"nativeOpenDevice", - "(Ljava/lang/String;IIII[B" + "(Ljava/lang/String;Ljava/lang/String;IIII[B" "Lcom/android/commands/hid/Device$DeviceCallback;)J", reinterpret_cast<void*>(openDevice)}, {"nativeSendReport", "(J[B)V", reinterpret_cast<void*>(sendReport)}, diff --git a/cmds/hid/jni/com_android_commands_hid_Device.h b/cmds/hid/jni/com_android_commands_hid_Device.h index 9c6060d837e0..bc7a9092cc4e 100644 --- a/cmds/hid/jni/com_android_commands_hid_Device.h +++ b/cmds/hid/jni/com_android_commands_hid_Device.h @@ -42,8 +42,9 @@ private: class Device { public: - static std::unique_ptr<Device> open(int32_t id, const char* name, int32_t vid, int32_t pid, - uint16_t bus, const std::vector<uint8_t>& descriptor, + static std::unique_ptr<Device> open(int32_t id, const char* name, const char* uniq, int32_t vid, + int32_t pid, uint16_t bus, + const std::vector<uint8_t>& descriptor, std::unique_ptr<DeviceCallback> callback); ~Device(); diff --git a/cmds/hid/src/com/android/commands/hid/Device.java b/cmds/hid/src/com/android/commands/hid/Device.java index 0415037cfc9f..4e8adc3af55c 100644 --- a/cmds/hid/src/com/android/commands/hid/Device.java +++ b/cmds/hid/src/com/android/commands/hid/Device.java @@ -71,6 +71,7 @@ public class Device { private static native long nativeOpenDevice( String name, + String uniq, int id, int vid, int pid, @@ -89,6 +90,7 @@ public class Device { public Device( int id, String name, + String uniq, int vid, int pid, int bus, @@ -113,8 +115,9 @@ public class Device { } else { args.arg1 = id + ":" + vid + ":" + pid; } - args.arg2 = descriptor; - args.arg3 = report; + args.arg2 = uniq; + args.arg3 = descriptor; + args.arg4 = report; mHandler.obtainMessage(MSG_OPEN_DEVICE, args).sendToTarget(); mTimeToSend = SystemClock.uptimeMillis(); } @@ -167,11 +170,12 @@ public class Device { mPtr = nativeOpenDevice( (String) args.arg1, + (String) args.arg2, args.argi1, args.argi2, args.argi3, args.argi4, - (byte[]) args.arg2, + (byte[]) args.arg3, new DeviceCallback()); pauseEvents(); break; diff --git a/cmds/hid/src/com/android/commands/hid/Event.java b/cmds/hid/src/com/android/commands/hid/Event.java index 3efb79766b94..3b022796356b 100644 --- a/cmds/hid/src/com/android/commands/hid/Event.java +++ b/cmds/hid/src/com/android/commands/hid/Event.java @@ -56,6 +56,7 @@ public class Event { private int mId; private String mCommand; private String mName; + private String mUniq; private byte[] mDescriptor; private int mVid; private int mPid; @@ -78,6 +79,10 @@ public class Event { return mName; } + public String getUniq() { + return mUniq; + } + public byte[] getDescriptor() { return mDescriptor; } @@ -116,8 +121,9 @@ public class Event { public String toString() { return "Event{id=" + mId - + ", command=" + String.valueOf(mCommand) - + ", name=" + String.valueOf(mName) + + ", command=" + mCommand + + ", name=" + mName + + ", uniq=" + mUniq + ", descriptor=" + Arrays.toString(mDescriptor) + ", vid=" + mVid + ", pid=" + mPid @@ -149,6 +155,10 @@ public class Event { mEvent.mName = name; } + public void setUniq(String uniq) { + mEvent.mUniq = uniq; + } + public void setDescriptor(byte[] descriptor) { mEvent.mDescriptor = descriptor; } @@ -247,6 +257,9 @@ public class Event { case "name": eb.setName(mReader.nextString()); break; + case "uniq": + eb.setUniq(mReader.nextString()); + break; case "vid": eb.setVid(readInt()); break; diff --git a/cmds/hid/src/com/android/commands/hid/Hid.java b/cmds/hid/src/com/android/commands/hid/Hid.java index 2db791fe90bd..5ebfd959ef33 100644 --- a/cmds/hid/src/com/android/commands/hid/Hid.java +++ b/cmds/hid/src/com/android/commands/hid/Hid.java @@ -117,8 +117,17 @@ public class Hid { "Tried to send command \"" + e.getCommand() + "\" to an unregistered device!"); } int id = e.getId(); - Device d = new Device(id, e.getName(), e.getVendorId(), e.getProductId(), e.getBus(), - e.getDescriptor(), e.getReport(), e.getFeatureReports(), e.getOutputs()); + Device d = new Device( + id, + e.getName(), + e.getUniq(), + e.getVendorId(), + e.getProductId(), + e.getBus(), + e.getDescriptor(), + e.getReport(), + e.getFeatureReports(), + e.getOutputs()); mDevices.append(id, d); } |