Class ShadowUsbManager

java.lang.Object
org.robolectric.shadows.ShadowUsbManager

@Implements(android.hardware.usb.UsbManager.class) public class ShadowUsbManager extends Object
Robolectric implementation of UsbManager.
  • Constructor Details

    • ShadowUsbManager

      public ShadowUsbManager()
  • Method Details

    • reset

      @Resetter public static void reset()
    • hasPermission

      @Implementation protected boolean hasPermission(UsbDevice device)
      Returns true if the caller has permission to access the device.
    • hasPermissionForPackage

      public boolean hasPermissionForPackage(UsbDevice device, String packageName)
      Returns true if the given package has permission to access the device.
    • hasPermission

      @Implementation protected boolean hasPermission(UsbAccessory accessory)
      Returns true if the caller has permission to access the accessory.
    • hasPermissionForPackage

      public boolean hasPermissionForPackage(UsbAccessory accessory, String packageName)
      Returns true if the given package has permission to access the device.
    • grantPermission

      @Implementation(minSdk=24) @HiddenApi protected void grantPermission(UsbDevice device)
    • grantPermission

      @Implementation(minSdk=25) @HiddenApi protected void grantPermission(UsbDevice device, String packageName)
    • grantPermission

      public void grantPermission(UsbAccessory accessory)
      Grants permission for the accessory.
    • revokePermission

      public void revokePermission(UsbDevice device, String packageName)
      Revokes permission to a USB device granted to a package. This method does nothing if the package doesn't have permission to access the device.
    • revokePermission

      public void revokePermission(UsbAccessory accessory, String packageName)
      Revokes permission to a USB accessory granted to a package. This method does nothing if the package doesn't have permission to access the accessory.
    • getDeviceList

      @Implementation protected HashMap<String,UsbDevice> getDeviceList()
      Returns a HashMap containing all USB devices currently attached. USB device name is the key for the returned HashMap. The result will be empty if no devices are attached, or if USB host mode is inactive or unsupported.
    • getAccessoryList

      @Implementation protected UsbAccessory[] getAccessoryList()
    • setAttachedUsbAccessory

      public void setAttachedUsbAccessory(UsbAccessory usbAccessory)
      Sets the currently attached Usb accessory returned in #getAccessoryList.
    • addOrUpdateUsbDevice

      public void addOrUpdateUsbDevice(UsbDevice usbDevice, boolean hasPermission)
      Adds a USB device into available USB devices map with permission value. If the USB device already exists, updates the USB device with new permission value.
    • removeUsbDevice

      public void removeUsbDevice(UsbDevice usbDevice)
      Removes a USB device from available USB devices map.
    • getPorts

      @Implementation(minSdk=23, maxSdk=28) @HiddenApi protected Object getPorts()
    • getPortsFromQ

      @Implementation(minSdk=29, methodName="getPorts") @HiddenApi protected List<?> getPortsFromQ()
    • clearPorts

      public void clearPorts()
      Remove all added ports from UsbManager.
    • addPort

      public void addPort(String portId)
      Adds a USB port with given ID to UsbManager.
    • addPort

      public void addPort(String portId, int statusCurrentMode, int statusCurrentPowerRole, int statusCurrentDataRole, int statusSupportedRoleCombinations)
      Adds a USB port with given ID and UsbPortStatus parameters to UsbManager for Q+.
    • getPortStatus

      public Object getPortStatus(String portId)
      Returns the UsbPortStatus corresponding to the UsbPort with given portId if present; otherwise returns null.
    • getPortStatus

      @Implementation(minSdk=23) @HiddenApi protected Object getPortStatus(Object port)
    • setPortRoles

      @Implementation(minSdk=23) @HiddenApi protected void setPortRoles(Object port, int powerRole, int dataRole)
    • openDevice

      @Implementation protected UsbDeviceConnection openDevice(UsbDevice device)
      Opens a file descriptor from a temporary file.
    • openAccessory

      @Implementation protected ParcelFileDescriptor openAccessory(UsbAccessory accessory)
      Opens a file descriptor from a temporary file.