adb.common module

Common code for ADB and Fastboot.

Common usb browsing and usb communication.

Contents

adb.common.DEFAULT_TIMEOUT_MS = 10000

Default timeout

adb.common.GetInterface(setting)[source]

Get the class, subclass, and protocol for the given USB setting.

_images/adb.common.GetInterface.CALLER_GRAPH.svg
Parameters

setting (TODO) – TODO

Returns

  • TODO – TODO

  • TODO – TODO

  • TODO – TODO

adb.common.InterfaceMatcher(clazz, subclass, protocol)[source]

Returns a matcher that returns the setting with the given interface.

_images/adb.common.InterfaceMatcher.CALL_GRAPH.svg
Parameters
  • clazz (TODO) – TODO

  • subclass (TODO) – TODO

  • protocol (TODO) – TODO

Returns

Matcher – TODO

Return type

function

class adb.common.TcpHandle(serial, timeout_ms=None)[source]

Bases: object

TCP connection object.

Provides same interface as UsbHandle.

_images/adb.common.TcpHandle.__init__.CALLER_GRAPH.svg
Parameters
  • serial (str, bytes, bytearray) – Android device serial of the form “host” or “host:port”. (Host may be an IP address or a host name.)

  • timeout_ms (TODO, None) – TODO

_connection

TODO

Type

TODO, None

_serial_number

<host>:<port>

Type

str

_timeout_ms

TODO

Type

float, None

host

TODO

Type

str, TODO

port

TODO

Type

str, int, TODO

BulkRead(numbytes, timeout=None)[source]

TODO

_images/adb.common.TcpHandle.BulkRead.CALL_GRAPH.svg
Parameters
  • numbytes (int) – TODO

  • timeout_ms (TODO, None) – TODO

Returns

TODO

Return type

TODO

Raises

adb.usb_exceptions.TcpTimeoutException – Reading timed out.

BulkWrite(data, timeout=None)[source]

TODO

_images/adb.common.TcpHandle.BulkWrite.CALL_GRAPH.svg
Parameters
  • data (TODO) – TODO

  • timeout (TODO, None) – TODO

Returns

TODO

Return type

TODO

Raises

adb.usb_exceptions.TcpTimeoutException – Sending data timed out. No data was sent.

Close()[source]

TODO

Returns

TODO

Return type

TODO

Timeout(timeout_ms)[source]

TODO

_images/adb.common.TcpHandle.Timeout.CALLER_GRAPH.svg
Parameters

timeout_ms (TODO) – TODO

Returns

TODO

Return type

float

TimeoutSeconds(timeout_ms)[source]

TODO

_images/adb.common.TcpHandle.TimeoutSeconds.CALL_GRAPH.svg_images/adb.common.TcpHandle.TimeoutSeconds.CALLER_GRAPH.svg
Parameters

timeout_ms (TODO) – TODO

Returns

TODO

Return type

float

_connect()[source]

TODO

_images/adb.common.TcpHandle._connect.CALL_GRAPH.svg
property serial_number

TODO

_images/adb.common.TcpHandle.serial_number.CALLER_GRAPH.svg
Returns

self._serial_number – The _serial_number attribute (<host>:<port>)

Return type

str

class adb.common.UsbHandle(device, setting, usb_info=None, timeout_ms=None)[source]

Bases: object

USB communication object. Not thread-safe.

Handles reading and writing over USB with the proper endpoints, exceptions, and interface claiming.

Important methods: * UsbHandle.FlushBuffers * UsbHandle.BulkRead * UsbHandle.BulkWrite(bytes data)

_images/adb.common.UsbHandle.__init__.CALLER_GRAPH.svg
Parameters
  • device (TODO) – libusb_device to connect to.

  • setting (TODO) – libusb setting with the correct endpoints to communicate with.

  • usb_info (TODO, None) – String describing the usb path/serial/device, for debugging.

  • timeout_ms (TODO, None) – Timeout in milliseconds for all I/O.

_device

libusb_device to connect to.

Type

TODO

_handle

TODO

Type

TODO

_interface_number

TODO

Type

TODO

_max_read_packet_len

TODO

Type

TODO

_read_endpoint

TODO

Type

TODO

_setting

libusb setting with the correct endpoints to communicate with.

Type

TODO

_timeout_ms

Timeout in milliseconds for all I/O.

Type

TODO, None

_usb_info

String describing the usb path/serial/device, for debugging.

Type

TODO

_write_endpoint

TODO

Type

TODO, None

BulkRead(length, timeout_ms=None)[source]

TODO

_images/adb.common.UsbHandle.BulkRead.CALL_GRAPH.svg_images/adb.common.UsbHandle.BulkRead.CALLER_GRAPH.svg
Parameters
  • length (int) – TODO

  • timeout_ms (TODO, None) – TODO

