diff options
author | Mike Lockwood <lockwood@android.com> | 2011-05-19 10:01:53 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-05-19 10:01:53 -0700 |
commit | ae448e2c90cae096efea53c1c93a70e7b5ca2db7 (patch) | |
tree | 9eb652a45fcaa84fa06fa2f5a880e95226112a2c /core/jni | |
parent | d466a4631f3e4f482dd658f42c277d6ad281a9d1 (diff) | |
parent | a88b42d569a91290477d8f5731a2ee43931271da (diff) | |
download | frameworks_base-ae448e2c90cae096efea53c1c93a70e7b5ca2db7.zip frameworks_base-ae448e2c90cae096efea53c1c93a70e7b5ca2db7.tar.gz frameworks_base-ae448e2c90cae096efea53c1c93a70e7b5ca2db7.tar.bz2 |
am a88b42d5: USB: Add method to access raw USB device descriptors
* commit 'a88b42d569a91290477d8f5731a2ee43931271da':
USB: Add method to access raw USB device descriptors
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android_hardware_UsbDeviceConnection.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/core/jni/android_hardware_UsbDeviceConnection.cpp b/core/jni/android_hardware_UsbDeviceConnection.cpp index ec36a38..b5d6b91 100644 --- a/core/jni/android_hardware_UsbDeviceConnection.cpp +++ b/core/jni/android_hardware_UsbDeviceConnection.cpp @@ -83,6 +83,27 @@ android_hardware_UsbDeviceConnection_get_fd(JNIEnv *env, jobject thiz) return usb_device_get_fd(device); } +static jbyteArray +android_hardware_UsbDeviceConnection_get_desc(JNIEnv *env, jobject thiz) +{ + char buffer[16384]; + int fd = android_hardware_UsbDeviceConnection_get_fd(env, thiz); + if (fd < 0) return NULL; + lseek(fd, 0, SEEK_SET); + int length = read(fd, buffer, sizeof(buffer)); + if (length < 0) return NULL; + + jbyteArray ret = env->NewByteArray(length); + if (ret) { + jbyte* bytes = (jbyte*)env->GetPrimitiveArrayCritical(ret, 0); + if (bytes) { + memcpy(bytes, buffer, length); + env->ReleasePrimitiveArrayCritical(ret, bytes, 0); + } + } + return ret; +} + static jboolean android_hardware_UsbDeviceConnection_claim_interface(JNIEnv *env, jobject thiz, int interfaceID, jboolean force) @@ -211,6 +232,7 @@ static JNINativeMethod method_table[] = { (void *)android_hardware_UsbDeviceConnection_open}, {"native_close", "()V", (void *)android_hardware_UsbDeviceConnection_close}, {"native_get_fd", "()I", (void *)android_hardware_UsbDeviceConnection_get_fd}, + {"native_get_desc", "()[B", (void *)android_hardware_UsbDeviceConnection_get_desc}, {"native_claim_interface", "(IZ)Z",(void *)android_hardware_UsbDeviceConnection_claim_interface}, {"native_release_interface","(I)Z", (void *)android_hardware_UsbDeviceConnection_release_interface}, {"native_control_request", "(IIII[BII)I", |