Class ShadowUsbDeviceConnection


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

    • ShadowUsbDeviceConnection

      public ShadowUsbDeviceConnection()
  • Method Details

    • claimInterface

      @Implementation protected boolean claimInterface(UsbInterface intf, boolean force)
    • releaseInterface

      @Implementation protected boolean releaseInterface(UsbInterface intf)
    • setInterface

      @Implementation(minSdk=21) protected boolean setInterface(UsbInterface intf)
      No-op on Robolectrict. The real implementation would return false on Robolectric and make it impossible to test callers that expect a successful result. Always returns true.
    • controlTransfer

      @Implementation protected int controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int length, int timeout)
    • controlTransfer

      @Implementation protected int controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int offset, int length, int timeout)
    • requestWait

      @Implementation protected UsbRequest requestWait()
    • requestWait

      @Implementation(minSdk=26) protected UsbRequest requestWait(long timeout) throws TimeoutException
    • bulkTransfer

      @Implementation protected int bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int offset, int length, int timeout)
    • bulkTransfer

      @Implementation protected int bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int length, int timeout)
    • readOutgoingData

      @Deprecated public void readOutgoingData(byte[] buffer) throws IOException
      prefer getOutgoingDataStream(), which allows callers to know how much data has been read and when the UsbDeviceConnection closes.
      Fills the buffer with data that was written by UsbDeviceConnection#bulkTransfer.
    • getOutgoingDataStream

      public InputStream getOutgoingDataStream()
      Provides an InputStream that allows reading data written by UsbDeviceConnection#bulkTransfer. Closing this stream has no effect. It is effectively closed during UsbDeviceConnection.releaseInterface(UsbInterface).
    • writeIncomingData

      public void writeIncomingData(byte[] data)
      Passes data that can then be read by an initialized UsbRequest#queue(ByteBuffer).