android.hardware.usb.UsbManager Java Examples

The following examples show how to use android.hardware.usb.UsbManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UsbUtils.java    From libcommon with Apache License 2.0 8 votes vote down vote up
/**
 * 接続されているUSBの機器リストをLogCatに出力
 * @param context
 */
public static void dumpDevices(@NonNull final Context context) {
	final UsbManager usbManager = ContextUtils.requireSystemService(context, UsbManager.class);
	final HashMap<String, UsbDevice> list = usbManager.getDeviceList();
	if ((list != null) && !list.isEmpty()) {
		final Set<String> keys = list.keySet();
		if (keys != null && keys.size() > 0) {
			final StringBuilder sb = new StringBuilder();
			for (final String key: keys) {
				final UsbDevice device = list.get(key);
				final int num_interface = device != null ? device.getInterfaceCount() : 0;
				sb.setLength(0);
				for (int i = 0; i < num_interface; i++) {
					sb.append(String.format(Locale.US, "interface%d:%s",
						i, device.getInterface(i).toString()));
				}
				Log.i(TAG, "key=" + key + ":" + device + ":" + sb.toString());
			}
		} else {
			Log.i(TAG, "no device");
		}
	} else {
		Log.i(TAG, "no device");
	}
}
 
Example #2
Source File: AbstractUSBHIDService.java    From USBHIDTerminal with Apache License 2.0 6 votes vote down vote up
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();
	if (Consts.ACTION_USB_PERMISSION.equals(action)) {
		setDevice(intent);
	}
	if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
		setDevice(intent);
		if (device == null) {
			onDeviceConnected(device);
		}
	}
	if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
		if (device != null) {
			device = null;
			if (usbThreadDataReceiver != null) {
				usbThreadDataReceiver.stopThis();
			}
			eventBus.post(new DeviceDetachedEvent());
			onDeviceDisconnected(device);
		}
	}
}
 
Example #3
Source File: SyncingService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
static public boolean isG4Connected(Context c){
    UsbManager manager = (UsbManager) c.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Log.i("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
                && device.getDeviceProtocol() == 0){
            Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: MainActivity.java    From android-stm32-dfu-programmer with Apache License 2.0 6 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();

    /* Setup USB */
    usb = new Usb(this);
    usb.setUsbManager((UsbManager) getSystemService(Context.USB_SERVICE));
    usb.setOnUsbChangeListener(this);

    // Handle two types of intents. Device attachment and permission
    registerReceiver(usb.getmUsbReceiver(), new IntentFilter(Usb.ACTION_USB_PERMISSION));
    registerReceiver(usb.getmUsbReceiver(), new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED));
    registerReceiver(usb.getmUsbReceiver(), new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED));


    // Handle case where USB device is connected before app launches;
    // hence ACTION_USB_DEVICE_ATTACHED will not occur so we explicitly call for permission
    usb.requestPermission(this, Usb.USB_VENDOR_ID, Usb.USB_PRODUCT_ID);
}
 
Example #5
Source File: InitCH340.java    From USB-OTG-CH340-UART-interface with Apache License 2.0 6 votes vote down vote up
/**
 * initialize ch340 parameters.
 *
 * @param context Application context.
 */
public static void initCH340(Context context) {
    if (context == null) return;
    Context appContext = context.getApplicationContext();
    mUsbManager = (UsbManager) appContext.getSystemService(Context.USB_SERVICE);
    if (mUsbManager != null) {
        HashMap<String, UsbDevice> deviceHashMap = mUsbManager.getDeviceList();
        LogUtils.e(TAG, "deviceHashMap.size()=" + deviceHashMap.size());
        for (UsbDevice device : deviceHashMap.values()) {
            LogUtils.i(TAG, "ProductId:" + device.getProductId() + ",VendorId:" + device.getVendorId());
            if (device.getProductId() == 29987 && device.getVendorId() == 6790) {
                mUsbDevice = device;
                if (mUsbManager.hasPermission(device)) {
                    loadDriver(appContext, mUsbManager);
                } else {
                    if (listener != null) {
                        listener.result(false);
                    }
                }
                break;
            }
        }
    }
}
 
