use of android.hardware.usb.UsbDevice in project android_frameworks_base by ParanoidAndroid.
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();
}
}
use of android.hardware.usb.UsbDevice in project android_frameworks_base by ParanoidAndroid.
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);
}
}
use of android.hardware.usb.UsbDevice in project platform_frameworks_base by android.
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);
}
}
}
use of android.hardware.usb.UsbDevice in project platform_frameworks_base by android.
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;
}
use of android.hardware.usb.UsbDevice in project android_frameworks_base by DirtyUnicorns.
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);
}
}
}
}
Aggregations