(Context context, Intent intent)
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public synchronized void onReceive(Context context, Intent intent) { |
| 253 | synchronized (this) { |
| 254 | String action = intent.getAction(); |
| 255 | if (!intent.hasExtra(UsbManager.EXTRA_DEVICE)) |
| 256 | return; |
| 257 | |
| 258 | UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); |
| 259 | if (device == null) |
| 260 | return; |
| 261 | |
| 262 | if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) { |
| 263 | if (usbmanager.hasPermission(device)) |
| 264 | addAvailable(device); |
| 265 | else |
| 266 | /* always request permission which is needed to read the |
| 267 | serial number */ |
| 268 | requestPermission(device); |
| 269 | } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { |
| 270 | removeAvailable(device); |
| 271 | } else if (ACTION_USB_PERMISSION.equals(action)) { |
| 272 | if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { |
| 273 | Log.d(TAG, "permission granted for device " + device.getDeviceName()); |
| 274 | |
| 275 | //Iterate through list of Pending connections. For each entry matching with granted device, open port and remove from list |
| 276 | boolean found = false; |
| 277 | for (UsbDeviceInterface i : interfaces) { |
| 278 | if (i.isDevice(device)) { |
| 279 | found = true; |
| 280 | i.permissionGranted(); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | if (!found) |
| 285 | addAvailable(device); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | private synchronized void addAvailable(UsbDevice device) { |
| 292 | if (!isSupported(device)) |
nothing calls this directly
no test coverage detected