Returns

TODO

Return type

bytearray

Raises

usb_exceptions.ReadFailedError – Could not receive data

BulkReadAsync(length, timeout_ms=None)[source]

TODO

Parameters
  • length (int) – TODO

  • timeout_ms (TODO, None) – TODO

Raises

NotImplementedError – This is always raised because this method is not implemented.

BulkWrite(data, timeout_ms=None)[source]

TODO

_images/adb.common.UsbHandle.BulkWrite.CALL_GRAPH.svg
Parameters
  • data (bytes) – TODO

  • timeout_ms (TODO, None) – TODO

Returns

TODO

Return type

TODO

Raises
Close()[source]

TODO

_images/adb.common.UsbHandle.Close.CALL_GRAPH.svg_images/adb.common.UsbHandle.Close.CALLER_GRAPH.svg
classmethod Find(setting_matcher, port_path=None, serial=None, timeout_ms=None)[source]

Gets the first device that matches according to the keyword args.

_images/adb.common.UsbHandle.Find.CALL_GRAPH.svg_images/adb.common.UsbHandle.Find.CALLER_GRAPH.svg
Parameters
  • setting_matcher (TODO) – TODO

  • port_path (TODO, None) – TODO

  • serial (TODO, None) – TODO

  • timeout_ms (TODO, None) – TODO

Returns

TODO

Return type

TODO

classmethod FindAndOpen(setting_matcher, port_path=None, serial=None, timeout_ms=None)[source]

TODO

_images/adb.common.UsbHandle.FindAndOpen.CALL_GRAPH.svg_images/adb.common.UsbHandle.FindAndOpen.CALLER_GRAPH.svg
Parameters
  • setting_matcher (TODO) – TODO

  • port_path (TODO, None) – TODO

  • serial (TODO, None) – TODO

  • timeout_ms (TODO, None) – TODO

Returns

dev – TODO

Return type

TODO

classmethod FindDevices(setting_matcher, device_matcher=None, usb_info='', timeout_ms=None)[source]

Find and yield the devices that match.

_images/adb.common.UsbHandle.FindDevices.CALLER_GRAPH.svg
Parameters
  • setting_matcher (TODO) – Function that returns the setting to use given a usb1.USBDevice, or None if the device doesn’t have a valid setting.

  • device_matcher (TODO, None) – Function that returns True if the given UsbHandle is valid. None to match any device.

  • usb_info (str) – Info string describing device(s).

  • timeout_ms (TODO, None) – Default timeout of commands in milliseconds.

Yields

TODO – UsbHandle instances

classmethod FindFirst(setting_matcher, device_matcher=None, **kwargs)[source]

Find and return the first matching device.

_images/adb.common.UsbHandle.FindFirst.CALL_GRAPH.svg_images/adb.common.UsbHandle.FindFirst.CALLER_GRAPH.svg
Parameters
Returns

An instance of UsbHandle.

Return type

TODO

Raises

adb.usb_exceptions.DeviceNotFoundError – Raised if the device is not available.

FlushBuffers()[source]

TODO

_images/adb.common.UsbHandle.FlushBuffers.CALL_GRAPH.svg
Raises

adb.usb_exceptions.ReadFailedError – TODO

Open()[source]

Opens the USB device for this setting, and claims the interface.

_images/adb.common.UsbHandle.Open.CALL_GRAPH.svg
classmethod PortPathMatcher(port_path)[source]

Returns a device matcher for the given port path.

_images/adb.common.UsbHandle.SerialMatcher.CALL_GRAPH.svg_images/adb.common.UsbHandle.PortPathMatcher.CALLER_GRAPH.svg
Parameters

port_path (TODO) – TODO

Returns

TODO

Return type

function

classmethod SerialMatcher(serial)[source]

Returns a device matcher for the given serial.

_images/adb.common.UsbHandle.SerialMatcher.CALLER_GRAPH.svg
Parameters

serial (TODO) – TODO

Returns

TODO

Return type

function

Timeout(timeout_ms)[source]

TODO

_images/adb.common.UsbHandle.Timeout.CALLER_GRAPH.svg
Returns

TODO

Return type

TODO

_HANDLE_CACHE = <WeakValueDictionary>
_HANDLE_CACHE_LOCK = <unlocked _thread.lock object>
property port_path

TODO

_images/adb.common.UsbHandle.port_path.CALLER_GRAPH.svg
Returns

TODO

Return type

TODO

property serial_number

TODO

_images/adb.common.UsbHandle.serial_number.CALLER_GRAPH.svg
Returns

TODO

Return type

TODO

property usb_info

TODO

_images/adb.common.UsbHandle.usb_info.CALL_GRAPH.svg_images/adb.common.UsbHandle.usb_info.CALLER_GRAPH.svg
Returns

TODO

Return type

TODO