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 ofUsbManager
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ShadowUsbManager._UsbManager_
Accessor interface forUsbManager
's internals.static interface
ShadowUsbManager._UsbManagerQ_
Accessor interface forUsbManager
's internals (Q+).
-
Constructor Summary
Constructors Constructor Description ShadowUsbManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOrUpdateUsbDevice(UsbDevice usbDevice, boolean hasPermission)
Adds a USB device into available USB devices map with permission value.void
addPort(String portId)
Adds a USB port with given ID to UsbManager.void
addPort(String portId, int statusCurrentMode, int statusCurrentPowerRole, int statusCurrentDataRole, int statusSupportedRoleCombinations)
Adds a USB port with given ID andUsbPortStatus
parameters to UsbManager for Q+.void
clearPorts()
Remove all added ports from UsbManager.protected UsbAccessory[]
getAccessoryList()
protected HashMap<String,UsbDevice>
getDeviceList()
Returns a HashMap containing all USB devices currently attached.protected Object
getPorts()
protected Object
getPortStatus(Object port)
Object
getPortStatus(String portId)
Returns theUsbPortStatus
corresponding to theUsbPort
with givenportId
if present; otherwise returnsnull
.protected void
grantPermission(UsbDevice device)
protected void
grantPermission(UsbDevice device, String packageName)
protected boolean
hasPermission(UsbDevice device)
Returns true if the caller has permission to access the device.boolean
hasPermissionForPackage(UsbDevice device, String packageName)
Returns true if the given package has permission to access the device.protected ParcelFileDescriptor
openAccessory(UsbAccessory accessory)
Opens a file descriptor from a temporary file.void
removeUsbDevice(UsbDevice usbDevice)
Removes a USB device from available USB devices map.void
revokePermission(UsbDevice device, String packageName)
Revokes permission to a USB device granted to a package.void
setAttachedUsbAccessory(UsbAccessory usbAccessory)
Sets the currently attached Usb accessory returned in #getAccessoryList.protected void
setPortRoles(Object port, Object powerRole, Object dataRole)
-
-
-
Method Detail
-
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.
-
grantPermission
@Implementation(minSdk=24) @HiddenApi protected void grantPermission(UsbDevice device)
-
grantPermission
@Implementation(minSdk=25) @HiddenApi protected void grantPermission(UsbDevice device, String packageName)
-
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.
-
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) @HiddenApi protected Object getPorts()
-
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 andUsbPortStatus
parameters to UsbManager for Q+.
-
getPortStatus
@Implementation(minSdk=23) public Object getPortStatus(String portId)
Returns theUsbPortStatus
corresponding to theUsbPort
with givenportId
if present; otherwise returnsnull
.
-
getPortStatus
@Implementation(minSdk=23) @HiddenApi protected Object getPortStatus(Object port)
-
setPortRoles
@Implementation(minSdk=23) @HiddenApi protected void setPortRoles(Object port, Object powerRole, Object dataRole)
-
openAccessory
@Implementation protected ParcelFileDescriptor openAccessory(UsbAccessory accessory)
Opens a file descriptor from a temporary file.
-
-