package com.ucar.connect.aoa;

import a.a.a.b;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.system.OsConstants;

public class UsbNative {

    /* renamed from: a  reason: collision with root package name */
    private static final String f221a = "UsbNative";
    private static final int b = 16384;
    private static int c = -1;

    static {
        System.loadLibrary("usbio");
    }

    private static int a(int i) {
        int i2 = c;
        if (i2 == -1) {
            return -1;
        }
        if (i2 >= 28 || i <= 16384) {
            return i;
        }
        return 16384;
    }

    public static int a(UsbDeviceConnection usbDeviceConnection, UsbEndpoint usbEndpoint, byte[] bArr, int i, int i2, long j) {
        int a2 = a(i2);
        if (usbDeviceConnection == null || bArr == null || usbEndpoint == null || a2 < 0 || i < 0 || i + a2 > bArr.length) {
            b.b(f221a, "invalid parameter for bulkRead");
            return -OsConstants.EINVAL;
        } else if (usbEndpoint.getDirection() == 128) {
            return nativeBulkRead(usbDeviceConnection.getFileDescriptor(), usbEndpoint.getAddress(), bArr, i, a2, j);
        } else {
            b.b(f221a, "wrong direction of usb endpoint for bulkRead");
            return -OsConstants.EINVAL;
        }
    }

    public static int b(UsbDeviceConnection usbDeviceConnection, UsbEndpoint usbEndpoint, byte[] bArr, int i, int i2, long j) {
        int a2 = a(i2);
        if (usbDeviceConnection == null || bArr == null || usbEndpoint == null || a2 < 0 || i < 0 || i + a2 > bArr.length) {
            b.b(f221a, "invalid parameter for bulkWrite");
            return -OsConstants.EINVAL;
        } else if (usbEndpoint.getDirection() == 0) {
            return nativeBulkWrite(usbDeviceConnection.getFileDescriptor(), usbEndpoint.getAddress(), bArr, i, a2, j);
        } else {
            b.b(f221a, "wrong direction of usb endpoint for bulkWrite");
            return -OsConstants.EINVAL;
        }
    }

    public static void b(int i) {
        c = i;
    }

    private static native int nativeBulkRead(int i, int i2, byte[] bArr, int i3, int i4, long j);

    private static native int nativeBulkWrite(int i, int i2, byte[] bArr, int i3, int i4, long j);
}
