Java 类android.hardware.usb.UsbInterface 实例源码

项目:buildAPKsSamples    文件:AdbDevice.java   
public AdbDevice(AdbTestActivity activity, UsbDeviceConnection connection,
        UsbInterface intf) {
    mActivity = activity;
    mDeviceConnection = connection;
    mSerial = connection.getSerial();

    UsbEndpoint epOut = null;
    UsbEndpoint epIn = null;
    // look for our bulk endpoints
    for (int i = 0; i < intf.getEndpointCount(); i++) {
        UsbEndpoint ep = intf.getEndpoint(i);
        if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
            if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
                epOut = ep;
            } else {
                epIn = ep;
            }
        }
    }
    if (epOut == null || epIn == null) {
        throw new IllegalArgumentException("not all endpoints found");
    }
    mEndpointOut = epOut;
    mEndpointIn = epIn;
}
项目:UsbHid    文件:UsbHidDevice.java   
public static UsbHidDevice[] enumerate(Context context, int vid, int pid) throws Exception {
    UsbManager usbManager = (UsbManager) context.getApplicationContext().getSystemService(Context.USB_SERVICE);
    if (usbManager == null) {
        throw new Exception("no usb service");
    }

    Map<String, UsbDevice> devices = usbManager.getDeviceList();
    List<UsbHidDevice> usbHidDevices = new ArrayList<>();
    for (UsbDevice device : devices.values()) {
        if ((vid == 0 || device.getVendorId() == vid) && (pid == 0 || device.getProductId() == pid)) {
            for (int i = 0; i < device.getInterfaceCount(); i++) {
                UsbInterface usbInterface = device.getInterface(i);
                if (usbInterface.getInterfaceClass() == INTERFACE_CLASS_HID) {
                    UsbHidDevice hidDevice = new UsbHidDevice(device, usbInterface, usbManager);
                    usbHidDevices.add(hidDevice);
                }
            }
        }
    }
    return usbHidDevices.toArray(new UsbHidDevice[usbHidDevices.size()]);
}
项目:UsbHid    文件:UsbHidDevice.java   
private UsbHidDevice(UsbDevice usbDevice, UsbInterface usbInterface, UsbManager usbManager) {
    mUsbDevice = usbDevice;
    mUsbInterface = usbInterface;
    mUsbManager= usbManager;

    for (int i = 0; i < mUsbInterface.getEndpointCount(); i++) {
        UsbEndpoint endpoint = mUsbInterface.getEndpoint(i);
        int dir = endpoint.getDirection();
        int type = endpoint.getType();
        if (mInUsbEndpoint == null && dir == UsbConstants.USB_DIR_IN && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
            mInUsbEndpoint = endpoint;
        }
        if (mOutUsbEndpoint == null && dir == UsbConstants.USB_DIR_OUT && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
            mOutUsbEndpoint = endpoint;
        }
    }
}
项目:AndroidUvcCameras    文件:USBMonitor.java   
/**
 * open specific interface
 * @param interfaceIndex
 * @return
 */
public synchronized UsbInterface open(final int interfaceIndex) {
    if (DEBUG) Log.i(TAG, "UsbControlBlock#open:" + interfaceIndex);
    final UsbDevice device = mWeakDevice.get();
    UsbInterface intf = null;
    intf = mInterfaces.get(interfaceIndex);
    if (intf == null) {
        intf = device.getInterface(interfaceIndex);
        if (intf != null) {
            synchronized (mInterfaces) {
                mInterfaces.append(interfaceIndex, intf);
            }
        }
    }
    return intf;
}
项目:AndroidUvcCameras    文件:USBMonitor.java   
/**
 * close specified interface. USB device itself still keep open.
 * @param interfaceIndex
 */
