Search in sources :

Example 11 with UsbDevice

use of android.hardware.usb.UsbDevice in project android_frameworks_base by ResurrectionRemix.

the class ReceiverActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(getIntent().getAction())) {
        final UsbDevice device = getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE);
        try {
            final MtpDocumentsProvider provider = MtpDocumentsProvider.getInstance();
            provider.openDevice(device.getDeviceId());
            final String deviceRootId = provider.getDeviceDocumentId(device.getDeviceId());
            final Uri uri = DocumentsContract.buildRootUri(MtpDocumentsProvider.AUTHORITY, deviceRootId);
            final Intent intent = new Intent(DocumentsContract.ACTION_BROWSE);
            intent.setData(uri);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.putExtra(DocumentsContract.EXTRA_FANCY_FEATURES, true);
            this.startActivity(intent);
        } catch (IOException exception) {
            Log.e(MtpDocumentsProvider.TAG, "Failed to open device", exception);
        }
    }
    finish();
}
Also used : UsbDevice(android.hardware.usb.UsbDevice) Intent(android.content.Intent) IOException(java.io.IOException) Uri(android.net.Uri)

Example 12 with UsbDevice

use of android.hardware.usb.UsbDevice in project android_frameworks_base by ResurrectionRemix.

the class UsbHostManager method openDevice.

/* Opens the specified USB device */
public ParcelFileDescriptor openDevice(String deviceName) {
    synchronized (mLock) {
        if (isBlackListed(deviceName)) {
            throw new SecurityException("USB device is on a restricted bus");
        }
        UsbDevice device = mDevices.get(deviceName);
        if (device == null) {
            // if it is not in mDevices, it either does not exist or is blacklisted
            throw new IllegalArgumentException("device " + deviceName + " does not exist or is restricted");
        }
        getCurrentSettings().checkPermission(device);
        return nativeOpenDevice(deviceName);
    }
}
Also used : UsbDevice(android.hardware.usb.UsbDevice)

Example 13 with UsbDevice

use of android.hardware.usb.UsbDevice in project android_frameworks_base by ResurrectionRemix.

the class UsbHostManager method beginUsbDeviceAdded.

/* Called from JNI in monitorUsbHostBus() to report new USB devices
       Returns true if successful, in which case the JNI code will continue adding configurations,
       interfaces and endpoints, and finally call endUsbDeviceAdded after all descriptors
       have been processed
     */
private boolean beginUsbDeviceAdded(String deviceName, int vendorID, int productID, int deviceClass, int deviceSubclass, int deviceProtocol, String manufacturerName, String productName, int version, String serialNumber) {
    if (DEBUG) {
        Slog.d(TAG, "usb:UsbHostManager.beginUsbDeviceAdded(" + deviceName + ")");
        // Audio Class Codes:
        // Audio: 0x01
        // Audio Subclass Codes:
        // undefined: 0x00
        // audio control: 0x01
        // audio streaming: 0x02
        // midi streaming: 0x03
        // some useful debugging info
        Slog.d(TAG, "usb: nm:" + deviceName + " vnd:" + vendorID + " prd:" + productID + " cls:" + deviceClass + " sub:" + deviceSubclass + " proto:" + deviceProtocol);
    }
    if (isBlackListed(deviceName) || isBlackListed(deviceClass, deviceSubclass, deviceProtocol)) {
        return false;
    }
    synchronized (mLock) {
        if (mDevices.get(deviceName) != null) {
            Slog.w(TAG, "device already on mDevices list: " + deviceName);
            return false;
        }
        if (mNewDevice != null) {
            Slog.e(TAG, "mNewDevice is not null in endUsbDeviceAdded");
            return false;
        }
        // Create version string in "%.%" format
        String versionString = Integer.toString(version >> 8) + "." + (version & 0xFF);
        mNewDevice = new UsbDevice(deviceName, vendorID, productID, deviceClass, deviceSubclass, deviceProtocol, manufacturerName, productName, versionString, serialNumber);
        mNewConfigurations = new ArrayList<UsbConfiguration>();
        mNewInterfaces = new ArrayList<UsbInterface>();
        mNewEndpoints = new ArrayList<UsbEndpoint>();
    }
    return true;
}
Also used : UsbDevice(android.hardware.usb.UsbDevice) UsbInterface(android.hardware.usb.UsbInterface) UsbEndpoint(android.hardware.usb.UsbEndpoint) UsbConfiguration(android.hardware.usb.UsbConfiguration)

Example 14 with UsbDevice

use of android.hardware.usb.UsbDevice in project android_frameworks_base by ResurrectionRemix.

the class UsbAlsaManager method dump.

//
// Logging
//
public void dump(IndentingPrintWriter pw) {
    pw.println("USB Audio Devices:");
    for (UsbDevice device : mAudioDevices.keySet()) {
        pw.println("  " + device.getDeviceName() + ": " + mAudioDevices.get(device));
    }
    pw.println("USB MIDI Devices:");
    for (UsbDevice device : mMidiDevices.keySet()) {
        pw.println("  " + device.getDeviceName() + ": " + mMidiDevices.get(device));
    }
}
Also used : UsbDevice(android.hardware.usb.UsbDevice)

Example 15 with UsbDevice

use of android.hardware.usb.UsbDevice in project android_frameworks_base by ResurrectionRemix.

the class TestUtil method findMtpDevice.

private static UsbDevice findMtpDevice(UsbManager usbManager, MtpManager manager) throws IOException {
    final HashMap<String, UsbDevice> devices = usbManager.getDeviceList();
    if (devices.size() == 0) {
        throw new IOException("Device not found.");
    }
    final UsbDevice device = devices.values().iterator().next();
    // Tries to get ownership of the device in case that another application use it.
    if (usbManager.hasPermission(device)) {
        final UsbDeviceConnection connection = usbManager.openDevice(device);
        for (int i = 0; i < device.getInterfaceCount(); i++) {
            // Since the test runs real environment, we need to call claim interface with
            // force = true to rob interfaces from other applications.
            connection.claimInterface(device.getInterface(i), true);
            connection.releaseInterface(device.getInterface(i));
        }
        connection.close();
    }
    manager.openDevice(device.getDeviceId());
    return device;
}
Also used : UsbDeviceConnection(android.hardware.usb.UsbDeviceConnection) UsbDevice(android.hardware.usb.UsbDevice) IOException(java.io.IOException)

Aggregations

UsbDevice (android.hardware.usb.UsbDevice)49 IOException (java.io.IOException)20 UsbDeviceConnection (android.hardware.usb.UsbDeviceConnection)10 Intent (android.content.Intent)9 UsbEndpoint (android.hardware.usb.UsbEndpoint)5 UsbInterface (android.hardware.usb.UsbInterface)5 MtpDevice (android.mtp.MtpDevice)5 Uri (android.net.Uri)5 PendingIntent (android.app.PendingIntent)4 IntentFilter (android.content.IntentFilter)4 UsbConfiguration (android.hardware.usb.UsbConfiguration)4 MotionEvent (android.view.MotionEvent)4 SurfaceView (android.view.SurfaceView)4 View (android.view.View)4 TextView (android.widget.TextView)4 UsbManager (android.hardware.usb.UsbManager)1 Parcelable (android.os.Parcelable)1