// Path: usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/util/MonotonicClock.java
// public final class MonotonicClock {
// 
//     private static final long NS_PER_MS = 1_000_000;
// 
//     private MonotonicClock() {
//     }
// 
//     public static long millis() {
//         return System.nanoTime() / NS_PER_MS;
//     }
// 
// }


import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.util.Log;
import com.hoho.android.usbserial.util.MonotonicClock;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
                throw new IOException("Init RTS,DTR failed: result=" + result);
            }

            // mDevice.getVersion() would require API 23
            byte[] rawDescriptors = connection.getRawDescriptors();
            if(rawDescriptors == null || rawDescriptors.length < 14) {
                throw new IOException("Could not get device descriptors");
            }
            int deviceType = rawDescriptors[13];
            baudRateWithPort = deviceType == 7 || deviceType == 8 || deviceType == 9 // ...H devices
                    || mDevice.getInterfaceCount() > 1; // FT2232C
        }

        @Override
        protected void closeInt() {
            try {
                mConnection.releaseInterface(mDevice.getInterface(mPortNumber));
            } catch(Exception ignored) {}
        }

        @Override
        public int read(final byte[] dest, final int timeout) throws IOException {
            if(dest.length <= READ_HEADER_LENGTH) {
                throw new IllegalArgumentException("Read buffer to small");
                // could allocate larger buffer, including space for 2 header bytes, but this would
                // result in buffers not being 64 byte aligned any more, causing data loss at continuous
                // data transfer at high baud rates when buffers are fully filled.
            }
            int nread;
            if (timeout != 0) {
// Path: usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/util/MonotonicClock.java
// public final class MonotonicClock {
// 
//     private static final long NS_PER_MS = 1_000_000;
// 
//     private MonotonicClock() {
//     }
// 
//     public static long millis() {
//         return System.nanoTime() / NS_PER_MS;
//     }
// 
// }


// Path: usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/driver/FtdiSerialDriver.java
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.util.Log;
import com.hoho.android.usbserial.util.MonotonicClock;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

                throw new IOException("Init RTS,DTR failed: result=" + result);
            }

            // mDevice.getVersion() would require API 23
            byte[] rawDescriptors = connection.getRawDescriptors();
            if(rawDescriptors == null || rawDescriptors.length < 14) {
                throw new IOException("Could not get device descriptors");
            }
            int deviceType = rawDescriptors[13];
            baudRateWithPort = deviceType == 7 || deviceType == 8 || deviceType == 9 // ...H devices
                    || mDevice.getInterfaceCount() > 1; // FT2232C
        }

        @Override
        protected void closeInt() {
            try {
                mConnection.releaseInterface(mDevice.getInterface(mPortNumber));
            } catch(Exception ignored) {}
        }

        @Override
        public int read(final byte[] dest, final int timeout) throws IOException {
            if(dest.length <= READ_HEADER_LENGTH) {
                throw new IllegalArgumentException("Read buffer to small");
                // could allocate larger buffer, including space for 2 header bytes, but this would
                // result in buffers not being 64 byte aligned any more, causing data loss at continuous
                // data transfer at high baud rates when buffers are fully filled.
            }
            int nread;
            if (timeout != 0) {
                long endTime = MonotonicClock.millis() + timeout;