public synchronized void close() {
    if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");

    if (mConnection != null) {
        final int n = mInterfaces.size();
        int key;
        UsbInterface intf;
        for (int i = 0; i < n; i++) {
            key = mInterfaces.keyAt(i);
            intf = mInterfaces.get(key);
            mConnection.releaseInterface(intf);
        }
        mConnection.close();
        mConnection = null;
        final USBMonitor monitor = mWeakMonitor.get();
        if (monitor != null) {
            if (monitor.mOnDeviceConnectListener != null) {
                final UsbDevice device = mWeakDevice.get();
                monitor.mOnDeviceConnectListener.onDisconnect(device, this);
            }
            monitor.mCtrlBlocks.remove(getDevice());
        }
    }
}
项目:AndroidDvbDriver    文件:AlternateUsbInterface.java   
public static List<AlternateUsbInterface> forUsbInterface(UsbDeviceConnection deviceConnection, UsbInterface usbInterface) {
    byte[] rawDescriptors = deviceConnection.getRawDescriptors();

    List<AlternateUsbInterface> alternateSettings = new ArrayList<>(2);
    int offset = 0;
    while(offset < rawDescriptors.length) {
        int bLength = rawDescriptors[offset] & 0xFF;
        int bDescriptorType = rawDescriptors[offset + 1] & 0xFF;

        if (bDescriptorType == 0x04) {
            // interface descriptor, we are not interested
            int bInterfaceNumber = rawDescriptors[offset + 2] & 0xFF;
            int bAlternateSetting = rawDescriptors[offset + 3] & 0xFF;

            if (bInterfaceNumber == usbInterface.getId()) {
                alternateSettings.add(new AlternateUsbInterface(usbInterface, bAlternateSetting));
            }
        }

        // go to next structure
        offset += bLength;
    }

    if (alternateSettings.size() < 1) throw new IllegalStateException();
    return alternateSettings;
}
项目:AndroidDvbDriver    文件:AlternateUsbInterfaceTest.java   
@Test
public void getAlternateSetting() throws Exception {
    UsbDeviceConnection usbDeviceConnection = mockConnectionWithRawDescriptors(new byte[] {
            18, 1, 0, 2, 0, 0, 0, 64, -38, 11, 56, 40, 0, 1, 1, 2, 3, 1, // Device Descriptor
            9, 2, 34, 0, 2, 1, 4, -128, -6, // Configuration Descriptor
            9, 4, 0, 0, 1, -1, -1, -1, 5, // Interface Descriptor for interface 0 with alternate setting 0
            9, 4, 0, 1, 1, -1, -1, -1, 5, // Interface Descriptor for interface 0 with alternate setting 1
            7, 5, -127, 2, 0, 2, 0, // Endpoint Descriptor
            9, 4, 1, 0, 0, -1, -1, -1, 5 // Interface Descriptor for interface 1 with alternate setting 0
    });

    // Interface 0 has alternate settings {0, 1}
    UsbInterface i0 = mockInterface(0);
    assertThat(AlternateUsbInterface.forUsbInterface(usbDeviceConnection, i0),
            equalTo(asList(new AlternateUsbInterface(i0, 0), new AlternateUsbInterface(i0, 1))));

    // Interface 1 has alternate settings {0}
    UsbInterface i1 = mockInterface(1);
    assertThat(AlternateUsbInterface.forUsbInterface(usbDeviceConnection, i1),
            equalTo(singletonList(new AlternateUsbInterface(i1, 0))));
}
项目:buildAPKsSamples    文件:AdbTestActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.adb);
    mLog = (TextView)findViewById(R.id.log);

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

    // check for existing devices
    for (UsbDevice device :  mManager.getDeviceList().values()) {
        UsbInterface intf = findAdbInterface(device);
        if (setAdbInterface(device, intf)) {
            break;
        }
    }

    // listen for new devices
    IntentFilter filter = new IntentFilter();
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mUsbReceiver, filter);
}
项目:buildAPKsSamples    文件:AdbTestActivity.java   
private boolean setAdbInterface(UsbDevice device, UsbInterface intf) {
    if (mDeviceConnection != null) {
        if (mInterface != null) {
            mDeviceConnection.releaseInterface(mInterface);
            mInterface = null;
        }
        mDeviceConnection.close();
        mDevice = null;
        mDeviceConnection = null;
    }

    if (device != null && intf != null) {
        UsbDeviceConnection connection = mManager.openDevice(device);
        if (connection != null) {
            log("open succeeded");
            if (connection.claimInterface(intf, false)) {
                log("claim interface succeeded");
                mDevice = device;
                mDeviceConnection = connection;
                mInterface = intf;
                mAdbDevice = new AdbDevice(this, mDeviceConnection, intf);
                log("call start");
                mAdbDevice.start();
                return true;
            } else {
                log("claim interface failed");
                connection.close();
            }
        } else {
            log("open failed");
        }
    }

    if (mDeviceConnection == null && mAdbDevice != null) {
        mAdbDevice.stop();
        mAdbDevice = null;
    }
    return false;
}
项目:sample-usbenum    文件:UsbHelper.java   
/**
 * Enumerate the endpoints and interfaces on the connected device.
 *
 * @param device Device to query.
 * @return String description of the device configuration.
 */
