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.
- 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.
- 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.
- 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
- 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
- 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.
-
Timeout
(timeout_ms)[source]¶ TODO
- Parameters
timeout_ms (TODO) – TODO
- Returns
TODO
- Return type
float
-
TimeoutSeconds
(timeout_ms)[source]¶ TODO
- Parameters
timeout_ms (TODO) – TODO
- Returns
TODO
- Return type
float
-
property
serial_number
¶ TODO
- 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)
- 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
- 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
- Parameters
data (bytes) – TODO
timeout_ms (TODO, None) – TODO
- Returns
TODO
- Return type
TODO
- Raises
adb.usb_exceptions.WriteFailedError – This handle has been closed, probably due to another being opened
adb.usb_exceptions.WriteFailedError – Could not send data
-
classmethod
Find
(setting_matcher, port_path=None, serial=None, timeout_ms=None)[source]¶ Gets the first device that matches according to the keyword args.
- 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
- 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.
- Parameters
setting_matcher (TODO) – Function that returns the setting to use given a
usb1.USBDevice
, orNone
if the device doesn’t have a valid setting.device_matcher (TODO, None) – Function that returns
True
if the givenUsbHandle
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.
- Parameters
setting_matcher (TODO) – See
UsbHandle.FindDevices()
.device_matcher (TODO) – See
UsbHandle.FindDevices()
.**kwargs (TODO) – See
UsbHandle.FindDevices()
.
- Returns
An instance of UsbHandle.
- Return type
TODO
- Raises
adb.usb_exceptions.DeviceNotFoundError – Raised if the device is not available.
-
classmethod
PortPathMatcher
(port_path)[source]¶ Returns a device matcher for the given port path.
- Parameters
port_path (TODO) – TODO
- Returns
TODO
- Return type
function
-
classmethod
SerialMatcher
(serial)[source]¶ Returns a device matcher for the given serial.
- Parameters
serial (TODO) – TODO
- Returns
TODO
- Return type
function
-
_HANDLE_CACHE
= <WeakValueDictionary>¶
-
_HANDLE_CACHE_LOCK
= <unlocked _thread.lock object>¶
-
property
port_path
¶ TODO
- Returns
TODO
- Return type
TODO
-
property
serial_number
¶ TODO
- Returns
TODO
- Return type
TODO
-
property
usb_info
¶ TODO
- Returns
TODO
- Return type
TODO