usb: Use Get/SetByteArrayRegion in controlTransfer
This change replaces GetPrimitiveArrayCritical/ReleasePrimitiveArrayCritical with GetByteArrayRegion/SetByteArrayRegion. This change is needed because the critical API variants are not appropriate for this context. See the JNI docs: "After calling GetPrimitiveArrayCritical, the native code should not run for an extended period of time before it calls ReleasePrimitiveArrayCritical." In controlTransfer, we call usb_device_control_transfer between GetPrimitiveArrayCritical/ReleasePrimitiveArrayCritical. usb_device_control_transfer is a blocking call so this can lead to GC hangs. Instead, we allocate a new buffer and then call GetByteArrayRegion/SetByteArrayRegion before/after usb_device_control_transfer, depending on the direction of the endpoint. This change is analogous to https://android-review.googlesource.com/c/platform/frameworks/base/+/3056082 which fixed the same problem in bulkTransfer. Test: I ran the USB Accessory Test - https://source.android.com/docs/compatibility/cts/verifier#testing-accessory-8 - both directions (this change on the DUT and this change on the companion device) Change-Id: I3f670121fc1c65f046376aa819d638edb446658a
Loading
Please register or sign in to comment