mirror of
https://github.com/mik3y/usb-serial-for-android
synced 2025-06-07 07:56:20 +00:00
handle uncaught NPE causing App termination in prolific driver controlline background thread
This commit is contained in:
parent
28506a9bf9
commit
9bc3834eff
@ -122,7 +122,7 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||||||
private volatile Thread mReadStatusThread = null;
|
private volatile Thread mReadStatusThread = null;
|
||||||
private final Object mReadStatusThreadLock = new Object();
|
private final Object mReadStatusThreadLock = new Object();
|
||||||
private boolean mStopReadStatusThread = false;
|
private boolean mStopReadStatusThread = false;
|
||||||
private IOException mReadStatusException = null;
|
private Exception mReadStatusException = null;
|
||||||
|
|
||||||
|
|
||||||
public ProlificSerialPort(UsbDevice device, int portNumber) {
|
public ProlificSerialPort(UsbDevice device, int portNumber) {
|
||||||
@ -201,8 +201,8 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||||||
|
|
||||||
private void readStatusThreadFunction() {
|
private void readStatusThreadFunction() {
|
||||||
try {
|
try {
|
||||||
|
byte[] buffer = new byte[STATUS_BUFFER_SIZE];
|
||||||
while (!mStopReadStatusThread) {
|
while (!mStopReadStatusThread) {
|
||||||
byte[] buffer = new byte[STATUS_BUFFER_SIZE];
|
|
||||||
long endTime = MonotonicClock.millis() + 500;
|
long endTime = MonotonicClock.millis() + 500;
|
||||||
int readBytesCount = mConnection.bulkTransfer(mInterruptEndpoint, buffer, STATUS_BUFFER_SIZE, 500);
|
int readBytesCount = mConnection.bulkTransfer(mInterruptEndpoint, buffer, STATUS_BUFFER_SIZE, 500);
|
||||||
if(readBytesCount == -1)
|
if(readBytesCount == -1)
|
||||||
@ -217,8 +217,9 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
mReadStatusException = e;
|
if (isOpen())
|
||||||
|
mReadStatusException = e;
|
||||||
}
|
}
|
||||||
//Log.d(TAG, "end control line status thread " + mStopReadStatusThread + " " + (mReadStatusException == null ? "-" : mReadStatusException.getMessage()));
|
//Log.d(TAG, "end control line status thread " + mStopReadStatusThread + " " + (mReadStatusException == null ? "-" : mReadStatusException.getMessage()));
|
||||||
}
|
}
|
||||||
@ -249,8 +250,8 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* throw and clear an exception which occured in the status read thread */
|
/* throw and clear an exception which occurred in the status read thread */
|
||||||
IOException readStatusException = mReadStatusException;
|
Exception readStatusException = mReadStatusException;
|
||||||
if (mReadStatusException != null) {
|
if (mReadStatusException != null) {
|
||||||
mReadStatusException = null;
|
mReadStatusException = null;
|
||||||
throw new IOException(readStatusException);
|
throw new IOException(readStatusException);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user