Example usage for android.hardware.usb UsbInterface getInterfaceClass

List of usage examples for android.hardware.usb UsbInterface getInterfaceClass

Introduction

In this page you can find the example usage for android.hardware.usb UsbInterface getInterfaceClass.

Prototype

public int getInterfaceClass() 

Source Link

Document

Returns the interface's class field.

Usage

From source file:org.ros.android.android_acm_serial.AcmDevice.java

/**
 * Goes through the given UsbInterface's endpoints and finds the incoming
 * and outgoing bulk transfer endpoints.
 * @return Array with incoming (first) and outgoing (second) USB endpoints
 * @return <code>null</code>  in case either of the endpoints is not found
 *///from   w w w  . jav a  2  s .  com
private AcmUsbEndpoints getAcmEndpoints(UsbInterface usbInterface) {
    UsbEndpoint outgoingEndpoint = null;
    UsbEndpoint incomingEndpoint = null;
    for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
        UsbEndpoint endpoint = usbInterface.getEndpoint(i);
        log.info("Interface: " + i + "/" + "Class: " + usbInterface.getInterfaceClass());
        if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA) {
            if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
                log.info("Endpoint " + i + "/" + usbInterface.getEndpointCount() + ": " + endpoint + ". Type = "
                        + endpoint.getType());
                outgoingEndpoint = endpoint;
            } else if (endpoint.getDirection() == UsbConstants.USB_DIR_IN) {
                log.info("Endpoint " + i + "/" + usbInterface.getEndpointCount() + ": " + endpoint + ". Type = "
                        + endpoint.getType());
                incomingEndpoint = endpoint;
            }
        }
    }
    if (outgoingEndpoint == null || incomingEndpoint == null) {
        return null;
    } else {
        return new AcmUsbEndpoints(incomingEndpoint, outgoingEndpoint);
    }
}

From source file:com.dslr.dashboard.PtpService.java

private void initUsbConnection() {

    try {/*from   ww  w. j av a2  s.  c o  m*/
        if (mUsbDevice != null) {
            if (mUsbIntf == null) {
                for (int i = 0; i < mUsbDevice.getInterfaceCount(); i++) {
                    UsbInterface uintf = mUsbDevice.getInterface(i);
                    if (uintf.getInterfaceClass() == UsbConstants.USB_CLASS_STILL_IMAGE) {
                        // we have a still image interface
                        // Log.d(MainActivity.TAG, "Imaging USB interface found");
                        mUsbIntf = uintf;
                        break;
                    }
                }
                if (mUsbIntf != null) {
                    // get the endpoints
                    for (int i = 0; i < mUsbIntf.getEndpointCount(); i++) {
                        UsbEndpoint ep = mUsbIntf.getEndpoint(i);
                        if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
                            if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
                                mUsbWriteEp = ep;
                                // Log.d(MainActivity.TAG, "write endpoint found");
                            }
                        } else {
                            switch (ep.getType()) {
                            case UsbConstants.USB_ENDPOINT_XFER_BULK:
                                mUsbReadEp = ep;
                                // Log.d(MainActivity.TAG, "read endpoint found");
                                break;
                            case UsbConstants.USB_ENDPOINT_XFER_INT:
                                mUsbInterruptEp = ep;
                                // Log.d(MainActivity.TAG, "interrupt endpoint found");
                                break;
                            }
                        }
                    }
                } else
                    Log.d(TAG, "No compatible USB interface found");
            } else
                Log.d(TAG, "USB interface found");
            // if we have read and write endpoints then we good to go
            if (mUsbReadEp != null && mUsbWriteEp != null) {
                if (!mIsUsbDeviceInitialized) {
                    mUsbConnection = mUsbManager.openDevice(mUsbDevice);
                    mIsUsbDeviceInitialized = mUsbConnection != null;
                }
                if (mIsUsbDeviceInitialized) {
                    // Log.d(TAG, "USB Device Initialized");
                    if (!mIsUsbInterfaceClaimed) {
                        mIsUsbInterfaceClaimed = mUsbConnection.claimInterface(mUsbIntf, true);
                        // Log.d(TAG, "USB Interface claimed: " + isInterfaceClaimed);
                    }
                    sendPtpServiceEvent(PtpServiceEvent.UsbDeviceInitialized);
                    // create the USB communicator
                    PtpUsbCommunicator communicator = new PtpUsbCommunicator(new PtpSession());
                    // initialize the USB communicator
                    communicator.initCommunicator(mUsbConnection, mUsbWriteEp, mUsbReadEp, mUsbInterruptEp);
                    // initialize the PTP device
                    mPtpDevice.initialize(mUsbDevice.getVendorId(), mUsbDevice.getProductId(), communicator);
                }
            }

        } else
            Log.d(TAG, "No USB device present");

    } catch (Exception e) {
        Log.d(TAG, "InitUsb exception: " + e.getMessage());
    }
}

From source file:aws.apps.usbDeviceEnumerator.ui.usbinfo.AndroidUsbInfoFragment.java

