10
10
import android .hardware .usb .UsbDeviceConnection ;
11
11
import android .hardware .usb .UsbEndpoint ;
12
12
import android .hardware .usb .UsbRequest ;
13
+ import android .os .Build ;
13
14
import android .util .Log ;
14
15
15
16
import com .hoho .android .usbserial .util .MonotonicClock ;
@@ -28,7 +29,7 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
28
29
public static boolean DEBUG = false ;
29
30
30
31
private static final String TAG = CommonUsbSerialPort .class .getSimpleName ();
31
- private static final int MAX_READ_SIZE = 16 * 1024 ; // = old bulkTransfer limit
32
+ private static final int MAX_READ_SIZE = 16 * 1024 ; // = old bulkTransfer limit prior to Android 9
32
33
33
34
protected final UsbDevice mDevice ;
34
35
protected final int mPortNumber ;
@@ -207,7 +208,7 @@ protected int read(final byte[] dest, int length, final int timeout, boolean tes
207
208
// /system/lib64/libandroid_runtime.so (android_hardware_UsbDeviceConnection_request_wait(_JNIEnv*, _jobject*, long)+84)
208
209
// data loss / crashes were observed with timeout up to 200 msec
209
210
long endTime = testConnection ? MonotonicClock .millis () + timeout : 0 ;
210
- int readMax = Math .min (length , MAX_READ_SIZE );
211
+ int readMax = ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . P ) ? length : Math .min (length , MAX_READ_SIZE );
211
212
nread = mConnection .bulkTransfer (mReadEndpoint , dest , readMax , timeout );
212
213
// Android error propagation is improvable:
213
214
// nread == -1 can be: timeout, connection lost, buffer to small, ???
0 commit comments