1 package com.intel.realsense.librealsense;
3 import android.app.PendingIntent;
4 import android.content.Context;
5 import android.content.Intent;
6 import android.hardware.usb.UsbDevice;
7 import android.hardware.usb.UsbManager;
8 import android.util.Log;
10 import java.lang.reflect.Array;
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
17 private static final String TAG =
"librs UsbUtilities";
20 public static boolean isIntel(UsbDevice usbDevice){
21 if (usbDevice.getVendorId() == 0x8086)
26 private static List<UsbDevice>
getUsbDevices(Context context, Integer vId) {
30 private static List<UsbDevice>
getUsbDevices(Context context, Integer vId, Integer pId) {
31 ArrayList<UsbDevice>
res =
new ArrayList<>();
32 UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
34 HashMap<String, UsbDevice> devicesMap = usbManager.getDeviceList();
35 for (Map.Entry<
String, UsbDevice>
entry : devicesMap.entrySet()) {
36 UsbDevice usbDevice =
entry.getValue();
37 if (usbDevice.getVendorId() == vId && (usbDevice.getProductId() == pId || pId == 0)) {
42 Log.w(TAG,
"getUsbDevice: failed to locate USB device, " +
"VID: " +
String.format(
"0x%04x", vId) +
", PID: " +
String.format(
"0x%04x", pId));
47 Log.d(TAG,
"hasUsbPermission");
49 if(usbDevice == null){
50 Log.w(TAG,
"hasUsbPermission: null USB device");
54 UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
55 return usbManager.hasPermission(usbDevice);
59 Log.d(TAG,
"grantUsbPermissions");
61 if(usbDevice == null){
62 Log.w(TAG,
"grantUsbPermissions: null USB device");
66 UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
67 boolean permission = usbManager.hasPermission(usbDevice);
70 Log.i(TAG,
"grantUsbPermissions:\ndevice: " + usbDevice.toString());
72 usbManager.requestPermission(usbDevice, pi);
76 private static List<UsbDevice>
getDevices(Context context) {
81 List<UsbDevice> usbDevices =
getDevices(context);
82 for (UsbDevice usbDevice : usbDevices) {
static List< UsbDevice > getUsbDevices(Context context, Integer vId, Integer pId)
::rosgraph_msgs::Log_< std::allocator< void > > Log
static void grantUsbPermissions(Context context, UsbDevice usbDevice)
::std_msgs::String_< std::allocator< void > > String
static final String ACTION_USB_PERMISSION
static List< UsbDevice > getUsbDevices(Context context, Integer vId)
static List< UsbDevice > getDevices(Context context)
static boolean hasUsbPermission(Context context, UsbDevice usbDevice)
static boolean isIntel(UsbDevice usbDevice)
static void grantUsbPermissionIfNeeded(Context context)