Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "UsbDeviceConnectionJNI" |
| 18 | |
| 19 | #include "utils/Log.h" |
| 20 | |
| 21 | #include "jni.h" |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 22 | #include <nativehelper/JNIHelp.h> |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 23 | #include "core_jni_helpers.h" |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 24 | |
| 25 | #include <usbhost/usbhost.h> |
| 26 | |
Philip P. Moltmann | 927fefe | 2016-10-18 12:57:34 -0700 | [diff] [blame] | 27 | #include <chrono> |
| 28 | |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/stat.h> |
| 32 | #include <fcntl.h> |
| 33 | |
| 34 | using namespace android; |
Philip P. Moltmann | 927fefe | 2016-10-18 12:57:34 -0700 | [diff] [blame] | 35 | using namespace std::chrono; |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 36 | |
Vitalii Tomkiv | d9804ef | 2016-10-21 14:03:48 -0700 | [diff] [blame] | 37 | static const int USB_CONTROL_READ_TIMEOUT_MS = 200; |
| 38 | |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 39 | static jfieldID field_context; |
| 40 | |
| 41 | struct usb_device* get_device_from_object(JNIEnv* env, jobject connection) |
| 42 | { |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 43 | return (struct usb_device*)env->GetLongField(connection, field_context); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static jboolean |
| 47 | android_hardware_UsbDeviceConnection_open(JNIEnv *env, jobject thiz, jstring deviceName, |
| 48 | jobject fileDescriptor) |
| 49 | { |
Elliott Hughes | a3804cf | 2011-04-11 16:50:19 -0700 | [diff] [blame] | 50 | int fd = jniGetFDFromFileDescriptor(env, fileDescriptor); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 51 | // duplicate the file descriptor, since ParcelFileDescriptor will eventually close its copy |
| 52 | fd = dup(fd); |
| 53 | if (fd < 0) |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 54 | return JNI_FALSE; |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 55 | |
| 56 | const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL); |
| 57 | struct usb_device* device = usb_device_new(deviceNameStr, fd); |
| 58 | if (device) { |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 59 | env->SetLongField(thiz, field_context, (jlong)device); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 60 | } else { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 61 | ALOGE("usb_device_open failed for %s", deviceNameStr); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 62 | close(fd); |
| 63 | } |
| 64 | |
| 65 | env->ReleaseStringUTFChars(deviceName, deviceNameStr); |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 66 | return (device != NULL) ? JNI_TRUE : JNI_FALSE; |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static void |
| 70 | android_hardware_UsbDeviceConnection_close(JNIEnv *env, jobject thiz) |
| 71 | { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 72 | ALOGD("close\n"); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 73 | struct usb_device* device = get_device_from_object(env, thiz); |
| 74 | if (device) { |
| 75 | usb_device_close(device); |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 76 | env->SetLongField(thiz, field_context, 0); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
| 80 | static jint |
| 81 | android_hardware_UsbDeviceConnection_get_fd(JNIEnv *env, jobject thiz) |
| 82 | { |
| 83 | struct usb_device* device = get_device_from_object(env, thiz); |
| 84 | if (!device) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 85 | ALOGE("device is closed in native_get_fd"); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 86 | return -1; |
| 87 | } |
| 88 | return usb_device_get_fd(device); |
| 89 | } |
| 90 | |
Mike Lockwood | a88b42d | 2011-05-19 11:52:40 -0400 | [diff] [blame] | 91 | static jbyteArray |
| 92 | android_hardware_UsbDeviceConnection_get_desc(JNIEnv *env, jobject thiz) |
| 93 | { |
| 94 | char buffer[16384]; |
| 95 | int fd = android_hardware_UsbDeviceConnection_get_fd(env, thiz); |
| 96 | if (fd < 0) return NULL; |
| 97 | lseek(fd, 0, SEEK_SET); |
| 98 | int length = read(fd, buffer, sizeof(buffer)); |
| 99 | if (length < 0) return NULL; |
| 100 | |
| 101 | jbyteArray ret = env->NewByteArray(length); |
| 102 | if (ret) { |
| 103 | jbyte* bytes = (jbyte*)env->GetPrimitiveArrayCritical(ret, 0); |
| 104 | if (bytes) { |
| 105 | memcpy(bytes, buffer, length); |
| 106 | env->ReleasePrimitiveArrayCritical(ret, bytes, 0); |
| 107 | } |
| 108 | } |
| 109 | return ret; |
| 110 | } |
| 111 | |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 112 | static jboolean |
| 113 | android_hardware_UsbDeviceConnection_claim_interface(JNIEnv *env, jobject thiz, |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 114 | jint interfaceID, jboolean force) |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 115 | { |
| 116 | struct usb_device* device = get_device_from_object(env, thiz); |
| 117 | if (!device) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 118 | ALOGE("device is closed in native_claim_interface"); |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 119 | return JNI_FALSE; |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | int ret = usb_device_claim_interface(device, interfaceID); |
| 123 | if (ret && force && errno == EBUSY) { |
| 124 | // disconnect kernel driver and try again |
| 125 | usb_device_connect_kernel_driver(device, interfaceID, false); |
| 126 | ret = usb_device_claim_interface(device, interfaceID); |
| 127 | } |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 128 | return (ret == 0) ? JNI_TRUE : JNI_FALSE; |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 129 | } |
| 130 | |
Mike Lockwood | 7531aa2 | 2014-01-13 10:31:01 -0800 | [diff] [blame] | 131 | static jboolean |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 132 | android_hardware_UsbDeviceConnection_release_interface(JNIEnv *env, jobject thiz, jint interfaceID) |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 133 | { |
| 134 | struct usb_device* device = get_device_from_object(env, thiz); |
| 135 | if (!device) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 136 | ALOGE("device is closed in native_release_interface"); |
Mike Lockwood | 7531aa2 | 2014-01-13 10:31:01 -0800 | [diff] [blame] | 137 | return JNI_FALSE; |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 138 | } |
| 139 | int ret = usb_device_release_interface(device, interfaceID); |
| 140 | if (ret == 0) { |
| 141 | // allow kernel to reconnect its driver |
| 142 | usb_device_connect_kernel_driver(device, interfaceID, true); |
| 143 | } |
Mike Lockwood | 7531aa2 | 2014-01-13 10:31:01 -0800 | [diff] [blame] | 144 | return (ret == 0) ? JNI_TRUE : JNI_FALSE; |
| 145 | } |
| 146 | |
| 147 | static jboolean |
| 148 | android_hardware_UsbDeviceConnection_set_interface(JNIEnv *env, jobject thiz, jint interfaceID, |
| 149 | jint alternateSetting) |
| 150 | { |
| 151 | struct usb_device* device = get_device_from_object(env, thiz); |
| 152 | if (!device) { |
| 153 | ALOGE("device is closed in native_set_interface"); |
| 154 | return JNI_FALSE; |
| 155 | } |
| 156 | int ret = usb_device_set_interface(device, interfaceID, alternateSetting); |
| 157 | return (ret == 0) ? JNI_TRUE : JNI_FALSE; |
| 158 | } |
| 159 | |
| 160 | static jboolean |
| 161 | android_hardware_UsbDeviceConnection_set_configuration(JNIEnv *env, jobject thiz, jint configurationID) |
| 162 | { |
| 163 | struct usb_device* device = get_device_from_object(env, thiz); |
| 164 | if (!device) { |
| 165 | ALOGE("device is closed in native_set_configuration"); |
| 166 | return JNI_FALSE; |
| 167 | } |
| 168 | int ret = usb_device_set_configuration(device, configurationID); |
| 169 | return (ret == 0) ? JNI_TRUE : JNI_FALSE; |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static jint |
| 173 | android_hardware_UsbDeviceConnection_control_request(JNIEnv *env, jobject thiz, |
| 174 | jint requestType, jint request, jint value, jint index, |
Jeff Brown | 6c81a93 | 2013-03-28 03:13:09 -0700 | [diff] [blame] | 175 | jbyteArray buffer, jint start, jint length, jint timeout) |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 176 | { |
| 177 | struct usb_device* device = get_device_from_object(env, thiz); |
| 178 | if (!device) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 179 | ALOGE("device is closed in native_control_request"); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 180 | return -1; |
| 181 | } |
| 182 | |
| 183 | jbyte* bufferBytes = NULL; |
| 184 | if (buffer) { |
Jeff Brown | 6c81a93 | 2013-03-28 03:13:09 -0700 | [diff] [blame] | 185 | bufferBytes = (jbyte*)env->GetPrimitiveArrayCritical(buffer, NULL); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | jint result = usb_device_control_transfer(device, requestType, request, |
Jeff Brown | 6c81a93 | 2013-03-28 03:13:09 -0700 | [diff] [blame] | 189 | value, index, bufferBytes + start, length, timeout); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 190 | |
Jeff Brown | 6c81a93 | 2013-03-28 03:13:09 -0700 | [diff] [blame] | 191 | if (bufferBytes) { |
| 192 | env->ReleasePrimitiveArrayCritical(buffer, bufferBytes, 0); |
| 193 | } |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 194 | |
| 195 | return result; |
| 196 | } |
| 197 | |
| 198 | static jint |
| 199 | android_hardware_UsbDeviceConnection_bulk_request(JNIEnv *env, jobject thiz, |
Jeff Brown | 6c81a93 | 2013-03-28 03:13:09 -0700 | [diff] [blame] | 200 | jint endpoint, jbyteArray buffer, jint start, jint length, jint timeout) |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 201 | { |
| 202 | struct usb_device* device = get_device_from_object(env, thiz); |
| 203 | if (!device) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 204 | ALOGE("device is closed in native_control_request"); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 205 | return -1; |
| 206 | } |
| 207 | |
| 208 | jbyte* bufferBytes = NULL; |
| 209 | if (buffer) { |
Jeff Brown | 6c81a93 | 2013-03-28 03:13:09 -0700 | [diff] [blame] | 210 | bufferBytes = (jbyte*)env->GetPrimitiveArrayCritical(buffer, NULL); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 211 | } |
| 212 | |
Jeff Brown | 6c81a93 | 2013-03-28 03:13:09 -0700 | [diff] [blame] | 213 | jint result = usb_device_bulk_transfer(device, endpoint, bufferBytes + start, length, timeout); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 214 | |
Jeff Brown | 6c81a93 | 2013-03-28 03:13:09 -0700 | [diff] [blame] | 215 | if (bufferBytes) { |
| 216 | env->ReleasePrimitiveArrayCritical(buffer, bufferBytes, 0); |
| 217 | } |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 218 | |
| 219 | return result; |
| 220 | } |
| 221 | |
| 222 | static jobject |
Philip P. Moltmann | 9b6dd2b | 2017-04-06 15:34:04 -0700 | [diff] [blame] | 223 | android_hardware_UsbDeviceConnection_request_wait(JNIEnv *env, jobject thiz, jlong timeoutMillis) |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 224 | { |
| 225 | struct usb_device* device = get_device_from_object(env, thiz); |
| 226 | if (!device) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 227 | ALOGE("device is closed in native_request_wait"); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 228 | return NULL; |
| 229 | } |
| 230 | |
Philip P. Moltmann | 927fefe | 2016-10-18 12:57:34 -0700 | [diff] [blame] | 231 | struct usb_request* request; |
| 232 | if (timeoutMillis == -1) { |
| 233 | request = usb_request_wait(device, -1); |
| 234 | } else { |
| 235 | steady_clock::time_point currentTime = steady_clock::now(); |
| 236 | steady_clock::time_point endTime = currentTime + std::chrono::milliseconds(timeoutMillis); |
| 237 | |
| 238 | // Poll the existence of a request via usb_request_wait until we get a result, an unexpected |
| 239 | // error or time out. As several threads can listen on the same fd, we might get wakeups |
| 240 | // without data. |
| 241 | while (1) { |
| 242 | request = usb_request_wait(device, duration_cast<std::chrono::milliseconds>(endTime |
| 243 | - currentTime).count()); |
| 244 | |
| 245 | int error = errno; |
Philip P. Moltmann | 9b6dd2b | 2017-04-06 15:34:04 -0700 | [diff] [blame] | 246 | if (request != NULL) { |
| 247 | break; |
| 248 | } |
| 249 | |
Philip P. Moltmann | 927fefe | 2016-10-18 12:57:34 -0700 | [diff] [blame] | 250 | currentTime = steady_clock::now(); |
Philip P. Moltmann | 9b6dd2b | 2017-04-06 15:34:04 -0700 | [diff] [blame] | 251 | if (currentTime >= endTime) { |
| 252 | jniThrowException(env, "java/util/concurrent/TimeoutException", ""); |
| 253 | break; |
| 254 | } |
| 255 | |
| 256 | if (error != EAGAIN) { |
Philip P. Moltmann | 927fefe | 2016-10-18 12:57:34 -0700 | [diff] [blame] | 257 | break; |
| 258 | } |
| 259 | }; |
| 260 | } |
| 261 | |
| 262 | if (request) { |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 263 | return (jobject)request->client_data; |
Philip P. Moltmann | 927fefe | 2016-10-18 12:57:34 -0700 | [diff] [blame] | 264 | } else { |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 265 | return NULL; |
Philip P. Moltmann | 927fefe | 2016-10-18 12:57:34 -0700 | [diff] [blame] | 266 | } |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static jstring |
| 270 | android_hardware_UsbDeviceConnection_get_serial(JNIEnv *env, jobject thiz) |
| 271 | { |
| 272 | struct usb_device* device = get_device_from_object(env, thiz); |
| 273 | if (!device) { |
Philip P. Moltmann | 674e8c3 | 2016-08-29 12:28:31 -0700 | [diff] [blame] | 274 | ALOGE("device is closed in native_get_serial"); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 275 | return NULL; |
| 276 | } |
Vitalii Tomkiv | d9804ef | 2016-10-21 14:03:48 -0700 | [diff] [blame] | 277 | char* serial = usb_device_get_serial(device, |
| 278 | USB_CONTROL_READ_TIMEOUT_MS); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 279 | if (!serial) |
| 280 | return NULL; |
| 281 | jstring result = env->NewStringUTF(serial); |
| 282 | free(serial); |
| 283 | return result; |
| 284 | } |
| 285 | |
Keun-young Park | badbbae | 2016-01-05 13:27:29 -0800 | [diff] [blame] | 286 | static jboolean |
| 287 | android_hardware_UsbDeviceConnection_reset_device(JNIEnv *env, jobject thiz) |
| 288 | { |
| 289 | struct usb_device* device = get_device_from_object(env, thiz); |
| 290 | if (!device) { |
| 291 | ALOGE("device is closed in native_reset_device"); |
| 292 | return JNI_FALSE; |
| 293 | } |
| 294 | int ret = usb_device_reset(device); |
| 295 | return (ret == 0) ? JNI_TRUE : JNI_FALSE; |
| 296 | } |
| 297 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 298 | static const JNINativeMethod method_table[] = { |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 299 | {"native_open", "(Ljava/lang/String;Ljava/io/FileDescriptor;)Z", |
| 300 | (void *)android_hardware_UsbDeviceConnection_open}, |
| 301 | {"native_close", "()V", (void *)android_hardware_UsbDeviceConnection_close}, |
| 302 | {"native_get_fd", "()I", (void *)android_hardware_UsbDeviceConnection_get_fd}, |
Mike Lockwood | a88b42d | 2011-05-19 11:52:40 -0400 | [diff] [blame] | 303 | {"native_get_desc", "()[B", (void *)android_hardware_UsbDeviceConnection_get_desc}, |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 304 | {"native_claim_interface", "(IZ)Z",(void *)android_hardware_UsbDeviceConnection_claim_interface}, |
| 305 | {"native_release_interface","(I)Z", (void *)android_hardware_UsbDeviceConnection_release_interface}, |
Mike Lockwood | 7531aa2 | 2014-01-13 10:31:01 -0800 | [diff] [blame] | 306 | {"native_set_interface","(II)Z", (void *)android_hardware_UsbDeviceConnection_set_interface}, |
| 307 | {"native_set_configuration","(I)Z", (void *)android_hardware_UsbDeviceConnection_set_configuration}, |
Jeff Brown | 6c81a93 | 2013-03-28 03:13:09 -0700 | [diff] [blame] | 308 | {"native_control_request", "(IIII[BIII)I", |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 309 | (void *)android_hardware_UsbDeviceConnection_control_request}, |
Jeff Brown | 6c81a93 | 2013-03-28 03:13:09 -0700 | [diff] [blame] | 310 | {"native_bulk_request", "(I[BIII)I", |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 311 | (void *)android_hardware_UsbDeviceConnection_bulk_request}, |
Philip P. Moltmann | 9b6dd2b | 2017-04-06 15:34:04 -0700 | [diff] [blame] | 312 | {"native_request_wait", "(J)Landroid/hardware/usb/UsbRequest;", |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 313 | (void *)android_hardware_UsbDeviceConnection_request_wait}, |
| 314 | { "native_get_serial", "()Ljava/lang/String;", |
| 315 | (void*)android_hardware_UsbDeviceConnection_get_serial }, |
Keun-young Park | badbbae | 2016-01-05 13:27:29 -0800 | [diff] [blame] | 316 | {"native_reset_device","()Z", (void *)android_hardware_UsbDeviceConnection_reset_device}, |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | int register_android_hardware_UsbDeviceConnection(JNIEnv *env) |
| 320 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 321 | jclass clazz = FindClassOrDie(env, "android/hardware/usb/UsbDeviceConnection"); |
| 322 | field_context = GetFieldIDOrDie(env, clazz, "mNativeContext", "J"); |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 323 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 324 | return RegisterMethodsOrDie(env, "android/hardware/usb/UsbDeviceConnection", |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 325 | method_table, NELEM(method_table)); |
| 326 | } |