本文整理匯總了Java中android.hardware.usb.UsbInterface.getInterfaceProtocol方法的典型用法代碼示例。如果您正苦於以下問題:Java UsbInterface.getInterfaceProtocol方法的具體用法?Java UsbInterface.getInterfaceProtocol怎麽用?Java UsbInterface.getInterfaceProtocol使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.hardware.usb.UsbInterface
的用法示例。
在下文中一共展示了UsbInterface.getInterfaceProtocol方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ConnectedUsbDevice
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
public ConnectedUsbDevice(UsbDeviceConnection connection, UsbInterface usbInterface) {
this.connection = connection;
this.usbInterface = usbInterface;
initConnection(connection);
int endPoints = usbInterface.getEndpointCount();
int interfaceProtocol = usbInterface.getInterfaceProtocol();
System.out.println("EndPoints: " + endPoints + " | interfaces: " + interfaceProtocol);
out = usbInterface.getEndpoint(1);
in = usbInterface.getEndpoint(2);
for (int x = 0; x < endPoints; x++) {
UsbEndpoint endpoint = usbInterface.getEndpoint(x);
boolean bulk = endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK;
boolean crtl = endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_CONTROL;
boolean inDir = endpoint.getDirection() == UsbConstants.USB_DIR_IN;
boolean outDir = endpoint.getDirection() == UsbConstants.USB_DIR_OUT;
System.out.println("ID: " + x + " Bulk: " + bulk + " Ctrl: " + crtl + " Out: " + outDir + " In: " + inDir);
}
}
示例2: findAdbInterface
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
static private UsbInterface findAdbInterface(UsbDevice device) {
Log.d(TAG, "findAdbInterface " + device);
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
if (intf.getInterfaceClass() == 255 && intf.getInterfaceSubclass() == 66 &&
intf.getInterfaceProtocol() == 1) {
return intf;
}
}
return null;
}
示例3: findAdbInterface
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
static private UsbInterface findAdbInterface(android.hardware.usb.UsbDevice device) {
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
if (intf.getInterfaceClass() == 3
&& intf.getInterfaceSubclass() == 0
&& intf.getInterfaceProtocol() == 0) {
return intf;
}
}
return null;
}
示例4: isCamera
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
/**
* Tests to see if a {@link android.hardware.usb.UsbDevice}
* supports the PTP protocol (typically used by digital cameras)
*
* @param device the device to test
* @return true if the device is a PTP device.
*/
static public boolean isCamera(UsbDevice device) {
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
if (intf.getInterfaceClass() == UsbConstants.USB_CLASS_STILL_IMAGE &&
intf.getInterfaceSubclass() == 1 &&
intf.getInterfaceProtocol() == 1) {
return true;
}
}
return false;
}
示例5: filterDevice
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
private boolean filterDevice(UsbDevice device, JSONArray filters) throws JSONException {
if (filters == null) {
return true;
}
Log.d(TAG, "filtering " + filters);
for (int filterIdx = 0; filterIdx < filters.length(); filterIdx++) {
JSONObject filter = filters.getJSONObject(filterIdx);
int vendorId = filter.optInt("vendorId", -1);
if (vendorId != -1) {
if (device.getVendorId() != vendorId) {
continue;
}
}
int productId = filter.optInt("productId", -1);
if (productId != -1) {
if (device.getProductId() != productId) {
continue;
}
}
int interfaceClass = filter.optInt("interfaceClass", -1);
int interfaceSubclass = filter.optInt("interfaceSubclass", -1);
int interfaceProtocol = filter.optInt("interfaceProtocol", -1);
if (interfaceClass == -1 && interfaceSubclass == -1 && interfaceProtocol == -1) {
return true;
}
int interfaceCount = device.getInterfaceCount();
for (int interfaceIdx = 0; interfaceIdx < interfaceCount; interfaceIdx++) {
UsbInterface usbInterface = device.getInterface(interfaceIdx);
if (interfaceClass != -1) {
if (interfaceClass != usbInterface.getInterfaceClass()) {
continue;
}
}
if (interfaceSubclass != -1) {
if (interfaceSubclass != usbInterface.getInterfaceSubclass()) {
continue;
}
}
if (interfaceProtocol != -1) {
if (interfaceProtocol != usbInterface.getInterfaceProtocol()) {
continue;
}
}
return true;
}
}
return false;
}
示例6: getInfoForDevice
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
private UsbDeviceInfo getInfoForDevice(UsbDevice dev, UsbDeviceConnection devConn) {
UsbDeviceInfo info = new UsbDeviceInfo();
UsbIpDevice ipDev = new UsbIpDevice();
ipDev.path = dev.getDeviceName();
ipDev.busnum = deviceIdToBusNum(dev.getDeviceId());
ipDev.devnum = deviceIdToDevNum(dev.getDeviceId());
ipDev.busid = String.format("%d-%d", ipDev.busnum, ipDev.devnum);
ipDev.idVendor = (short) dev.getVendorId();
ipDev.idProduct = (short) dev.getProductId();
ipDev.bcdDevice = -1;
ipDev.bDeviceClass = (byte) dev.getDeviceClass();
ipDev.bDeviceSubClass = (byte) dev.getDeviceSubclass();
ipDev.bDeviceProtocol = (byte) dev.getDeviceProtocol();
ipDev.bConfigurationValue = 0;
ipDev.bNumConfigurations = 1;
ipDev.bNumInterfaces = (byte) dev.getInterfaceCount();
info.dev = ipDev;
info.interfaces = new UsbIpInterface[ipDev.bNumInterfaces];
for (int i = 0; i < ipDev.bNumInterfaces; i++) {
info.interfaces[i] = new UsbIpInterface();
UsbInterface iface = dev.getInterface(i);
info.interfaces[i].bInterfaceClass = (byte) iface.getInterfaceClass();
info.interfaces[i].bInterfaceSubClass = (byte) iface.getInterfaceSubclass();
info.interfaces[i].bInterfaceProtocol = (byte) iface.getInterfaceProtocol();
}
AttachedDeviceContext context = connections.get(dev.getDeviceId());
UsbDeviceDescriptor devDesc = null;
if (context != null) {
// Since we're attached already, we can directly query the USB descriptors
// to fill some information that Android's USB API doesn't expose
devDesc = UsbControlHelper.readDeviceDescriptor(context.devConn);
ipDev.bcdDevice = devDesc.bcdDevice;
ipDev.bNumConfigurations = devDesc.bNumConfigurations;
}
ipDev.speed = detectSpeed(dev, devDesc);
return info;
}
示例7: getMassStorageDevices
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
/**
* This method iterates through all connected USB devices and searches for
* mass storage devices.
*
* @param context Context to get the {@link UsbManager}
* @return An array of suitable mass storage devices or an empty array if none could be found.
*/
public static UsbMassStorageDevice[] getMassStorageDevices(Context context) {
UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
ArrayList<UsbMassStorageDevice> result = new ArrayList<UsbMassStorageDevice>();
for (UsbDevice device : usbManager.getDeviceList().values()) {
Log.i(TAG, "found usb device: " + device);
int interfaceCount = device.getInterfaceCount();
for (int i = 0; i < interfaceCount; i++) {
UsbInterface usbInterface = device.getInterface(i);
Log.i(TAG, "found usb interface: " + usbInterface);
// we currently only support SCSI transparent command set with
// bulk transfers only!
if (usbInterface.getInterfaceClass() != UsbConstants.USB_CLASS_MASS_STORAGE
|| usbInterface.getInterfaceSubclass() != INTERFACE_SUBCLASS
|| usbInterface.getInterfaceProtocol() != INTERFACE_PROTOCOL) {
Log.i(TAG, "device interface not suitable!");
continue;
}
// Every mass storage device has exactly two endpoints
// One IN and one OUT endpoint
int endpointCount = usbInterface.getEndpointCount();
if (endpointCount != 2) {
Log.w(TAG, "inteface endpoint count != 2");
}
UsbEndpoint outEndpoint = null;
UsbEndpoint inEndpoint = null;
for (int j = 0; j < endpointCount; j++) {
UsbEndpoint endpoint = usbInterface.getEndpoint(j);
Log.i(TAG, "found usb endpoint: " + endpoint);
if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
outEndpoint = endpoint;
} else {
inEndpoint = endpoint;
}
}
}
if (outEndpoint == null || inEndpoint == null) {
Log.e(TAG, "Not all needed endpoints found!");
continue;
}
result.add(new UsbMassStorageDevice(usbManager, device, usbInterface, inEndpoint,
outEndpoint));
}
}
return result.toArray(new UsbMassStorageDevice[0]);
}