Skip to content

Commit

Permalink
Allow Unlimited Read Size for Android 9+ (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey authored Nov 9, 2024
1 parent 0b5950c commit 8584fe4
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbRequest;
import android.os.Build;
import android.util.Log;

import com.hoho.android.usbserial.util.MonotonicClock;
Expand All @@ -28,7 +29,7 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
public static boolean DEBUG = false;

private static final String TAG = CommonUsbSerialPort.class.getSimpleName();
private static final int MAX_READ_SIZE = 16 * 1024; // = old bulkTransfer limit
private static final int MAX_READ_SIZE = 16 * 1024; // = old bulkTransfer limit prior to Android 9

protected final UsbDevice mDevice;
protected final int mPortNumber;
Expand Down Expand Up @@ -207,7 +208,7 @@ protected int read(final byte[] dest, int length, final int timeout, boolean tes
// /system/lib64/libandroid_runtime.so (android_hardware_UsbDeviceConnection_request_wait(_JNIEnv*, _jobject*, long)+84)
// data loss / crashes were observed with timeout up to 200 msec
long endTime = testConnection ? MonotonicClock.millis() + timeout : 0;
int readMax = Math.min(length, MAX_READ_SIZE);
int readMax = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) ? length : Math.min(length, MAX_READ_SIZE);
nread = mConnection.bulkTransfer(mReadEndpoint, dest, readMax, timeout);
// Android error propagation is improvable:
// nread == -1 can be: timeout, connection lost, buffer to small, ???
Expand Down

0 comments on commit 8584fe4

Please sign in to comment.