Search in sources :

Example 41 with UsbDevice

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

the class UsbHostManager method usbDeviceRemoved.

/* Called from JNI in monitorUsbHostBus to report USB device removal */
private void usbDeviceRemoved(String deviceName) {
    synchronized (mLock) {
        UsbDevice device = mDevices.remove(deviceName);
        if (device != null) {
            mUsbAlsaManager.usbDeviceRemoved(device);
            getCurrentSettings().deviceDetached(device);
        }
    }
}
Also used : UsbDevice(android.hardware.usb.UsbDevice)

Example 42 with UsbDevice

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

the class SinkActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    setContentView(R.layout.sink_activity);
    mLogTextView = (TextView) findViewById(R.id.logTextView);
    mLogTextView.setMovementMethod(ScrollingMovementMethod.getInstance());
    mLogger = new TextLogger();
    mFpsTextView = (TextView) findViewById(R.id.fpsTextView);
    mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView);
    mSurfaceView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            sendHidTouch(event);
            return true;
        }
    });
    mLogger.log("Waiting for accessory display source to be attached to USB...");
    IntentFilter filter = new IntentFilter();
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    filter.addAction(ACTION_USB_DEVICE_PERMISSION);
    mReceiver = new DeviceReceiver();
    registerReceiver(mReceiver, filter);
    Intent intent = getIntent();
    if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
        UsbDevice device = intent.<UsbDevice>getParcelableExtra(UsbManager.EXTRA_DEVICE);
        if (device != null) {
            onDeviceAttached(device);
        }
    } else {
        Map<String, UsbDevice> devices = mUsbManager.getDeviceList();
        if (devices != null) {
            for (UsbDevice device : devices.values()) {
                onDeviceAttached(device);
            }
        }
    }
}
Also used : IntentFilter(android.content.IntentFilter) UsbDevice(android.hardware.usb.UsbDevice) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SurfaceView(android.view.SurfaceView) View(android.view.View) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent)

Example 43 with UsbDevice

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

the class TestUtil method setupMtpDevice.

/**
     * Requests permission for a MTP device and returns the first MTP device that has at least one
     * storage.
     */
static UsbDevice setupMtpDevice(TestResultInstrumentation instrumentation, UsbManager usbManager, MtpManager manager) {
    while (true) {
        try {
            final UsbDevice device = findMtpDevice(usbManager, manager);
            waitForStorages(instrumentation, manager, device.getDeviceId());
            return device;
        } catch (IOException exp) {
            instrumentation.show(Objects.toString(exp.getMessage()));
            SystemClock.sleep(1000);
            // again.
            continue;
        }
    }
}
Also used : UsbDevice(android.hardware.usb.UsbDevice) IOException(java.io.IOException)

Example 44 with UsbDevice

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

the class DeviceDisconnectedReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    String deviceName = device.getDeviceName();
    Log.d(TAG, "ACTION_USB_DEVICE_DETACHED " + deviceName);
    // close our activity if the device it is displaying is disconnected
    if (deviceName.equals(mDeviceName)) {
        mActivity.finish();
    }
}
Also used : UsbDevice(android.hardware.usb.UsbDevice)

Example 45 with UsbDevice

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

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