private void populateDataTable(LayoutInflater inflater) {
    final String vid = CommonLogic.padLeft(Integer.toHexString(device.getVendorId()), "0", 4);
    final String pid = CommonLogic.padLeft(Integer.toHexString(device.getProductId()), "0", 4);
    final String deviceClass = UsbConstants.resolveUsbClass(device.getDeviceClass());

    viewHolder.getLogo().setImageResource(R.drawable.no_image);

    viewHolder.getVid().setText(vid);/*from   ww w  .  j a  v  a 2 s.  com*/
    viewHolder.getPid().setText(pid);
    viewHolder.getDevicePath().setText(usbKey);
    viewHolder.getDeviceClass().setText(deviceClass);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        viewHolder.getReportedVendor().setText(device.getManufacturerName());
        viewHolder.getReportedProduct().setText(device.getProductName());
    } else {
        viewHolder.getReportedVendor().setText("not provided");
        viewHolder.getReportedProduct().setText("not provided");
    }

    UsbInterface iFace;
    for (int i = 0; i < device.getInterfaceCount(); i++) {
        iFace = device.getInterface(i);
        if (iFace != null) {
            final TableLayout bottomTable = viewHolder.getBottomTable();
            final String usbClass = UsbConstants.resolveUsbClass((iFace.getInterfaceClass()));

            CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.interface_) + i, "");
            CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.class_), usbClass);

            if (iFace.getEndpointCount() > 0) {
                String endpointText;
                for (int j = 0; j < iFace.getEndpointCount(); j++) {
                    endpointText = getEndpointText(iFace.getEndpoint(j), j);
                    CommonLogic.addDataRow(inflater, bottomTable, getString(R.string.endpoint_), endpointText);
                }
            } else {
                CommonLogic.addDataRow(inflater, bottomTable, "\tEndpoints:", "none");
            }
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        loadAsyncData(vid, pid, device.getManufacturerName());
    } else {
        loadAsyncData(vid, pid, null);
    }
}

From source file:com.dslr.dashboard.PtpService.java

public void searchForUsbCamera() {
    boolean deviceFound = false;
    try {//w ww .java 2 s  .c  om
        if (mUsbDevice == null) {
            Log.d(TAG, "Ptp service usb device not initialized, search for one");

            if (mUsbManager != null) {
                HashMap<String, UsbDevice> devices = mUsbManager.getDeviceList();
                Log.d(TAG, "Found USB devices count: " + devices.size());
                Iterator<UsbDevice> iterator = devices.values().iterator();
                while (iterator.hasNext()) {
                    UsbDevice usbDevice = iterator.next();
                    Log.d(TAG,
                            "USB Device: " + usbDevice.getDeviceName() + " Product ID: "
                                    + usbDevice.getProductId() + " Vendor ID: " + usbDevice.getVendorId()
                                    + " Interface count: " + usbDevice.getInterfaceCount());
                    for (int i = 0; i < usbDevice.getInterfaceCount(); i++) {
                        UsbInterface intf = usbDevice.getInterface(i);
                        Log.d(TAG, "Interface class: " + intf.getInterfaceClass());
                        if (intf.getInterfaceClass() == android.hardware.usb.UsbConstants.USB_CLASS_STILL_IMAGE) {
                            //mUsbDevice = usbDevice;
                            Log.d(TAG, "Ptp Service imaging usb device found requesting permission");
                            mUsbManager.requestPermission(usbDevice, mPermissionIntent);
                            deviceFound = true;
                            break;
                        }
                    }
                    if (deviceFound)
                        break;
                }
            } else
                Log.d(TAG, "USB Manager is unavailable");

        } else {
            Log.d(TAG, "Ptp service usb imaging device already present");
            //_usbManager.requestPermission(_usbDevice, mPermissionIntent);
        }
    } catch (Exception e) {
        Log.d(TAG, "PtpService search for USB camrea exception: " + e.getMessage());
    }

}

From source file:fr.bmartel.android.fadecandy.service.FadecandyService.java

/**
 * Open USB device & choose USBEndpoint.
 *
 * @param device Usb device object.//  w  w w. j av  a 2  s. c  o m
 * @return Ubs item composed of USBDevice , USBEndpoint & UsbConnection
 */
private UsbItem openDevice(UsbDevice device) {

    UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

    try {
        UsbDeviceConnection connection = manager.openDevice(device);

        Log.v("USB", "Device name=" + device.getDeviceName());

        UsbInterface intf = null;

        for (int interfaceIndex = 0; interfaceIndex < device.getInterfaceCount(); interfaceIndex++) {

            UsbInterface usbInterface = device.getInterface(interfaceIndex);

            if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC) {
                intf = usbInterface;
            }
        }

        if (intf == null) {
            intf = device.getInterface(0);
        }

        UsbEndpoint endpoint = intf.getEndpoint(0);

        if (connection != null) {
            connection.claimInterface(intf, true);
        } else {
            Log.e(TAG, "USB connection error");
            return null;
        }

        return new UsbItem(device, connection, endpoint);

    } catch (IllegalArgumentException e) {
    }
    return null;
}