public static String readDevice(UsbDevice device) {
    StringBuilder sb = new StringBuilder();
    sb.append("Device Name: " + device.getDeviceName() + "\n");
    sb.append(String.format(
            "Device Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n",
            nameForClass(device.getDeviceClass()),
            device.getDeviceSubclass(), device.getDeviceProtocol()));

    for (int i = 0; i < device.getInterfaceCount(); i++) {
        UsbInterface intf = device.getInterface(i);
        sb.append(String.format(Locale.US,
                "-- Interface %d Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n",
                intf.getId(),
                nameForClass(intf.getInterfaceClass()),
                intf.getInterfaceSubclass(),
                intf.getInterfaceProtocol()));

        sb.append(String.format(Locale.US, "   -- Endpoint Count: %d\n",
                intf.getEndpointCount()));
    }

    return sb.toString();
}
项目:astrobee_android    文件:MainActivity.java   
protected void setupUsb(UsbDevice device) {
    UsbInterface inf = device.getInterface(0);
    UsbDeviceConnection conn = mUsbManager.openDevice(device);
    if (conn == null) {
        Log.wtf("MainActivity", "unable to open device?");
        return;
    }

    if (!conn.claimInterface(inf, true)) {
        conn.close();
        Log.wtf("MainActivity", "unable to claim interface!");
        return;
    }

    mBlinkDevice = device;
    mBlinkConn = conn;
}
项目:UVCCameraZxing    文件:USBMonitor.java   
/**
 * open specific interface
 * @param interfaceIndex
 * @return
 */
public synchronized UsbInterface open(final int interfaceIndex) {
    if (DEBUG) Log.i(TAG, "UsbControlBlock#open:" + interfaceIndex);
    final UsbDevice device = mWeakDevice.get();
    UsbInterface intf = null;
    intf = mInterfaces.get(interfaceIndex);
    if (intf == null) {
        intf = device.getInterface(interfaceIndex);
        if (intf != null) {
            synchronized (mInterfaces) {
                mInterfaces.append(interfaceIndex, intf);
            }
        }
    }
    return intf;
}
项目:UVCCameraZxing    文件:USBMonitor.java   
/**
 * close specified interface. USB device itself still keep open.
 */
public synchronized void close() {
    if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");

    if (mConnection != null) {
        final int n = mInterfaces.size();
        int key;
        UsbInterface intf;
        for (int i = 0; i < n; i++) {
            key = mInterfaces.keyAt(i);
            intf = mInterfaces.get(key);
            mConnection.releaseInterface(intf);
        }
        mConnection.close();
        mConnection = null;
        final USBMonitor monitor = mWeakMonitor.get();
        if (monitor != null) {
            if (monitor.mOnDeviceConnectListener != null) {
                final UsbDevice device = mWeakDevice.get();
                monitor.mOnDeviceConnectListener.onDisconnect(device, this);
            }
            monitor.mCtrlBlocks.remove(getDevice());
        }
    }
}
项目:AndroidUvcCameras    文件:USBMonitor.java   
/**
 * open specific interface
 * @param interfaceIndex
 * @return
 */
public synchronized UsbInterface open(final int interfaceIndex) {
    if (DEBUG) Log.i(TAG, "UsbControlBlock#open:" + interfaceIndex);
    final UsbDevice device = mWeakDevice.get();
    UsbInterface intf = null;
    intf = mInterfaces.get(interfaceIndex);
    if (intf == null) {
        intf = device.getInterface(interfaceIndex);
        if (intf != null) {
            synchronized (mInterfaces) {
                mInterfaces.append(interfaceIndex, intf);
            }
        }
    }
    return intf;
}
项目:AndroidUvcCameras    文件:USBMonitor.java   
/**
 * close specified interface. USB device itself still keep open.
 * @param interfaceIndex
 */
