Merge "Added ability to set bus used for hid device tests"
This commit is contained in:
committed by
Android (Google) Code Review
commit
5a9b426ef3
@@ -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,
|
||||
const std::vector<uint8_t>& descriptor,
|
||||
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) {
|
||||
@@ -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));
|
||||
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_BLUETOOTH;
|
||||
ev.u.create2.bus = bus;
|
||||
ev.u.create2.vendor = vid;
|
||||
ev.u.create2.product = pid;
|
||||
ev.u.create2.version = 0;
|
||||
@@ -293,8 +293,8 @@ 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,
|
||||
jbyteArray rawDescriptor, jobject callback) {
|
||||
static jlong openDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jint id, jint vid,
|
||||
jint pid, jint bus, jbyteArray rawDescriptor, jobject callback) {
|
||||
ScopedUtfChars name(env, rawName);
|
||||
if (name.c_str() == nullptr) {
|
||||
return 0;
|
||||
@@ -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::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));
|
||||
return reinterpret_cast<jlong>(d.release());
|
||||
}
|
||||
@@ -339,14 +339,14 @@ static void closeDevice(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) {
|
||||
}
|
||||
|
||||
static JNINativeMethod sMethods[] = {
|
||||
{ "nativeOpenDevice",
|
||||
"(Ljava/lang/String;III[B"
|
||||
"Lcom/android/commands/hid/Device$DeviceCallback;)J",
|
||||
reinterpret_cast<void*>(openDevice) },
|
||||
{ "nativeSendReport", "(J[B)V", reinterpret_cast<void*>(sendReport) },
|
||||
{ "nativeSendGetFeatureReportReply", "(JI[B)V",
|
||||
reinterpret_cast<void*>(sendGetFeatureReportReply) },
|
||||
{ "nativeCloseDevice", "(J)V", reinterpret_cast<void*>(closeDevice) },
|
||||
{"nativeOpenDevice",
|
||||
"(Ljava/lang/String;IIII[B"
|
||||
"Lcom/android/commands/hid/Device$DeviceCallback;)J",
|
||||
reinterpret_cast<void*>(openDevice)},
|
||||
{"nativeSendReport", "(J[B)V", reinterpret_cast<void*>(sendReport)},
|
||||
{"nativeSendGetFeatureReportReply", "(JI[B)V",
|
||||
reinterpret_cast<void*>(sendGetFeatureReportReply)},
|
||||
{"nativeCloseDevice", "(J)V", reinterpret_cast<void*>(closeDevice)},
|
||||
};
|
||||
|
||||
int register_com_android_commands_hid_Device(JNIEnv* env) {
|
||||
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
class Device {
|
||||
public:
|
||||
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);
|
||||
|
||||
~Device();
|
||||
|
||||
@@ -52,13 +52,13 @@ public class Device {
|
||||
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);
|
||||
private static native void nativeSendReport(long ptr, byte[] data);
|
||||
private static native void nativeSendGetFeatureReportReply(long ptr, int id, byte[] data);
|
||||
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) {
|
||||
mId = id;
|
||||
mThread = new HandlerThread("HidDeviceHandler");
|
||||
@@ -70,6 +70,7 @@ public class Device {
|
||||
args.argi1 = id;
|
||||
args.argi2 = vid;
|
||||
args.argi3 = pid;
|
||||
args.argi4 = bus;
|
||||
if (name != null) {
|
||||
args.arg1 = name;
|
||||
} else {
|
||||
@@ -115,7 +116,7 @@ public class Device {
|
||||
case MSG_OPEN_DEVICE:
|
||||
SomeArgs args = (SomeArgs) msg.obj;
|
||||
mPtr = nativeOpenDevice((String) args.arg1, args.argi1, args.argi2, args.argi3,
|
||||
(byte[]) args.arg2, new DeviceCallback());
|
||||
args.argi4, (byte[]) args.arg2, new DeviceCallback());
|
||||
pauseEvents();
|
||||
break;
|
||||
case MSG_SEND_REPORT:
|
||||
|
||||
@@ -36,12 +36,28 @@ public class Event {
|
||||
public static final String COMMAND_DELAY = "delay";
|
||||
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 String mCommand;
|
||||
private String mName;
|
||||
private byte[] mDescriptor;
|
||||
private int mVid;
|
||||
private int mPid;
|
||||
private Bus mBus;
|
||||
private byte[] mReport;
|
||||
private SparseArray<byte[]> mFeatureReports;
|
||||
private Map<ByteBuffer, byte[]> mOutputs;
|
||||
@@ -71,6 +87,10 @@ public class Event {
|
||||
return mPid;
|
||||
}
|
||||
|
||||
public int getBus() {
|
||||
return mBus.getValue();
|
||||
}
|
||||
|
||||
public byte[] getReport() {
|
||||
return mReport;
|
||||
}
|
||||
@@ -94,6 +114,7 @@ public class Event {
|
||||
+ ", descriptor=" + Arrays.toString(mDescriptor)
|
||||
+ ", vid=" + mVid
|
||||
+ ", pid=" + mPid
|
||||
+ ", bus=" + mBus
|
||||
+ ", report=" + Arrays.toString(mReport)
|
||||
+ ", feature_reports=" + mFeatureReports.toString()
|
||||
+ ", outputs=" + mOutputs.toString()
|
||||
@@ -144,6 +165,10 @@ public class Event {
|
||||
mEvent.mPid = pid;
|
||||
}
|
||||
|
||||
public void setBus(Bus bus) {
|
||||
mEvent.mBus = bus;
|
||||
}
|
||||
|
||||
public void setDuration(int duration) {
|
||||
mEvent.mDuration = duration;
|
||||
}
|
||||
@@ -206,6 +231,9 @@ public class Event {
|
||||
case "pid":
|
||||
eb.setPid(readInt());
|
||||
break;
|
||||
case "bus":
|
||||
eb.setBus(readBus());
|
||||
break;
|
||||
case "report":
|
||||
eb.setReport(readData());
|
||||
break;
|
||||
@@ -264,6 +292,11 @@ public class Event {
|
||||
return Integer.decode(val);
|
||||
}
|
||||
|
||||
private Bus readBus() throws IOException {
|
||||
String val = mReader.nextString();
|
||||
return Bus.valueOf(val.toUpperCase());
|
||||
}
|
||||
|
||||
private SparseArray<byte[]> readFeatureReports()
|
||||
throws IllegalStateException, IOException {
|
||||
SparseArray<byte[]> featureReports = new SparseArray<>();
|
||||
|
||||
@@ -113,7 +113,7 @@ 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(),
|
||||
Device d = new Device(id, e.getName(), e.getVendorId(), e.getProductId(), e.getBus(),
|
||||
e.getDescriptor(), e.getReport(), e.getFeatureReports(), e.getOutputs());
|
||||
mDevices.append(id, d);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user