mirror of
https://github.com/mik3y/usb-serial-for-android.git
synced 2026-08-12 17:03:06 +00:00
iomanager with configurable threadpriority and higher default to prevent data loss
This commit is contained in:
@@ -14,6 +14,7 @@ import android.content.Context;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.os.Process;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.util.Log;
|
||||
@@ -1025,6 +1026,8 @@ public class DeviceTest {
|
||||
usb.ioManager = new SerialInputOutputManager(usb.serialPort, usb);
|
||||
assertEquals(usb, usb.ioManager.getListener());
|
||||
|
||||
usb.ioManager.setThreadPriority(Process.THREAD_PRIORITY_AUDIO);
|
||||
|
||||
assertEquals(0, usb.ioManager.getReadTimeout());
|
||||
usb.ioManager.setReadTimeout(10);
|
||||
assertEquals(10, usb.ioManager.getReadTimeout());
|
||||
@@ -1043,6 +1046,10 @@ public class DeviceTest {
|
||||
usb.setParameters(19200, 8, 1, UsbSerialPort.PARITY_NONE);
|
||||
telnet.setParameters(19200, 8, 1, UsbSerialPort.PARITY_NONE);
|
||||
usb.waitForIoManagerStarted();
|
||||
try {
|
||||
usb.ioManager.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
|
||||
fail("setThreadPriority IllegalStateException expected");
|
||||
} catch (IllegalStateException ignored) {}
|
||||
try {
|
||||
usb.ioManager.setReadTimeout(20);
|
||||
fail("setReadTimeout IllegalStateException expected");
|
||||
|
||||
+1
-9
@@ -35,7 +35,6 @@ public class UsbWrapper implements SerialInputOutputManager.Listener {
|
||||
|
||||
private final static int USB_READ_WAIT = 500;
|
||||
private final static int USB_WRITE_WAIT = 500;
|
||||
private final static Integer SERIAL_INPUT_OUTPUT_MANAGER_THREAD_PRIORITY = Process.THREAD_PRIORITY_URGENT_AUDIO;
|
||||
private static final String TAG = UsbWrapper.class.getSimpleName();
|
||||
|
||||
public enum OpenCloseFlags { NO_IOMANAGER_THREAD, NO_CONTROL_LINE_INIT, NO_DEVICE_CONNECTION };
|
||||
@@ -157,14 +156,7 @@ public class UsbWrapper implements SerialInputOutputManager.Listener {
|
||||
serialPort.setRTS(true);
|
||||
}
|
||||
if(!flags.contains(OpenCloseFlags.NO_IOMANAGER_THREAD)) {
|
||||
ioManager = new SerialInputOutputManager(serialPort, this) {
|
||||
@Override
|
||||
public void run() {
|
||||
if (SERIAL_INPUT_OUTPUT_MANAGER_THREAD_PRIORITY != null)
|
||||
Process.setThreadPriority(SERIAL_INPUT_OUTPUT_MANAGER_THREAD_PRIORITY);
|
||||
super.run();
|
||||
}
|
||||
};
|
||||
ioManager = new SerialInputOutputManager(serialPort, this);
|
||||
ioManager.setReadTimeout(ioManagerTimeout);
|
||||
ioManager.setWriteTimeout(ioManagerTimeout);
|
||||
Executors.newSingleThreadExecutor().submit(ioManager);
|
||||
|
||||
Reference in New Issue
Block a user