Loading cmds/hid/jni/com_android_commands_hid_Device.cpp +13 −13 Original line number Original line Diff line number Diff line Loading @@ -129,7 +129,7 @@ JNIEnv* DeviceCallback::getJNIEnv() { } } std::unique_ptr<Device> Device::open(int32_t id, const char* name, int32_t vid, int32_t pid, std::unique_ptr<Device> Device::open(int32_t id, const char* name, int32_t vid, int32_t pid, const std::vector<uint8_t>& descriptor, uint16_t bus, const std::vector<uint8_t>& descriptor, std::unique_ptr<DeviceCallback> callback) { std::unique_ptr<DeviceCallback> callback) { size_t size = descriptor.size(); size_t size = descriptor.size(); if (size > HID_MAX_DESCRIPTOR_SIZE) { if (size > HID_MAX_DESCRIPTOR_SIZE) { Loading @@ -148,7 +148,7 @@ std::unique_ptr<Device> Device::open(int32_t id, const char* name, int32_t vid, strlcpy(reinterpret_cast<char*>(ev.u.create2.name), name, sizeof(ev.u.create2.name)); strlcpy(reinterpret_cast<char*>(ev.u.create2.name), name, sizeof(ev.u.create2.name)); memcpy(&ev.u.create2.rd_data, descriptor.data(), size * sizeof(ev.u.create2.rd_data[0])); 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.rd_size = size; ev.u.create2.bus = BUS_BLUETOOTH; ev.u.create2.bus = bus; ev.u.create2.vendor = vid; ev.u.create2.vendor = vid; ev.u.create2.product = pid; ev.u.create2.product = pid; ev.u.create2.version = 0; ev.u.create2.version = 0; Loading Loading @@ -293,8 +293,8 @@ std::vector<uint8_t> getData(JNIEnv* env, jbyteArray javaArray) { return data; return data; } } static jlong openDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jint id, jint vid, jint pid, static jlong openDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jint id, jint vid, jbyteArray rawDescriptor, jobject callback) { jint pid, jint bus, jbyteArray rawDescriptor, jobject callback) { ScopedUtfChars name(env, rawName); ScopedUtfChars name(env, rawName); if (name.c_str() == nullptr) { if (name.c_str() == nullptr) { return 0; return 0; Loading @@ -305,7 +305,7 @@ static jlong openDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jint i std::unique_ptr<uhid::DeviceCallback> cb(new uhid::DeviceCallback(env, callback)); std::unique_ptr<uhid::DeviceCallback> cb(new uhid::DeviceCallback(env, callback)); std::unique_ptr<uhid::Device> d = std::unique_ptr<uhid::Device> d = uhid::Device::open(id, reinterpret_cast<const char*>(name.c_str()), vid, pid, desc, uhid::Device::open(id, reinterpret_cast<const char*>(name.c_str()), vid, pid, bus, desc, std::move(cb)); std::move(cb)); return reinterpret_cast<jlong>(d.release()); return reinterpret_cast<jlong>(d.release()); } } Loading Loading @@ -340,7 +340,7 @@ static void closeDevice(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) { static JNINativeMethod sMethods[] = { static JNINativeMethod sMethods[] = { {"nativeOpenDevice", {"nativeOpenDevice", "(Ljava/lang/String;III[B" "(Ljava/lang/String;IIII[B" "Lcom/android/commands/hid/Device$DeviceCallback;)J", "Lcom/android/commands/hid/Device$DeviceCallback;)J", reinterpret_cast<void*>(openDevice)}, reinterpret_cast<void*>(openDevice)}, {"nativeSendReport", "(J[B)V", reinterpret_cast<void*>(sendReport)}, {"nativeSendReport", "(J[B)V", reinterpret_cast<void*>(sendReport)}, Loading cmds/hid/jni/com_android_commands_hid_Device.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -43,7 +43,7 @@ private: class Device { class Device { public: public: static std::unique_ptr<Device> open(int32_t id, const char* name, int32_t vid, int32_t pid, static std::unique_ptr<Device> open(int32_t id, const char* name, int32_t vid, int32_t pid, const std::vector<uint8_t>& descriptor, uint16_t bus, const std::vector<uint8_t>& descriptor, std::unique_ptr<DeviceCallback> callback); std::unique_ptr<DeviceCallback> callback); ~Device(); ~Device(); Loading cmds/hid/src/com/android/commands/hid/Device.java +4 −3 Original line number Original line Diff line number Diff line Loading @@ -52,13 +52,13 @@ public class Device { System.loadLibrary("hidcommand_jni"); System.loadLibrary("hidcommand_jni"); } } private static native long nativeOpenDevice(String name, int id, int vid, int pid, private static native long nativeOpenDevice(String name, int id, int vid, int pid, int bus, byte[] descriptor, DeviceCallback callback); byte[] descriptor, DeviceCallback callback); private static native void nativeSendReport(long ptr, byte[] data); private static native void nativeSendReport(long ptr, byte[] data); private static native void nativeSendGetFeatureReportReply(long ptr, int id, byte[] data); private static native void nativeSendGetFeatureReportReply(long ptr, int id, byte[] data); private static native void nativeCloseDevice(long ptr); private static native void nativeCloseDevice(long ptr); public Device(int id, String name, int vid, int pid, byte[] descriptor, public Device(int id, String name, int vid, int pid, int bus, byte[] descriptor, byte[] report, SparseArray<byte[]> featureReports, Map<ByteBuffer, byte[]> outputs) { byte[] report, SparseArray<byte[]> featureReports, Map<ByteBuffer, byte[]> outputs) { mId = id; mId = id; mThread = new HandlerThread("HidDeviceHandler"); mThread = new HandlerThread("HidDeviceHandler"); Loading @@ -70,6 +70,7 @@ public class Device { args.argi1 = id; args.argi1 = id; args.argi2 = vid; args.argi2 = vid; args.argi3 = pid; args.argi3 = pid; args.argi4 = bus; if (name != null) { if (name != null) { args.arg1 = name; args.arg1 = name; } else { } else { Loading Loading @@ -115,7 +116,7 @@ public class Device { case MSG_OPEN_DEVICE: case MSG_OPEN_DEVICE: SomeArgs args = (SomeArgs) msg.obj; SomeArgs args = (SomeArgs) msg.obj; mPtr = nativeOpenDevice((String) args.arg1, args.argi1, args.argi2, args.argi3, mPtr = nativeOpenDevice((String) args.arg1, args.argi1, args.argi2, args.argi3, (byte[]) args.arg2, new DeviceCallback()); args.argi4, (byte[]) args.arg2, new DeviceCallback()); pauseEvents(); pauseEvents(); break; break; case MSG_SEND_REPORT: case MSG_SEND_REPORT: Loading cmds/hid/src/com/android/commands/hid/Event.java +33 −0 Original line number Original line Diff line number Diff line Loading @@ -36,12 +36,28 @@ public class Event { public static final String COMMAND_DELAY = "delay"; public static final String COMMAND_DELAY = "delay"; public static final String COMMAND_REPORT = "report"; public static final String COMMAND_REPORT = "report"; // These constants come from "include/uapi/linux/input.h" in the kernel enum Bus { USB(0x03), BLUETOOTH(0x05); Bus(int value) { mValue = value; } int getValue() { return mValue; } private int mValue; } private int mId; private int mId; private String mCommand; private String mCommand; private String mName; private String mName; private byte[] mDescriptor; private byte[] mDescriptor; private int mVid; private int mVid; private int mPid; private int mPid; private Bus mBus; private byte[] mReport; private byte[] mReport; private SparseArray<byte[]> mFeatureReports; private SparseArray<byte[]> mFeatureReports; private Map<ByteBuffer, byte[]> mOutputs; private Map<ByteBuffer, byte[]> mOutputs; Loading Loading @@ -71,6 +87,10 @@ public class Event { return mPid; return mPid; } } public int getBus() { return mBus.getValue(); } public byte[] getReport() { public byte[] getReport() { return mReport; return mReport; } } Loading @@ -94,6 +114,7 @@ public class Event { + ", descriptor=" + Arrays.toString(mDescriptor) + ", descriptor=" + Arrays.toString(mDescriptor) + ", vid=" + mVid + ", vid=" + mVid + ", pid=" + mPid + ", pid=" + mPid + ", bus=" + mBus + ", report=" + Arrays.toString(mReport) + ", report=" + Arrays.toString(mReport) + ", feature_reports=" + mFeatureReports.toString() + ", feature_reports=" + mFeatureReports.toString() + ", outputs=" + mOutputs.toString() + ", outputs=" + mOutputs.toString() Loading Loading @@ -144,6 +165,10 @@ public class Event { mEvent.mPid = pid; mEvent.mPid = pid; } } public void setBus(Bus bus) { mEvent.mBus = bus; } public void setDuration(int duration) { public void setDuration(int duration) { mEvent.mDuration = duration; mEvent.mDuration = duration; } } Loading Loading @@ -206,6 +231,9 @@ public class Event { case "pid": case "pid": eb.setPid(readInt()); eb.setPid(readInt()); break; break; case "bus": eb.setBus(readBus()); break; case "report": case "report": eb.setReport(readData()); eb.setReport(readData()); break; break; Loading Loading @@ -264,6 +292,11 @@ public class Event { return Integer.decode(val); return Integer.decode(val); } } private Bus readBus() throws IOException { String val = mReader.nextString(); return Bus.valueOf(val.toUpperCase()); } private SparseArray<byte[]> readFeatureReports() private SparseArray<byte[]> readFeatureReports() throws IllegalStateException, IOException { throws IllegalStateException, IOException { SparseArray<byte[]> featureReports = new SparseArray<>(); SparseArray<byte[]> featureReports = new SparseArray<>(); Loading cmds/hid/src/com/android/commands/hid/Hid.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -113,7 +113,7 @@ public class Hid { "Tried to send command \"" + e.getCommand() + "\" to an unregistered device!"); "Tried to send command \"" + e.getCommand() + "\" to an unregistered device!"); } } int id = e.getId(); int id = e.getId(); Device d = new Device(id, e.getName(), e.getVendorId(), e.getProductId(), Device d = new Device(id, e.getName(), e.getVendorId(), e.getProductId(), e.getBus(), e.getDescriptor(), e.getReport(), e.getFeatureReports(), e.getOutputs()); e.getDescriptor(), e.getReport(), e.getFeatureReports(), e.getOutputs()); mDevices.append(id, d); mDevices.append(id, d); } } Loading Loading
cmds/hid/jni/com_android_commands_hid_Device.cpp +13 −13 Original line number Original line Diff line number Diff line Loading @@ -129,7 +129,7 @@ JNIEnv* DeviceCallback::getJNIEnv() { } } std::unique_ptr<Device> Device::open(int32_t id, const char* name, int32_t vid, int32_t pid, std::unique_ptr<Device> Device::open(int32_t id, const char* name, int32_t vid, int32_t pid, const std::vector<uint8_t>& descriptor, uint16_t bus, const std::vector<uint8_t>& descriptor, std::unique_ptr<DeviceCallback> callback) { std::unique_ptr<DeviceCallback> callback) { size_t size = descriptor.size(); size_t size = descriptor.size(); if (size > HID_MAX_DESCRIPTOR_SIZE) { if (size > HID_MAX_DESCRIPTOR_SIZE) { Loading @@ -148,7 +148,7 @@ std::unique_ptr<Device> Device::open(int32_t id, const char* name, int32_t vid, strlcpy(reinterpret_cast<char*>(ev.u.create2.name), name, sizeof(ev.u.create2.name)); strlcpy(reinterpret_cast<char*>(ev.u.create2.name), name, sizeof(ev.u.create2.name)); memcpy(&ev.u.create2.rd_data, descriptor.data(), size * sizeof(ev.u.create2.rd_data[0])); 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.rd_size = size; ev.u.create2.bus = BUS_BLUETOOTH; ev.u.create2.bus = bus; ev.u.create2.vendor = vid; ev.u.create2.vendor = vid; ev.u.create2.product = pid; ev.u.create2.product = pid; ev.u.create2.version = 0; ev.u.create2.version = 0; Loading Loading @@ -293,8 +293,8 @@ std::vector<uint8_t> getData(JNIEnv* env, jbyteArray javaArray) { return data; return data; } } static jlong openDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jint id, jint vid, jint pid, static jlong openDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jint id, jint vid, jbyteArray rawDescriptor, jobject callback) { jint pid, jint bus, jbyteArray rawDescriptor, jobject callback) { ScopedUtfChars name(env, rawName); ScopedUtfChars name(env, rawName); if (name.c_str() == nullptr) { if (name.c_str() == nullptr) { return 0; return 0; Loading @@ -305,7 +305,7 @@ static jlong openDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jint i std::unique_ptr<uhid::DeviceCallback> cb(new uhid::DeviceCallback(env, callback)); std::unique_ptr<uhid::DeviceCallback> cb(new uhid::DeviceCallback(env, callback)); std::unique_ptr<uhid::Device> d = std::unique_ptr<uhid::Device> d = uhid::Device::open(id, reinterpret_cast<const char*>(name.c_str()), vid, pid, desc, uhid::Device::open(id, reinterpret_cast<const char*>(name.c_str()), vid, pid, bus, desc, std::move(cb)); std::move(cb)); return reinterpret_cast<jlong>(d.release()); return reinterpret_cast<jlong>(d.release()); } } Loading Loading @@ -340,7 +340,7 @@ static void closeDevice(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) { static JNINativeMethod sMethods[] = { static JNINativeMethod sMethods[] = { {"nativeOpenDevice", {"nativeOpenDevice", "(Ljava/lang/String;III[B" "(Ljava/lang/String;IIII[B" "Lcom/android/commands/hid/Device$DeviceCallback;)J", "Lcom/android/commands/hid/Device$DeviceCallback;)J", reinterpret_cast<void*>(openDevice)}, reinterpret_cast<void*>(openDevice)}, {"nativeSendReport", "(J[B)V", reinterpret_cast<void*>(sendReport)}, {"nativeSendReport", "(J[B)V", reinterpret_cast<void*>(sendReport)}, Loading
cmds/hid/jni/com_android_commands_hid_Device.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -43,7 +43,7 @@ private: class Device { class Device { public: public: static std::unique_ptr<Device> open(int32_t id, const char* name, int32_t vid, int32_t pid, static std::unique_ptr<Device> open(int32_t id, const char* name, int32_t vid, int32_t pid, const std::vector<uint8_t>& descriptor, uint16_t bus, const std::vector<uint8_t>& descriptor, std::unique_ptr<DeviceCallback> callback); std::unique_ptr<DeviceCallback> callback); ~Device(); ~Device(); Loading
cmds/hid/src/com/android/commands/hid/Device.java +4 −3 Original line number Original line Diff line number Diff line Loading @@ -52,13 +52,13 @@ public class Device { System.loadLibrary("hidcommand_jni"); System.loadLibrary("hidcommand_jni"); } } private static native long nativeOpenDevice(String name, int id, int vid, int pid, private static native long nativeOpenDevice(String name, int id, int vid, int pid, int bus, byte[] descriptor, DeviceCallback callback); byte[] descriptor, DeviceCallback callback); private static native void nativeSendReport(long ptr, byte[] data); private static native void nativeSendReport(long ptr, byte[] data); private static native void nativeSendGetFeatureReportReply(long ptr, int id, byte[] data); private static native void nativeSendGetFeatureReportReply(long ptr, int id, byte[] data); private static native void nativeCloseDevice(long ptr); private static native void nativeCloseDevice(long ptr); public Device(int id, String name, int vid, int pid, byte[] descriptor, public Device(int id, String name, int vid, int pid, int bus, byte[] descriptor, byte[] report, SparseArray<byte[]> featureReports, Map<ByteBuffer, byte[]> outputs) { byte[] report, SparseArray<byte[]> featureReports, Map<ByteBuffer, byte[]> outputs) { mId = id; mId = id; mThread = new HandlerThread("HidDeviceHandler"); mThread = new HandlerThread("HidDeviceHandler"); Loading @@ -70,6 +70,7 @@ public class Device { args.argi1 = id; args.argi1 = id; args.argi2 = vid; args.argi2 = vid; args.argi3 = pid; args.argi3 = pid; args.argi4 = bus; if (name != null) { if (name != null) { args.arg1 = name; args.arg1 = name; } else { } else { Loading Loading @@ -115,7 +116,7 @@ public class Device { case MSG_OPEN_DEVICE: case MSG_OPEN_DEVICE: SomeArgs args = (SomeArgs) msg.obj; SomeArgs args = (SomeArgs) msg.obj; mPtr = nativeOpenDevice((String) args.arg1, args.argi1, args.argi2, args.argi3, mPtr = nativeOpenDevice((String) args.arg1, args.argi1, args.argi2, args.argi3, (byte[]) args.arg2, new DeviceCallback()); args.argi4, (byte[]) args.arg2, new DeviceCallback()); pauseEvents(); pauseEvents(); break; break; case MSG_SEND_REPORT: case MSG_SEND_REPORT: Loading
cmds/hid/src/com/android/commands/hid/Event.java +33 −0 Original line number Original line Diff line number Diff line Loading @@ -36,12 +36,28 @@ public class Event { public static final String COMMAND_DELAY = "delay"; public static final String COMMAND_DELAY = "delay"; public static final String COMMAND_REPORT = "report"; public static final String COMMAND_REPORT = "report"; // These constants come from "include/uapi/linux/input.h" in the kernel enum Bus { USB(0x03), BLUETOOTH(0x05); Bus(int value) { mValue = value; } int getValue() { return mValue; } private int mValue; } private int mId; private int mId; private String mCommand; private String mCommand; private String mName; private String mName; private byte[] mDescriptor; private byte[] mDescriptor; private int mVid; private int mVid; private int mPid; private int mPid; private Bus mBus; private byte[] mReport; private byte[] mReport; private SparseArray<byte[]> mFeatureReports; private SparseArray<byte[]> mFeatureReports; private Map<ByteBuffer, byte[]> mOutputs; private Map<ByteBuffer, byte[]> mOutputs; Loading Loading @@ -71,6 +87,10 @@ public class Event { return mPid; return mPid; } } public int getBus() { return mBus.getValue(); } public byte[] getReport() { public byte[] getReport() { return mReport; return mReport; } } Loading @@ -94,6 +114,7 @@ public class Event { + ", descriptor=" + Arrays.toString(mDescriptor) + ", descriptor=" + Arrays.toString(mDescriptor) + ", vid=" + mVid + ", vid=" + mVid + ", pid=" + mPid + ", pid=" + mPid + ", bus=" + mBus + ", report=" + Arrays.toString(mReport) + ", report=" + Arrays.toString(mReport) + ", feature_reports=" + mFeatureReports.toString() + ", feature_reports=" + mFeatureReports.toString() + ", outputs=" + mOutputs.toString() + ", outputs=" + mOutputs.toString() Loading Loading @@ -144,6 +165,10 @@ public class Event { mEvent.mPid = pid; mEvent.mPid = pid; } } public void setBus(Bus bus) { mEvent.mBus = bus; } public void setDuration(int duration) { public void setDuration(int duration) { mEvent.mDuration = duration; mEvent.mDuration = duration; } } Loading Loading @@ -206,6 +231,9 @@ public class Event { case "pid": case "pid": eb.setPid(readInt()); eb.setPid(readInt()); break; break; case "bus": eb.setBus(readBus()); break; case "report": case "report": eb.setReport(readData()); eb.setReport(readData()); break; break; Loading Loading @@ -264,6 +292,11 @@ public class Event { return Integer.decode(val); return Integer.decode(val); } } private Bus readBus() throws IOException { String val = mReader.nextString(); return Bus.valueOf(val.toUpperCase()); } private SparseArray<byte[]> readFeatureReports() private SparseArray<byte[]> readFeatureReports() throws IllegalStateException, IOException { throws IllegalStateException, IOException { SparseArray<byte[]> featureReports = new SparseArray<>(); SparseArray<byte[]> featureReports = new SparseArray<>(); Loading
cmds/hid/src/com/android/commands/hid/Hid.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -113,7 +113,7 @@ public class Hid { "Tried to send command \"" + e.getCommand() + "\" to an unregistered device!"); "Tried to send command \"" + e.getCommand() + "\" to an unregistered device!"); } } int id = e.getId(); int id = e.getId(); Device d = new Device(id, e.getName(), e.getVendorId(), e.getProductId(), Device d = new Device(id, e.getName(), e.getVendorId(), e.getProductId(), e.getBus(), e.getDescriptor(), e.getReport(), e.getFeatureReports(), e.getOutputs()); e.getDescriptor(), e.getReport(), e.getFeatureReports(), e.getOutputs()); mDevices.append(id, d); mDevices.append(id, d); } } Loading