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/java/android/hardware | |
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/java/android/hardware')
-rw-r--r-- | core/java/android/hardware/usb/UsbRequest.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/core/java/android/hardware/usb/UsbRequest.java b/core/java/android/hardware/usb/UsbRequest.java index 2252248..3646715 100644 --- a/core/java/android/hardware/usb/UsbRequest.java +++ b/core/java/android/hardware/usb/UsbRequest.java @@ -152,10 +152,14 @@ public class UsbRequest { /* package */ void dequeue() { boolean out = (mEndpoint.getDirection() == UsbConstants.USB_DIR_OUT); + int bytesRead; if (mBuffer.isDirect()) { - native_dequeue_direct(); + bytesRead = native_dequeue_direct(); } else { - native_dequeue_array(mBuffer.array(), mLength, out); + bytesRead = native_dequeue_array(mBuffer.array(), mLength, out); + } + if (bytesRead >= 0) { + mBuffer.position(Math.min(bytesRead, mLength)); } mBuffer = null; mLength = 0; @@ -174,8 +178,8 @@ public class UsbRequest { int ep_attributes, int ep_max_packet_size, int ep_interval); private native void native_close(); private native boolean native_queue_array(byte[] buffer, int length, boolean out); - private native void native_dequeue_array(byte[] buffer, int length, boolean out); + private native int native_dequeue_array(byte[] buffer, int length, boolean out); private native boolean native_queue_direct(ByteBuffer buffer, int length, boolean out); - private native void native_dequeue_direct(); + private native int native_dequeue_direct(); private native boolean native_cancel(); } |