FileDocCategorySizeDatePackage
UsbDevice.javaAPI DocAndroid 5.1 API10181Thu Mar 12 22:22:10 GMT 2015android.hardware.usb

UsbDevice

public class UsbDevice extends Object implements android.os.Parcelable
This class represents a USB device attached to the android device with the android device acting as the USB host. Each device contains one or more {@link UsbInterface}s, each of which contains a number of {@link UsbEndpoint}s (the channels via which data is transmitted over USB).

This class contains information (along with {@link UsbInterface} and {@link UsbEndpoint}) that describes the capabilities of the USB device. To communicate with the device, you open a {@link UsbDeviceConnection} for the device and use {@link UsbRequest} to send and receive data on an endpoint. {@link UsbDeviceConnection#controlTransfer} is used for control requests on endpoint zero.

Developer Guides

For more information about communicating with USB hardware, read the USB developer guide.

Fields Summary
private static final String
TAG
private final String
mName
private final String
mManufacturerName
private final String
mProductName
private final String
mSerialNumber
private final int
mVendorId
private final int
mProductId
private final int
mClass
private final int
mSubclass
private final int
mProtocol
private android.os.Parcelable[]
mConfigurations
private UsbInterface[]
mInterfaces
public static final Parcelable.Creator
CREATOR
Constructors Summary
public UsbDevice(String name, int vendorId, int productId, int Class, int subClass, int protocol, String manufacturerName, String productName, String serialNumber)
UsbDevice should only be instantiated by UsbService implementation

hide


                  
          
                 
                  
        mName = name;
        mVendorId = vendorId;
        mProductId = productId;
        mClass = Class;
        mSubclass = subClass;
        mProtocol = protocol;
        mManufacturerName = manufacturerName;
        mProductName = productName;
        mSerialNumber = serialNumber;
    
Methods Summary
public intdescribeContents()


       
        return 0;
    
public booleanequals(java.lang.Object o)

        if (o instanceof UsbDevice) {
            return ((UsbDevice)o).mName.equals(mName);
        } else if (o instanceof String) {
            return ((String)o).equals(mName);
        } else {
            return false;
        }
    
public UsbConfigurationgetConfiguration(int index)
Returns the {@link UsbConfiguration} at the given index.

return
the configuration

        return (UsbConfiguration)mConfigurations[index];
    
public intgetConfigurationCount()
Returns the number of {@link UsbConfiguration}s this device contains.

return
the number of configurations

        return mConfigurations.length;
    
public intgetDeviceClass()
Returns the devices's class field. Some useful constants for USB device classes can be found in {@link UsbConstants}.

return
the devices's class

        return mClass;
    
public static intgetDeviceId(java.lang.String name)

        return native_get_device_id(name);
    
public intgetDeviceId()
Returns a unique integer ID for the device. This is a convenience for clients that want to use an integer to represent the device, rather than the device name. IDs are not persistent across USB disconnects.

return
the device ID

        return getDeviceId(mName);
    
public java.lang.StringgetDeviceName()
Returns the name of the device. In the standard implementation, this is the path of the device file for the device in the usbfs file system.

return
the device name

        return mName;
    
public static java.lang.StringgetDeviceName(int id)

        return native_get_device_name(id);
    
public intgetDeviceProtocol()
Returns the device's protocol field.

return
the device's protocol

        return mProtocol;
    
public intgetDeviceSubclass()
Returns the device's subclass field.

return
the device's subclass

        return mSubclass;
    
public UsbInterfacegetInterface(int index)
Returns the {@link UsbInterface} at the given index. For devices with multiple configurations, you will probably want to use {@link UsbConfiguration#getInterface} instead.

return
the interface

        return getInterfaceList()[index];
    
public intgetInterfaceCount()
Returns the number of {@link UsbInterface}s this device contains. For devices with multiple configurations, you will probably want to use {@link UsbConfiguration#getInterfaceCount} instead.

return
the number of interfaces

        return getInterfaceList().length;
    
private UsbInterface[]getInterfaceList()

        if (mInterfaces == null) {
            int configurationCount = mConfigurations.length;
            int interfaceCount = 0;
            for (int i = 0; i < configurationCount; i++) {
                UsbConfiguration configuration = (UsbConfiguration)mConfigurations[i];
                interfaceCount += configuration.getInterfaceCount();
            }

            mInterfaces = new UsbInterface[interfaceCount];
            int offset = 0;
            for (int i = 0; i < configurationCount; i++) {
                UsbConfiguration configuration = (UsbConfiguration)mConfigurations[i];
                interfaceCount = configuration.getInterfaceCount();
                for (int j = 0; j < interfaceCount; j++) {
                    mInterfaces[offset++] = configuration.getInterface(j);
                }
            }
        }

        return mInterfaces;
    
public java.lang.StringgetManufacturerName()
Returns the manufacturer name of the device.

return
the manufacturer name

        return mManufacturerName;
    
public intgetProductId()
Returns a product ID for the device.

return
the device product ID

        return mProductId;
    
public java.lang.StringgetProductName()
Returns the product name of the device.

return
the product name

        return mProductName;
    
public java.lang.StringgetSerialNumber()
Returns the serial number of the device.

return
the serial number name

        return mSerialNumber;
    
public intgetVendorId()
Returns a vendor ID for the device.

return
the device vendor ID

        return mVendorId;
    
public inthashCode()

        return mName.hashCode();
    
private static native intnative_get_device_id(java.lang.String name)

private static native java.lang.Stringnative_get_device_name(int id)

public voidsetConfigurations(android.os.Parcelable[] configuration)
Only used by UsbService implementation

hide

        mConfigurations = configuration;
    
public java.lang.StringtoString()

        StringBuilder builder = new StringBuilder("UsbDevice[mName=" + mName +
                ",mVendorId=" + mVendorId + ",mProductId=" + mProductId +
                ",mClass=" + mClass + ",mSubclass=" + mSubclass + ",mProtocol=" + mProtocol +
                ",mManufacturerName=" + mManufacturerName + ",mProductName=" + mProductName +
                ",mSerialNumber=" + mSerialNumber + ",mConfigurations=[");
        for (int i = 0; i < mConfigurations.length; i++) {
            builder.append("\n");
            builder.append(mConfigurations[i].toString());
        }
        builder.append("]");
        return builder.toString();
    
public voidwriteToParcel(android.os.Parcel parcel, int flags)

        parcel.writeString(mName);
        parcel.writeInt(mVendorId);
        parcel.writeInt(mProductId);
        parcel.writeInt(mClass);
        parcel.writeInt(mSubclass);
        parcel.writeInt(mProtocol);
        parcel.writeString(mManufacturerName);
        parcel.writeString(mProductName);
        parcel.writeString(mSerialNumber);
        parcel.writeParcelableArray(mConfigurations, 0);