Example #6
Source File: GoldLeaf.java    From ns-usbloader-mobile with GNU General Public License v3.0 6 votes vote down vote up
GoldLeaf(ResultReceiver resultReceiver,
         Context context,
         UsbDevice usbDevice,
         UsbManager usbManager,
         ArrayList<NSPElement> nspElements) throws Exception {
    super(resultReceiver, context, usbDevice, usbManager);

    this.nspElements = nspElements;
    String fileName;
    InputStream fileInputStream;

    fileInputStream = context.getContentResolver().openInputStream(nspElements.get(0).getUri());
    fileName = nspElements.get(0).getFilename();
    pfsElement = new PFSProvider(fileInputStream, fileName);
    if (! pfsElement.init())
        throw new Exception("GL File provided have incorrect structure and won't be uploaded.");
}
 
Example #7
Source File: DevicesFragment.java    From usb-serial-for-android with GNU Lesser General Public License v2.1 6 votes vote down vote up
void refresh() {
    UsbManager usbManager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE);
    UsbSerialProber usbDefaultProber = UsbSerialProber.getDefaultProber();
    UsbSerialProber usbCustomProber = CustomProber.getCustomProber();
    listItems.clear();
    for(UsbDevice device : usbManager.getDeviceList().values()) {
        UsbSerialDriver driver = usbDefaultProber.probeDevice(device);
        if(driver == null) {
            driver = usbCustomProber.probeDevice(device);
        }
        if(driver != null) {
            for(int port = 0; port < driver.getPorts().size(); port++)
                listItems.add(new ListItem(device, port, driver));
        } else {
            listItems.add(new ListItem(device, 0, null));
        }
    }
    listAdapter.notifyDataSetChanged();
}
 
Example #8
Source File: BaseUsbConnection.java    From walt with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

    if (usbDevice == null) {
        logger.log("USB device was not properly opened");
        return;
    }

    if(intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false) &&
            usbDevice.equals(intent.getParcelableExtra(UsbManager.EXTRA_DEVICE))){
        usbConnection = usbManager.openDevice(usbDevice);

        BaseUsbConnection.this.context.registerReceiver(disconnectReceiver,
                new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED));

        onConnect();

        broadcastManager.sendBroadcast(new Intent(getConnectIntent()));
    } else {
        logger.log("Could not get permission to open the USB device");
    }
    BaseUsbConnection.this.context.unregisterReceiver(respondToUsbPermission);
}
 
Example #9
Source File: PtpUsbService.java    From remoteyourcam-usb with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (ACTION_USB_PERMISSION.equals(action)) {
        unregisterPermissionReceiver(context);
        synchronized (this) {
            UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

            if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                connect(context, device);
            } else {
                //TODO report
            }
        }
    }
}
 
Example #10
Source File: UsbDeviceInfo.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * USB機器情報(ベンダー名・製品名・バージョン・シリアル等)を取得する
 * @param manager
 * @param device
 * @param out
 * @return
 */
@SuppressLint("NewApi")
public static UsbDeviceInfo getDeviceInfo(
	@NonNull final UsbManager manager,
	@Nullable final UsbDevice device, @Nullable final UsbDeviceInfo out) {

	final UsbDeviceConnection connection
		= (device != null && manager.hasPermission(device))
			? manager.openDevice(device) : null;

	try {
		return getDeviceInfo(connection, device, out);
	} finally {
		if (connection != null) {
			connection.close();
		}
	}
}
 
Example #11
Source File: USBConnectionManager.java    From Android-Bridge-App with MIT License 6 votes vote down vote up
public void checkForDJIAccessory() {
    mUsbManager = (UsbManager) BridgeApplication.getInstance().getSystemService(Context.USB_SERVICE);
    UsbAccessory[] accessoryList = mUsbManager.getAccessoryList();
    if (accessoryList != null
        && accessoryList.length > 0
        && !TextUtils.isEmpty(accessoryList[0].getManufacturer())
        && accessoryList[0].getManufacturer().equals("DJI")) {
        BridgeApplication.getInstance().getBus().post(new RCConnectionEvent(true));
        //Check permission
        mAccessory = accessoryList[0];
        if (mUsbManager.hasPermission(mAccessory)) {
            Log.d(TAG, "RC CONNECTED");
        } else {
            Log.d(TAG, "NO Permission to USB Accessory");
            DJILogger.e(TAG, "NO Permission to USB Accessory");
            //mUsbManager.requestPermission(mAccessory, null);
        }
    } else {
        BridgeApplication.getInstance().getBus().post(new RCConnectionEvent(false));
        Log.d(TAG, "RC DISCONNECTED");
    }
}
 
