Search in sources :

Example 6 with UsbAccessory

use of android.hardware.usb.UsbAccessory in project android_frameworks_base by ParanoidAndroid.

the class UsbDeviceManager method openAccessory.

/* opens the currently attached USB accessory */
public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
    UsbAccessory currentAccessory = mHandler.getCurrentAccessory();
    if (currentAccessory == null) {
        throw new IllegalArgumentException("no accessory attached");
    }
    if (!currentAccessory.equals(accessory)) {
        String error = accessory.toString() + " does not match current accessory " + currentAccessory;
        throw new IllegalArgumentException(error);
    }
    getCurrentSettings().checkPermission(accessory);
    return nativeOpenAccessory();
}
Also used : UsbAccessory(android.hardware.usb.UsbAccessory)

Example 7 with UsbAccessory

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

the class UsbDeviceManager method openAccessory.

/* opens the currently attached USB accessory */
public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
    UsbAccessory currentAccessory = mHandler.getCurrentAccessory();
    if (currentAccessory == null) {
        throw new IllegalArgumentException("no accessory attached");
    }
    if (!currentAccessory.equals(accessory)) {
        String error = accessory.toString() + " does not match current accessory " + currentAccessory;
        throw new IllegalArgumentException(error);
    }
    getCurrentSettings().checkPermission(accessory);
    return nativeOpenAccessory();
}
Also used : UsbAccessory(android.hardware.usb.UsbAccessory)

Example 8 with UsbAccessory

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

the class SourceActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    setContentView(R.layout.source_activity);
    mLogTextView = (TextView) findViewById(R.id.logTextView);
    mLogTextView.setMovementMethod(ScrollingMovementMethod.getInstance());
    mLogger = new TextLogger();
    mPresenter = new Presenter();
    mLogger.log("Waiting for accessory display sink to be attached to USB...");
    IntentFilter filter = new IntentFilter();
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    filter.addAction(ACTION_USB_ACCESSORY_PERMISSION);
    mReceiver = new AccessoryReceiver();
    registerReceiver(mReceiver, filter);
    Intent intent = getIntent();
    if (intent.getAction().equals(UsbManager.ACTION_USB_ACCESSORY_ATTACHED)) {
        UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
        if (accessory != null) {
            onAccessoryAttached(accessory);
        }
    } else {
        UsbAccessory[] accessories = mUsbManager.getAccessoryList();
        if (accessories != null) {
            for (UsbAccessory accessory : accessories) {
                onAccessoryAttached(accessory);
            }
        }
    }
}
Also used : IntentFilter(android.content.IntentFilter) UsbAccessory(android.hardware.usb.UsbAccessory) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 9 with UsbAccessory

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

the class AccessoryChat method onResume.

@Override
public void onResume() {
    super.onResume();
    Intent intent = getIntent();
    Log.d(TAG, "intent: " + intent);
    UsbAccessory[] accessories = mUsbManager.getAccessoryList();
    UsbAccessory accessory = (accessories == null ? null : accessories[0]);
    if (accessory != null) {
        if (mUsbManager.hasPermission(accessory)) {
            openAccessory(accessory);
        } else {
            synchronized (mUsbReceiver) {
                if (!mPermissionRequestPending) {
                    mUsbManager.requestPermission(accessory, mPermissionIntent);
                    mPermissionRequestPending = true;
                }
            }
        }
    } else {
        Log.d(TAG, "mAccessory is null");
    }
}
Also used : UsbAccessory(android.hardware.usb.UsbAccessory) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 10 with UsbAccessory

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

the class SourceActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    setContentView(R.layout.source_activity);
    mLogTextView = (TextView) findViewById(R.id.logTextView);
    mLogTextView.setMovementMethod(ScrollingMovementMethod.getInstance());
    mLogger = new TextLogger();
    mPresenter = new Presenter();
    mLogger.log("Waiting for accessory display sink to be attached to USB...");
    IntentFilter filter = new IntentFilter();
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    filter.addAction(ACTION_USB_ACCESSORY_PERMISSION);
    mReceiver = new AccessoryReceiver();
    registerReceiver(mReceiver, filter);
    Intent intent = getIntent();
    if (intent.getAction().equals(UsbManager.ACTION_USB_ACCESSORY_ATTACHED)) {
        UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
        if (accessory != null) {
            onAccessoryAttached(accessory);
        }
    } else {
        UsbAccessory[] accessories = mUsbManager.getAccessoryList();
        if (accessories != null) {
            for (UsbAccessory accessory : accessories) {
                onAccessoryAttached(accessory);
            }
        }
    }
}
Also used : IntentFilter(android.content.IntentFilter) UsbAccessory(android.hardware.usb.UsbAccessory) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Aggregations

UsbAccessory (android.hardware.usb.UsbAccessory)20 PendingIntent (android.app.PendingIntent)10 Intent (android.content.Intent)10 SparseBooleanArray (android.util.SparseBooleanArray)5 IntentFilter (android.content.IntentFilter)4