本文整理汇总了Java中android.hardware.usb.UsbInterface.getInterfaceSubclass方法的典型用法代码示例。如果您正苦于以下问题:Java UsbInterface.getInterfaceSubclass方法的具体用法?Java UsbInterface.getInterfaceSubclass怎么用?Java UsbInterface.getInterfaceSubclass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.hardware.usb.UsbInterface
的用法示例。
在下文中一共展示了UsbInterface.getInterfaceSubclass方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestDevicePermissionIfNecessary
import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
/**
* Request a device access permission if there is a MIDI interface in the device.
*
* @param device a USB device
*/
private void requestDevicePermissionIfNecessary(UsbDevice device) {
for (UsbDevice d : mRequestedDevices) {
if (d.getDeviceId() == device.getDeviceId()) {
// It is already requested.
return;
}
}
for (int i = 0; i < device.getInterfaceCount(); ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() == UsbConstants.USB_CLASS_AUDIO
&& iface.getInterfaceSubclass() == UsbMidiDeviceAndroid.MIDI_SUBCLASS) {
// There is at least one interface supporting MIDI.
mUsbManager.requestPermission(device,
PendingIntent.getBroadcast(ContextUtils.getApplicationContext(), 0,
new Intent(ACTION_USB_PERMISSION), 0));
mRequestedDevices.add(device);
break;
}
}
}
示例2: UsbMidiDeviceAndroid
import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
/**
* Constructs a UsbMidiDeviceAndroid.
* @param manager
* @param device The USB device which this object is assocated with.
*/
UsbMidiDeviceAndroid(UsbManager manager, UsbDevice device) {
mConnection = manager.openDevice(device);
mEndpointMap = new HashMap<Integer, UsbEndpoint>();
mRequestMap = new HashMap<UsbEndpoint, UsbRequest>();
for (int i = 0; i < device.getInterfaceCount(); ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() != UsbConstants.USB_CLASS_AUDIO ||
iface.getInterfaceSubclass() != MIDI_SUBCLASS) {
continue;
}
mConnection.claimInterface(iface, true);
for (int j = 0; j < iface.getEndpointCount(); ++j) {
UsbEndpoint endpoint = iface.getEndpoint(j);
if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
mEndpointMap.put(endpoint.getEndpointNumber(), endpoint);
}
}
}
}
示例3: 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;
}
示例4: 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;
}
示例5: initEnpoints
import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
private void initEnpoints(UsbInterface usbInterface) {
usbInterface.getInterfaceSubclass();
UsbEndpoint endpoint = usbInterface.getEndpoint(0);
UsbEndpoint endpoint2 = usbInterface.getEndpoint(1);
if (endpoint.getDirection() == UsbConstants.USB_DIR_IN) {
UsbEndpoint usbEndpoint = endpoint2;
endpoint2 = endpoint;
endpoint = usbEndpoint;
}
inputEndpoint = endpoint2;
outputEndpoint = endpoint;
}
示例6: 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;
}
示例7: UsbMidiDeviceAndroid
import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
/**
* Constructs a UsbMidiDeviceAndroid.
* @param manager
* @param device The USB device which this object is assocated with.
*/
UsbMidiDeviceAndroid(UsbManager manager, UsbDevice device) {
mConnection = manager.openDevice(device);
mEndpointMap = new SparseArray<UsbEndpoint>();
mRequestMap = new HashMap<UsbEndpoint, UsbRequest>();
mHandler = new Handler();
mUsbDevice = device;
mIsClosed = false;
mHasInputThread = false;
mNativePointer = 0;
for (int i = 0; i < device.getInterfaceCount(); ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() != UsbConstants.USB_CLASS_AUDIO
|| iface.getInterfaceSubclass() != MIDI_SUBCLASS) {
continue;
}
mConnection.claimInterface(iface, true);
for (int j = 0; j < iface.getEndpointCount(); ++j) {
UsbEndpoint endpoint = iface.getEndpoint(j);
if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
mEndpointMap.put(endpoint.getEndpointNumber(), endpoint);
}
}
}
// Start listening for input endpoints.
// This function will create and run a thread if there is USB-MIDI endpoints in the
// device. Note that because UsbMidiDevice is shared among all tabs and the thread
// will be terminated when the device is disconnected, at most one thread can be created
// for each connected USB-MIDI device.
startListen(device);
}
示例8: enumerateDevices
import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
/**
* Enumerates USB-MIDI devices.
* If there are devices having USB-MIDI interfaces, this function requests permission for
* accessing the device to the user.
* When the permission request is accepted or rejected onRequestDone will be called.
*
* If there are no USB-MIDI interfaces, this function returns false.
* @return true if some permission requests are in progress.
*/
@CalledByNative
boolean enumerateDevices(Context context) {
mUsbManager = (UsbManager)context.getSystemService(Context.USB_SERVICE);
Map<String, UsbDevice> devices = mUsbManager.getDeviceList();
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context, 0, new Intent(ACTION_USB_PERMISSION), 0);
mRequestedDevices = new HashSet<UsbDevice>();
for (UsbDevice device : devices.values()) {
boolean found = false;
for (int i = 0; i < device.getInterfaceCount() && !found; ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() == UsbConstants.USB_CLASS_AUDIO &&
iface.getInterfaceSubclass() == UsbMidiDeviceAndroid.MIDI_SUBCLASS) {
found = true;
}
}
if (found) {
mUsbManager.requestPermission(device, pendingIntent);
mRequestedDevices.add(device);
}
}
if (mRequestedDevices.isEmpty()) {
// No USB-MIDI devices are found.
return false;
}
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
if (ACTION_USB_PERMISSION.equals(intent.getAction())) {
onRequestDone(context, intent);
}
}
};
context.registerReceiver(mReceiver, filter);
return true;
}
示例9: findMidiInterface
import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
public static UsbInterface findMidiInterface(UsbDevice device) {
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface usbIf = device.getInterface(i);
if (usbIf.getInterfaceClass() == 1 && usbIf.getInterfaceSubclass() == 3) {
return usbIf;
}
}
return null;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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]);
}