Example #12
Source File: MainActivity.java    From USB-OTG-CH340-UART-interface with Apache License 2.0 6 votes vote down vote up
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (ACTION_USB_PERMISSION.equals(action)) {
        synchronized (this) {
            UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
            if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                if (device != null) {
                    Toast.makeText(MainActivity.this, "EXTRA_PERMISSION_GRANTED~", Toast.LENGTH_SHORT).show();
                    InitCH340.loadDriver(MyApplication.getContext(), InitCH340.getmUsbManager());
                }
            } else {
                Toast.makeText(MainActivity.this, "EXTRA_PERMISSION_GRANTED null!", Toast.LENGTH_SHORT).show();
            }
        }
    }
}
 
Example #13
Source File: UsbService.java    From UsbSerial with MIT License 6 votes vote down vote up
@Override
public void onCreate() {
    this.context = this;
    UsbService.SERVICE_CONNECTED = true;
    setFilter();
    usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    builder = SerialPortBuilder.createSerialPortBuilder(this);

    boolean ret = builder.openSerialPorts(context, BAUD_RATE,
            UsbSerialInterface.DATA_BITS_8,
            UsbSerialInterface.STOP_BITS_1,
            UsbSerialInterface.PARITY_NONE,
            UsbSerialInterface.FLOW_CONTROL_OFF);

    if(!ret)
        Toast.makeText(context, "No Usb serial ports available", Toast.LENGTH_SHORT).show();
}
 
Example #14
Source File: FTDI_USB_Handler.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();

	if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
		UsbDevice dev = (UsbDevice) intent
				.getParcelableExtra(UsbManager.EXTRA_DEVICE);
		if (dev != null) {
			if (String.format("%04X:%04X", dev.getVendorId(), dev.getProductId())
					.equals(VID_PID)) {
				if (usbIf != null && conn != null) {
					conn.releaseInterface(usbIf);
					conn.close();
				}
			}
		}
	}
}
 
Example #15
Source File: SnifferDeviceService.java    From sniffer154 with GNU General Public License v3.0 6 votes vote down vote up
private void setupUsbDevice() {
	mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
	mSerialDevice = UsbSerialProber.acquire(mUsbManager);
	if (mSerialDevice == null) {
		Toast.makeText(this, "Cannot find USB device", Toast.LENGTH_SHORT)
				.show();
	} else {
		try {
			mSerialDevice.open();
		} catch (IOException e) {
			Log.e(TAG, "Error setting up device: " + e.getMessage(), e);
			try {
				mSerialDevice.close();
			} catch (IOException e2) {
				// Ignore.
			}
			mSerialDevice = null;
			return;
		}
	}
	mSerialIoManager = new SerialInputOutputManager(mSerialDevice,
			mListener);
	mExecutor.submit(mSerialIoManager);
}
 
Example #16
Source File: RequestLoginActivity.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    mActiveNetwork.setText(getString(R.string.id_s_network, networkData.getName()));

    final Intent intent = getIntent();

    if (ACTION_USB_ATTACHED.equalsIgnoreCase(intent.getAction())) {
        onUsbAttach(intent.getParcelableExtra(UsbManager.EXTRA_DEVICE));
    }

    if (mUsb != null || mInLedgerDashboard) {
        // Continue displaying instructions until the user opens the
        // correct wallet app, or log in completes/errors out
        return;
    }

    // No hardware wallet, jump to PIN or 1st screen entry
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    if (AuthenticationHandler.hasPin(this))
        startActivityForResult(new Intent(this, PinActivity.class), 0);
    else
        startActivityForResult(new Intent(this, FirstScreenActivity.class), 0);
}
 
Example #17
Source File: UsbTools.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (ACTION_USB_PERMISSION.equals(intent.getAction())) {
        synchronized (this) {
            final UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

            if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                if (device != null) {
                    onGranted(device);
                }
            } else {
                Log.d(TAG, "permission denied for device " + device);
            }
            xdrip.getAppContext().unregisterReceiver(this);
        }
    }
}
 
Example #18
Source File: FaBoFirmwareFragment.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (StkWriter.ACTION_USB_PERMISSION.equals(action)) {

    } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
        // USBを閉じる
        /*
        mStkWriter.closeUsb();
        mTextViewComment.setText(R.string.disconnect_usb);
        mButtonConnect.setEnabled(false);
        mButtonSend.setVisibility(Button.INVISIBLE);
        mButtonBack.setVisibility(Button.INVISIBLE);
        */
    }
}
 