public synchronized void close() {
    if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");

    if (mConnection != null) {
        final int n = mInterfaces.size();
        int key;
        UsbInterface intf;
        for (int i = 0; i < n; i++) {
            key = mInterfaces.keyAt(i);
            intf = mInterfaces.get(key);
            mConnection.releaseInterface(intf);
        }
        mConnection.close();
        mConnection = null;
        final USBMonitor monitor = mWeakMonitor.get();
        if (monitor != null) {
            if (monitor.mOnDeviceConnectListener != null) {
                final UsbDevice device = mWeakDevice.get();
                monitor.mOnDeviceConnectListener.onDisconnect(device, this);
            }
            monitor.mCtrlBlocks.remove(getDevice());
        }
    }
}
项目:walt    文件:WaltUsbConnection.java   
@Override
public void onConnect() {
    // Serial mode only
    // TODO: find the interface and endpoint indexes no matter what mode it is
    int ifIdx = 1;
    int epInIdx = 1;
    int epOutIdx = 0;

    UsbInterface iface = usbDevice.getInterface(ifIdx);

    if (usbConnection.claimInterface(iface, true)) {
        logger.log("Interface claimed successfully\n");
    } else {
        logger.log("ERROR - can't claim interface\n");
        return;
    }

    endpointIn = iface.getEndpoint(epInIdx);
    endpointOut = iface.getEndpoint(epOutIdx);

    super.onConnect();
}
项目:bootloadHID-android    文件:UsbWriter.java   
private boolean setDevice(UsbDevice device) {
    Logger.d("setDevice " + device);
    clearDevice();
    if (null == device) {
        return false;
    }
    if (device.getVendorId() != mVendorId) {
        printDevice(device);
        Logger.i("Not a target vendor: expecting %d", mVendorId);
        return false;
    }
    if (device.getProductId() != mProductId) {
        printDevice(device);
        Logger.i("Not a target product: expecting %d", mProductId);
        return false;
    }
    if (!mUsbManager.hasPermission(device)) {
        Logger.d("request permission");
        mUsbManager.requestPermission(device, mPermissionIntent);
        return false;
    }
    printDevice(device);
    try {
        UsbInterface usbinterface = device.getInterface(0);
        UsbDeviceConnection connection = mUsbManager.openDevice(device);
        if (!connection.claimInterface(usbinterface, true)) {
            return false;
        }
        mDevice = device;
        mConnection = connection;
        Logger.d("open SUCCESS");
        if (null != mOnDeviceListener) {
            mOnDeviceListener.onAttached();
        }
        return true;
    } catch (Exception e) {
        Logger.e(e, e.getLocalizedMessage());
    }
    return false;
}
项目:lp2go    文件:MainActivity.java   
private boolean setUsbInterface(android.hardware.usb.UsbDevice device, UsbInterface intf) {
    if (mDeviceConnection != null) {
        if (mInterface != null) {
            mDeviceConnection.releaseInterface(mInterface);
            mInterface = null;
        }
        mDeviceConnection.close();
        mDevice = null;
        mDeviceConnection = null;
    }

    if (device != null && intf != null) {
        UsbDeviceConnection connection = mUsbManager.openDevice(device);
        if (connection != null) {
            if (connection.claimInterface(intf, true)) {
                mDevice = device;
                mDeviceConnection = connection;
                mInterface = intf;
                mFcDevice = new FcUsbDevice(this, mDeviceConnection, intf,
                        mXmlObjects);
                mFcDevice.getObjectTree().setXmlObjects(mXmlObjects);

                mFcDevice.start();
                return true;
            } else {
                connection.close();
            }
        }
    }

    if (mDeviceConnection == null && mFcDevice != null) {
        mFcDevice.stop();
        mFcDevice = null;
    }
    return false;
}
项目:TrueTone    文件:MidiInputDevice.java   
/**
 * constructor
 *
 * @param usbDevice
 * @param usbDeviceConnection
 * @param usbInterface
 * @param midiEventListener
 * @throws IllegalArgumentException endpoint not found.
 */
