1 diff -urp libusb-1.0.9.orig/libusb/io.c libusb-1.0.9/libusb/io.c
2 --- libusb-1.0.9.orig/libusb/io.c 2013-08-28 14:33:15.000000000 +0200
3 +++ libusb-1.0.9/libusb/io.c 2013-08-28 14:31:25.000000000 +0200
8 +#ifndef TIMESPEC_TO_TIMEVAL
9 +#define TIMESPEC_TO_TIMEVAL(tv, ts) \
11 + (tv)->tv_sec = (ts)->tv_sec; \
12 + (tv)->tv_usec = (ts)->tv_nsec / 1000; \
17 * \page io Synchronous and asynchronous device I/O
19 diff -urp libusbx-1.0.17.orig/libusb/os/linux_usbfs.c libusbx-1.0.17/libusb/os/linux_usbfs.c
20 --- libusbx-1.0.17.orig/libusb/os/linux_usbfs.c 2014-07-05 23:14:45.487803220 +0200
21 +++ libusbx-1.0.17/libusb/os/linux_usbfs.c 2014-07-06 16:42:17.013481236 +0200
23 #include <sys/types.h>
24 #include <sys/utsname.h>
32 #include "linux_usbfs.h"
35 +static JavaVM *g_jvm = NULL;
36 +static jclass usb_helper_class;
37 +static jmethodID usb_helper_open_mid;
38 +static int usb_helper_open(const char *pathname, int flags);
42 * opening a usbfs node causes the device to be resumed, so we attempt to
43 * avoid this during enumeration.
45 snprintf(path, PATH_MAX, "%s/%03d/%03d",
46 usbfs_path, dev->bus_number, dev->device_address);
50 + fd = usb_helper_open(path, mode);
53 fd = open(path, mode);
55 return fd; /* Success */
56 @@ -2603,3 +2618,79 @@
57 .transfer_priv_size = sizeof(struct linux_transfer_priv),
58 .add_iso_packet_size = 0,
62 +jint JNI_OnLoad(JavaVM *vm, void *reserved)
66 + if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_6) != JNI_OK) {
70 + jclass helper = (*env)->FindClass(env, "org/sigrok/androidutils/UsbHelper");
74 + usb_helper_class = (jclass)(*env)->NewGlobalRef(env, helper);
76 + usb_helper_open_mid = (*env)->GetStaticMethodID(env, helper, "open",
77 + "(Ljava/lang/String;I)I");
78 + (*env)->DeleteLocalRef(env, helper);
81 + if ((*env)->ExceptionCheck(env)) {
82 + (*env)->ExceptionClear(env);
87 + return JNI_VERSION_1_6;
90 +void JNI_OnUnload(JavaVM *vm, void *reserved)
93 + if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_6) != JNI_OK) {
97 + jclass helper = usb_helper_class;
98 + usb_helper_class = NULL;
100 + (*env)->DeleteGlobalRef(env, helper);
104 +static int usb_helper_open(const char *pathname, int flags)
111 + if (g_jvm == NULL) {
114 + st = (*g_jvm)->GetEnv(g_jvm, (void **)&env, JNI_VERSION_1_6);
116 + if (st == JNI_EDETACHED) {
117 + st = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
121 + if (st != JNI_OK) {
125 + jstring string = (*env)->NewStringUTF(env, pathname);
126 + res = (*env)->CallStaticIntMethod(env, usb_helper_class, usb_helper_open_mid, string, (jint)flags);
127 + (*env)->DeleteLocalRef(env, string);
130 + (*g_jvm)->DetachCurrentThread(g_jvm);