Example #19
Source File: ReactUsbSerialModule.java    From react-native-usbserial with MIT License 6 votes vote down vote up
@ReactMethod
public void openDeviceAsync(ReadableMap deviceObject, Promise p) {

    try {
        int prodId = deviceObject.getInt("productId");
        UsbManager manager = getUsbManager();
        UsbSerialDriver driver = getUsbSerialDriver(prodId, manager);

        if (manager.hasPermission(driver.getDevice())) {
            WritableMap usd = createUsbSerialDevice(manager, driver);

            p.resolve(usd);
        } else {
            requestUsbPermission(manager, driver.getDevice(), p);
        }

    } catch (Exception e) {
        p.reject(e);
    }
}
 
Example #20
Source File: SyncingService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public UsbDevice findDexcom() {
    Log.i("CALIBRATION-CHECK-IN: ", "Searching for dexcom");
    mUsbManager = (UsbManager) getApplicationContext().getSystemService(Context.USB_SERVICE);
    Log.i("USB MANAGER = ", mUsbManager.toString());
    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
    Log.i("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
                && device.getDeviceProtocol() == 0){
            dexcom = device;
            Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return device;
        } else {
            Log.w("CALIBRATION-CHECK-IN: ", "that was not a dexcom (I dont think)");
        }
    }
    return null;
}
 
Example #21
Source File: LoginActivity.java    From xmrwallet with Apache License 2.0 6 votes vote down vote up
private void registerDetachReceiver() {
    detachReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
                unregisterDetachReceiver();
                final UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
                Timber.i("Ledger detached!");
                if (device != null)
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(LoginActivity.this,
                                    getString(R.string.toast_ledger_detached, device.getProductName()),
                                    Toast.LENGTH_SHORT)
                                    .show();
                        }
                    });
                Ledger.disconnect();
                onLedgerAction();
            }
        }
    };

    registerReceiver(detachReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED));
}
 
Example #22
Source File: USBMonitor.java    From AndroidUSBCamera with Apache License 2.0 6 votes vote down vote up
/**
 * register BroadcastReceiver to monitor USB events
 * @throws IllegalStateException
 */
public synchronized void register() throws IllegalStateException {
	if (destroyed) throw new IllegalStateException("already destroyed");
	if (mPermissionIntent == null) {
		if (DEBUG) Log.i(TAG, "register:");
		final Context context = mWeakContext.get();
		if (context != null) {
			mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0);
			final IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
			// ACTION_USB_DEVICE_ATTACHED never comes on some devices so it should not be added here
			filter.addAction(ACTION_USB_DEVICE_ATTACHED);
			filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
			context.registerReceiver(mUsbReceiver, filter);
		}
		// start connection check
		mDeviceCounts = 0;
		mAsyncHandler.postDelayed(mDeviceCheckRunnable, 1000);
	}
}
 
Example #23
Source File: ConnectRcManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public synchronized void connectRC(Context mContext) {
    if (!this.isTryConnect) {
        this.isTryConnect = true;
        UsbManager usbManager = (UsbManager) mContext.getSystemService("usb");
        this.mPermissionIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_USB_PERMISSION), 0);
        if (usbManager != null) {
            UsbAccessory[] accessories = usbManager.getAccessoryList();
            UsbAccessory accessory = accessories == null ? null : accessories[0];
            if (accessory != null) {
                if (usbManager.hasPermission(accessory)) {
                    CommunicationManager.getCommunicationManager().setAccessory(accessory);
                    CommunicationManager.getCommunicationManager().startConnectThread(mContext, ConnectType.Aoa);
                } else if (!this.isRequestPermission) {
                    usbManager.requestPermission(accessory, this.mPermissionIntent);
                    this.isRequestPermission = true;
                }
            }
        }
        this.isTryConnect = false;
    }
}
 
Example #24
Source File: Ledger.java    From xmrwallet with Apache License 2.0 5 votes vote down vote up
private Ledger(UsbManager usbManager, UsbDevice usbDevice) throws IOException {
    final BTChipTransport transport = BTChipTransportAndroidHID.open(usbManager, usbDevice);
    Timber.d("transport opened = %s", transport.toString());
    transport.setDebug(BuildConfig.DEBUG);
    this.transport = transport;
    this.name = usbDevice.getManufacturerName() + " " + usbDevice.getProductName();
    initKey();
}
 
