diff options
author | mike wakerly <mikey@google.com> | 2012-08-09 15:28:10 -0700 |
---|---|---|
committer | mike wakerly <mikey@google.com> | 2012-08-09 15:28:10 -0700 |
commit | a3665ba95d806fcb6780d29d49bd0f1032e8bc86 (patch) | |
tree | 5d617d2800d07691b32fd76109c0e4b0653836ac /core/jni/android_hardware_UsbRequest.cpp | |
parent | 2c02933b13b426637808d3d4fd57aea1ff11011a (diff) | |
download | frameworks_base-a3665ba95d806fcb6780d29d49bd0f1032e8bc86.zip frameworks_base-a3665ba95d806fcb6780d29d49bd0f1032e8bc86.tar.gz frameworks_base-a3665ba95d806fcb6780d29d49bd0f1032e8bc86.tar.bz2 |
UsbRequest: set ByteBuffer.position() upon success.
Also clears allocated buffer before copying.
Closes http://b.android.com/28023
Bug: 5385026
Bug: 6766413
Change-Id: Icf2c1d45db4fb2a9bd1fcfdb29aa7308034faaf0
Diffstat (limited to 'core/jni/android_hardware_UsbRequest.cpp')
-rw-r--r-- | core/jni/android_hardware_UsbRequest.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/core/jni/android_hardware_UsbRequest.cpp b/core/jni/android_hardware_UsbRequest.cpp index 1398968..32d5135 100644 --- a/core/jni/android_hardware_UsbRequest.cpp +++ b/core/jni/android_hardware_UsbRequest.cpp @@ -90,6 +90,7 @@ android_hardware_UsbRequest_queue_array(JNIEnv *env, jobject thiz, request->buffer = malloc(length); if (!request->buffer) return false; + memset(request->buffer, 0, length); if (out) { // copy data from Java buffer to native buffer env->GetByteArrayRegion(buffer, 0, length, (jbyte *)request->buffer); @@ -113,14 +114,14 @@ android_hardware_UsbRequest_queue_array(JNIEnv *env, jobject thiz, } } -static void +static int android_hardware_UsbRequest_dequeue_array(JNIEnv *env, jobject thiz, jbyteArray buffer, jint length, jboolean out) { struct usb_request* request = get_request_from_object(env, thiz); if (!request) { ALOGE("request is closed in native_dequeue"); - return; + return -1; } if (buffer && length && request->buffer && !out) { @@ -129,7 +130,7 @@ android_hardware_UsbRequest_dequeue_array(JNIEnv *env, jobject thiz, } free(request->buffer); env->DeleteGlobalRef((jobject)request->client_data); - + return request->actual_length; } static jboolean @@ -163,16 +164,17 @@ android_hardware_UsbRequest_queue_direct(JNIEnv *env, jobject thiz, } } -static void +static int android_hardware_UsbRequest_dequeue_direct(JNIEnv *env, jobject thiz) { struct usb_request* request = get_request_from_object(env, thiz); if (!request) { ALOGE("request is closed in native_dequeue"); - return; + return -1; } // all we need to do is delete our global ref env->DeleteGlobalRef((jobject)request->client_data); + return request->actual_length; } static jboolean @@ -191,10 +193,10 @@ static JNINativeMethod method_table[] = { (void *)android_hardware_UsbRequest_init}, {"native_close", "()V", (void *)android_hardware_UsbRequest_close}, {"native_queue_array", "([BIZ)Z", (void *)android_hardware_UsbRequest_queue_array}, - {"native_dequeue_array", "([BIZ)V", (void *)android_hardware_UsbRequest_dequeue_array}, + {"native_dequeue_array", "([BIZ)I", (void *)android_hardware_UsbRequest_dequeue_array}, {"native_queue_direct", "(Ljava/nio/ByteBuffer;IZ)Z", (void *)android_hardware_UsbRequest_queue_direct}, - {"native_dequeue_direct", "()V", (void *)android_hardware_UsbRequest_dequeue_direct}, + {"native_dequeue_direct", "()I", (void *)android_hardware_UsbRequest_dequeue_direct}, {"native_cancel", "()Z", (void *)android_hardware_UsbRequest_cancel}, }; |