public MidiInputDevice(UsbDevice usbDevice, UsbDeviceConnection usbDeviceConnection, UsbInterface usbInterface, UsbEndpoint usbEndpoint, OnMidiInputEventListener midiEventListener) throws IllegalArgumentException {
    //this.usbDevice = usbDevice;
    this.usbDeviceConnection = usbDeviceConnection;
    this.usbInterface = usbInterface;

    this.midiEventListener = midiEventListener;

    waiterThread = new WaiterThread();

    inputEndpoint = usbEndpoint;


    usbDeviceConnection.claimInterface(usbInterface, true);
    waiterThread.setPriority(8);
    waiterThread.setName("MidiInputDevice[" + usbDevice.getDeviceName() + "].WaiterThread");
    waiterThread.start();
    FragMentManager.getInstance().updateUSBConnection(true);
}
项目:DeviceConnect-Android    文件:USBMonitor.java   
/**
 * get interface
 * @param interface_id
 * @param altsetting
 * @return
 * @throws IllegalStateException
 */
public synchronized UsbInterface getInterface(final int interface_id, final int altsetting) throws IllegalStateException {
    checkConnection();
    SparseArray<UsbInterface> intfs = mInterfaces.get(interface_id);
    if (intfs == null) {
        intfs = new SparseArray<UsbInterface>();
        mInterfaces.put(interface_id, intfs);
    }
    UsbInterface intf = intfs.get(altsetting);
    if (intf == null) {
        final UsbDevice device = mWeakDevice.get();
        final int n = device.getInterfaceCount();
        for (int i = 0; i < n; i++) {
            final UsbInterface temp = device.getInterface(i);
            if ((temp.getId() == interface_id) && (temp.getAlternateSetting() == altsetting)) {
                intf = temp;
                break;
            }
        }
        if (intf != null) {
            intfs.append(altsetting, intf);
        }
    }
    return intf;
}
项目:OTGDiskBackup    文件:OtgDeviceFacade.java   
public OtgDeviceFacade(UsbInterface usbInterface, byte lun, UsbDeviceConnection usbDeviceConnection,
                       UsbDevice usbDevice) {

    this.cbwBuffer = ByteBuffer.wrap(new byte[USB_CBW_LENGTH]);
    this.cswBuffer = ByteBuffer.wrap(new byte[USB_CSW_LENGTH]);

    this.ufiCmdRequestSenseBuffer = ByteBuffer.wrap(new byte[UFI_CMD_REQUEST_SENSE_LENGTH]);
    this.ufiCmdReadCapacityBuffer = ByteBuffer.wrap(new byte[UFI_CMD_READ_CAPACITY_LENGTH]);
    this.ufiCmdReadBuffer = ByteBuffer.wrap(new byte[UFI_CMD_READ_LENGTH]);
    this.ufiCmdWriteBuffer = ByteBuffer.wrap(new byte[UFI_CMD_WRITE_LENGTH]);
    this.cbwTag = 0;
    this.sectorSize = 512;
    this.receiveBuffer = new byte[8192];
    this.usbDeviceConnection = usbDeviceConnection;
    this.lun = lun;
    initEnpoints(usbInterface);

    initCommandBuffers();
}
项目:365browser    文件:UsbMidiDeviceFactoryAndroid.java   
/**
 * 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;
        }
    }
}
项目:USBIPServerForAndroid    文件:UsbIpService.java   
public static void dumpInterfaces(UsbDevice dev) {
    for (int i = 0; i < dev.getInterfaceCount(); i++) {
        System.out.printf("%d - Iface %d (%02x/%02x/%02x)\n",
                i, dev.getInterface(i).getId(),
                dev.getInterface(i).getInterfaceClass(),
                dev.getInterface(i).getInterfaceSubclass(),
                dev.getInterface(i).getInterfaceProtocol());

        UsbInterface iface = dev.getInterface(i);
        for (int j = 0; j < iface.getEndpointCount(); j++) {
            System.out.printf("\t%d - Endpoint %d (%x/%x)\n",
                    j, iface.getEndpoint(j).getEndpointNumber(),
                    iface.getEndpoint(j).getAddress(),
                    iface.getEndpoint(j).getAttributes());
        }
    }
}
项目:android-weather-station    文件:ConnectedUsbDevice.java   
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);
    }
}
项目:RHome    文件:FTDriver.java   
private boolean setFTDIEndpoints(UsbInterface[] intf, int portNum) {
    UsbEndpoint epIn;
    UsbEndpoint epOut;

    if (intf[0] == null) {
        return false;
    }

    for (int i = 0; i < portNum; ++i) {
        epIn = intf[i].getEndpoint(0);
        epOut = intf[i].getEndpoint(1);

        if (epIn != null && epOut != null) {
            mFTDIEndpointIN[i] = epIn;
            mFTDIEndpointOUT[i] = epOut;
        } else {
            return false;
        }
    }
    return true;

}
项目:chromium_webview    文件:UsbMidiDeviceAndroid.java   
/**
 * 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);
            }
        }
    }
}
项目:music-synthesizer-for-android-old    文件:SynthesizerService.java   
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private void scanUsbMidi() {
  UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
  HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
  Log.i("synth", "USB device count=" + deviceList.size());
  for (UsbDevice device : deviceList.values()) {
    UsbInterface intf = UsbMidiDevice.findMidiInterface(device);
    if (intf != null) {
      if (usbManager.hasPermission(device)) {
        if (connectUsbMidi(device)) {
          break;
        }
      } else {
        usbDeviceNeedsPermission_ = device;
      }
    }
  }
}
项目:AndroidUvcCameras    文件:USBMonitor.java   
/**
 * close specified interface. USB device itself still keep open.
 * @param interfaceIndex
 */