Example #25
Source File: UsbIpService.java    From USBIPServerForAndroid with GNU General Public License v3.0 5 votes vote down vote up
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();
	if (ACTION_USB_PERMISSION.equals(action)) {
		UsbDevice dev = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

		synchronized (dev) {
			permission.put(dev.getDeviceId(), intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false));
			dev.notifyAll();
		}
	}
}
 
Example #26
Source File: UsbSerialProber.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Finds and builds all possible {@link UsbSerialDriver UsbSerialDrivers}
 * from the currently-attached {@link UsbDevice} hierarchy. This method does
 * not require permission from the Android USB system, since it does not
 * open any of the devices.
 *
 * @param usbManager
 * @return a list, possibly empty, of all compatible drivers
 */
public List<UsbSerialDriver> findAllDrivers(final UsbManager usbManager) {
    final List<UsbSerialDriver> result = new ArrayList<UsbSerialDriver>();

    for (final UsbDevice usbDevice : usbManager.getDeviceList().values()) {
        final UsbSerialDriver driver = probeDevice(usbDevice);
        if (driver != null) {
            result.add(driver);
        }
    }
    return result;
}
 
Example #27
Source File: ConnectManager.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
public boolean isADBDeviceIn() {
    final int usbClassAdb = 255;
    final int usbSubClassAdb = 66;
    final int usbProtocolAdb = 1;


    UsbManager mUsbManager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
    if (null == mUsbManager) {
        return  false;
    }

    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.d( TAG, "device count=" + deviceList.size() );

    int nInedex = 0;
    boolean bGetADBDevice = false;
    while (deviceIterator.hasNext()) {
        UsbDevice device = deviceIterator.next();
        int interfaceCount = device.getInterfaceCount();
        Log.d( TAG, "Device Info index ::" + nInedex + "Interface Count ::" + interfaceCount );
        for (int interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) {
            UsbInterface usbInterface = device.getInterface(interfaceIndex);
            Log.d( TAG, "Interface  ::[Class=" + usbInterface.getInterfaceClass() + "][Sub Class="
                    + usbInterface.getInterfaceSubclass()
                    + "][Protocol=" + usbInterface.getInterfaceProtocol() + "]");

            if ((usbClassAdb == usbInterface.getInterfaceClass())
                    && (usbSubClassAdb == usbInterface.getInterfaceSubclass())
                    && (usbProtocolAdb == usbInterface.getInterfaceProtocol())) {
                Log.d( TAG, "GetADB Initeface !!!!!!" );
                bGetADBDevice  = true;
                break;
            }
        }
        ++nInedex;
    }
    return  bGetADBDevice;
}
 
Example #28
Source File: UsbMidiDeviceAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #29
Source File: RequestLoginActivity.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mInLedgerDashboard = false;
    mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);

    mInstructionsText = UI.find(this, R.id.first_login_instructions);
    mActiveNetwork = UI.find(this, R.id.activeNetwork);
    networkData = getNetwork();
}
 
Example #30
Source File: FTDI_USB_Handler.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
private void enumerate() {
	l("enumerating");

	UsbManager usbman = (UsbManager) activity
			.getSystemService(Context.USB_SERVICE);

	HashMap<String, UsbDevice> devlist = usbman.getDeviceList();
	Iterator<UsbDevice> deviter = devlist.values().iterator();
	PendingIntent pi = PendingIntent.getBroadcast(activity, 0, new Intent(
			ACTION_USB_PERMISSION), 0);

	while (deviter.hasNext()) {
		UsbDevice d = deviter.next();
		l("Found device: "
				+ String.format("%04X:%04X", d.getVendorId(), d.getProductId()));
		if (String.format("%04X:%04X", d.getVendorId(), d.getProductId()).equals(
				VID_PID)) {
			// we need to upload the hex file, first request permission
			l("Device under: " + d.getDeviceName());
			activity.registerReceiver(mPermissionReceiver, new IntentFilter(
					ACTION_USB_PERMISSION));
			if (!usbman.hasPermission(d))
				usbman.requestPermission(d, pi);
			else
				init_USB(d);

			// init_USB(d);
			break;
		}
	}
	l("no more devices found");
}