Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Unlimited Read Size for Android 9+ #609

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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