public void close(final int interfaceIndex) {
    UsbInterface intf = null;
    synchronized (mInterfaces) {
        intf = mInterfaces.get(interfaceIndex);
        if (intf != null) {
            mInterfaces.delete(interfaceIndex);
            mConnection.releaseInterface(intf);
        }
    }
}
项目:InstantUpload    文件:ControllerActivity.java   
private UsbInterface findUsbInterface(UsbDevice device) {
    //Log.d (TAG, "findAdbInterface " + device.getDeviceName());
    int count = device.getInterfaceCount();
    for (int i = 0; i < count; i++) {
        UsbInterface intf = device.getInterface(i);
        Log.d (TAG, "Interface " +i + " Class " +intf.getInterfaceClass() +" Prot " +intf.getInterfaceProtocol());
        if (intf.getInterfaceClass() == 6
            //255 && intf.getInterfaceSubclass() == 66 && intf.getInterfaceProtocol() == 1
                ) {
            return intf;
        }
    }
    return null;
}
项目:InstantUpload    文件:BaselineInitiator.java   
protected UsbInterface findUsbInterface(UsbDevice device) {
    //Log.d (TAG, "findAdbInterface " + device.getDeviceName());
    int count = device.getInterfaceCount();
    for (int i = 0; i < count; i++) {
        UsbInterface intf = device.getInterface(i);
        Log.d (TAG, "Interface " +i + " Class " +intf.getInterfaceClass() +" Prot " +intf.getInterfaceProtocol());
        if (intf.getInterfaceClass() == 6
                //255 && intf.getInterfaceSubclass() == 66 && intf.getInterfaceProtocol() == 1
                ) {
            return intf;
        }
    }
    return null;
}
项目:buildAPKsSamples    文件:AdbTestActivity.java   
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;
}
项目:can4eve    文件:UsbSerialDevice.java   
public static boolean isCdcDevice(UsbDevice device)
{
    int iIndex = device.getInterfaceCount();
    for(int i=0;i<=iIndex-1;i++)
    {
        UsbInterface iface = device.getInterface(i);
        if(iface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
            return true;
    }
    return false;
}
项目:mi-firma-android    文件:SmartCardChannel.java   
/** Constructor. Inicia los EndPoints del Interfaz del dispositivo
 * @param usbDevCon
 * @param usbInterface */
protected SmartCardChannel(final UsbDeviceConnection usbDevCon, final UsbInterface usbInterface) {
    this.usbDeviceConnection = usbDevCon;
    for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
        final UsbEndpoint usbEndPoint = usbInterface.getEndpoint(i);
        if (usbEndPoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
            if (usbEndPoint.getDirection() == UsbConstants.USB_DIR_IN) {
                this.endPointIn = usbEndPoint;
            }
            else if (usbEndPoint.getDirection() == UsbConstants.USB_DIR_OUT) {
                this.endPointOut = usbEndPoint;
            }
        }
    }
}
项目:UVCCameraZxing    文件:DeviceFilter.java   
public boolean matches(final UsbDevice device) {
        if (mVendorId != -1 && device.getVendorId() != mVendorId)
            return false;
        if (mProductId != -1 && device.getProductId() != mProductId)
            return false;
/*      if (mManufacturerName != null && device.getManufacturerName() == null)
            return false;
        if (mProductName != null && device.getProductName() == null)
            return false;
        if (mSerialNumber != null && device.getSerialNumber() == null)
            return false;
        if (mManufacturerName != null && device.getManufacturerName() != null
                && !mManufacturerName.equals(device.getManufacturerName()))
            return false;
        if (mProductName != null && device.getProductName() != null
                && !mProductName.equals(device.getProductName()))
            return false;
        if (mSerialNumber != null && device.getSerialNumber() != null
                && !mSerialNumber.equals(device.getSerialNumber()))
            return false; */

        // check device class/subclass/protocol
        if (matches(device.getDeviceClass(), device.getDeviceSubclass(),
                device.getDeviceProtocol()))
            return true;

        // if device doesn't match, check the interfaces
        final int count = device.getInterfaceCount();
        for (int i = 0; i < count; i++) {
            final UsbInterface intf = device.getInterface(i);
            if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(),
                    intf.getInterfaceProtocol()))
                return true;
        }

        return false;
    }
