Package org.robolectric.shadows
Class ShadowUsbManager
java.lang.Object
org.robolectric.shadows.ShadowUsbManager
@Implements(value=android.hardware.usb.UsbManager.class,
looseSignatures=true)
public class ShadowUsbManager
extends Object
Robolectric implementation of
UsbManager.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAccessor interface forUsbManager's internals.static interfaceAccessor interface forUsbManager's internals (Q+). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOrUpdateUsbDevice(UsbDevice usbDevice, boolean hasPermission) Adds a USB device into available USB devices map with permission value.voidAdds a USB port with given ID to UsbManager.voidaddPort(String portId, int statusCurrentMode, int statusCurrentPowerRole, int statusCurrentDataRole, int statusSupportedRoleCombinations) Adds a USB port with given ID andUsbPortStatusparameters to UsbManager for Q+.voidRemove all added ports from UsbManager.protected UsbAccessory[]Returns a HashMap containing all USB devices currently attached.protected ObjectgetPorts()protected ObjectgetPortStatus(Object port) getPortStatus(String portId) Returns theUsbPortStatuscorresponding to theUsbPortwith givenportIdif present; otherwise returnsnull.voidgrantPermission(UsbAccessory accessory) Grants permission for the accessory.protected voidgrantPermission(UsbDevice device) protected voidgrantPermission(UsbDevice device, String packageName) protected booleanhasPermission(UsbAccessory accessory) Returns true if the caller has permission to access the accessory.protected booleanhasPermission(UsbDevice device) Returns true if the caller has permission to access the device.booleanhasPermissionForPackage(UsbAccessory accessory, String packageName) Returns true if the given package has permission to access the device.booleanhasPermissionForPackage(UsbDevice device, String packageName) Returns true if the given package has permission to access the device.protected ParcelFileDescriptoropenAccessory(UsbAccessory accessory) Opens a file descriptor from a temporary file.protected UsbDeviceConnectionopenDevice(UsbDevice device) Opens a file descriptor from a temporary file.voidremoveUsbDevice(UsbDevice usbDevice) Removes a USB device from available USB devices map.voidrevokePermission(UsbAccessory accessory, String packageName) Revokes permission to a USB accessory granted to a package.voidrevokePermission(UsbDevice device, String packageName) Revokes permission to a USB device granted to a package.voidsetAttachedUsbAccessory(UsbAccessory usbAccessory) Sets the currently attached Usb accessory returned in #getAccessoryList.protected voidsetPortRoles(Object port, Object powerRole, Object dataRole)
-
Constructor Details
-
ShadowUsbManager
public ShadowUsbManager()
-
-
Method Details
-
hasPermission
Returns true if the caller has permission to access the device. -
hasPermissionForPackage
Returns true if the given package has permission to access the device. -
hasPermission
Returns true if the caller has permission to access the accessory. -
hasPermissionForPackage
Returns true if the given package has permission to access the device. -
grantPermission
-
grantPermission
@Implementation(minSdk=25) @HiddenApi protected void grantPermission(UsbDevice device, String packageName) -
grantPermission
Grants permission for the accessory. -
revokePermission
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
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
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
-
setAttachedUsbAccessory
Sets the currently attached Usb accessory returned in #getAccessoryList. -
addOrUpdateUsbDevice
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
Removes a USB device from available USB devices map. -
getPorts
-
clearPorts
public void clearPorts()Remove all added ports from UsbManager. -
addPort
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 andUsbPortStatusparameters to UsbManager for Q+. -
getPortStatus
Returns theUsbPortStatuscorresponding to theUsbPortwith givenportIdif present; otherwise returnsnull. -
getPortStatus
-
setPortRoles
@Implementation(minSdk=23) @HiddenApi protected void setPortRoles(Object port, Object powerRole, Object dataRole) -
openDevice
Opens a file descriptor from a temporary file. -
openAccessory
Opens a file descriptor from a temporary file.
-