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 final Object mReadStatusThreadLock = new Object();
|
||||
private boolean mStopReadStatusThread = false;
|
||||
private IOException mReadStatusException = null;
|
||||
private Exception mReadStatusException = null;
|
||||
|
||||
|
||||
public ProlificSerialPort(UsbDevice device, int portNumber) {
|
||||
@ -201,8 +201,8 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
||||
|
||||
private void readStatusThreadFunction() {
|
||||
try {
|
||||
while (!mStopReadStatusThread) {
|
||||
byte[] buffer = new byte[STATUS_BUFFER_SIZE];
|
||||
while (!mStopReadStatusThread) {
|
||||
long endTime = MonotonicClock.millis() + 500;
|
||||
int readBytesCount = mConnection.bulkTransfer(mInterruptEndpoint, buffer, STATUS_BUFFER_SIZE, 500);
|
||||
if(readBytesCount == -1)
|
||||
@ -217,7 +217,8 @@ public class ProlificSerialDriver implements UsbSerialDriver {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
if (isOpen())
|
||||
mReadStatusException = e;
|
||||
}
|
||||
//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 */
|
||||
IOException readStatusException = mReadStatusException;
|
||||
/* throw and clear an exception which occurred in the status read thread */
|
||||
Exception readStatusException = mReadStatusException;
|
||||
if (mReadStatusException != null) {
|
||||
mReadStatusException = null;
|
||||
throw new IOException(readStatusException);
|
||||
|
Loading…
x
Reference in New Issue
Block a user