项目:UVCCameraZxing    文件:USBMonitor.java   
/**
 * close specified interface. USB device itself still keep open.
 * @param interfaceIndex
 */
public void close(final int interfaceIndex) {
    UsbInterface intf = null;
    synchronized (mInterfaces) {
        intf = mInterfaces.get(interfaceIndex);
        if (intf != null) {
            mInterfaces.delete(interfaceIndex);
            mConnection.releaseInterface(intf);
        }
    }
}
项目:AndroidUvcCameras    文件:USBMonitor.java   
/**
 * close specified interface. USB device itself still keep open.
 * @param interfaceIndex
 */
public void close(final int interfaceIndex) {
    UsbInterface intf = null;
    synchronized (mInterfaces) {
        intf = mInterfaces.get(interfaceIndex);
        if (intf != null) {
            mInterfaces.delete(interfaceIndex);
            mConnection.releaseInterface(intf);
        }
    }
}
项目:UsbExtension    文件:UsbSerialDevice.java   
public static boolean isCdcDevice(UsbDevice device)
{
    int iIndex = device.getInterfaceCount();
    for(int i=0;i<=iIndex-1;i++)
    {
        UsbInterface iface = device.getInterface(i);
        if(iface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
            return true;
    }
    return false;
}
项目:truth-android    文件:UsbInterfaceSubject.java   
public static SubjectFactory<UsbInterfaceSubject, UsbInterface> type() {
  return new SubjectFactory<UsbInterfaceSubject, UsbInterface>() {
    @Override
    public UsbInterfaceSubject getSubject(FailureStrategy fs, UsbInterface that) {
      return new UsbInterfaceSubject(fs, that);
    }
  };
}
项目:walt    文件:BootloaderConnection.java   
@Override
public void onConnect() {
    int ifIdx = 0;

    UsbInterface iface = usbDevice.getInterface(ifIdx);

    if (usbConnection.claimInterface(iface, true)) {
        logger.log("Interface claimed successfully\n");
    } else {
        logger.log("ERROR - can't claim interface\n");
    }

    super.onConnect();
}
项目:android-u2f-bridge    文件:U2FTransportAndroidHID.java   
public U2FTransportAndroidHID(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out, int timeout) {
   this.connection = connection;
   this.dongleInterface = dongleInterface;
   this.in = in;
   this.out = out;
   this.timeout = timeout;
   transferBuffer = new byte[HID_BUFFER_SIZE];
   helper = new U2FHelper();
   random = new Random();
}