adb_shell.hidden_helpers module

Implement helpers for the AdbDevice and AdbDeviceAsync classes.

Contents

class adb_shell.hidden_helpers.DeviceFile(filename, mode, size, mtime)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('filename', 'mode', 'size', 'mtime')
classmethod _make(iterable)

Make a new DeviceFile object from a sequence or iterable

_replace(**kwds)

Return a new DeviceFile object replacing specified fields with new values

filename

Alias for field number 0

mode

Alias for field number 1

mtime

Alias for field number 3

size

Alias for field number 2

class adb_shell.hidden_helpers._AdbPacketStore[source]

Bases: object

A class for storing ADB packets.

This class is used to support multiple streams.

_dict

A dictionary of dictionaries of queues. The first (outer) dictionary keys are the arg1 return values from the adb_shell.adb_device._AdbIOManager._read_packet_from_device() and adb_shell.adb_device_async._AdbIOManagerAsync._read_packet_from_device() methods. The second (inner) dictionary keys are the arg0 return values from those methods. And the values of this inner dictionary are queues of (cmd, data) tuples.

Type:

dict[int: dict[int: Queue]]

clear(arg0, arg1)[source]

Delete the entry for (arg0, arg1), if it exists.

Parameters:
clear_all()[source]

Clear all the entries.

find(arg0, arg1)[source]

Find the entry corresponding to arg0 and arg1.

Parameters:
  • arg0 (int, None) – The arg0 value that we are looking for; None serves as a wildcard

  • arg1 (int, None) – The arg1 value that we are looking for; None serves as a wildcard

Returns:

The (arg0, arg1) pair that was found in the dictionary of dictionaries, or None if no match was found

Return type:

tuple[int, int], None

find_allow_zeros(arg0, arg1)[source]

Find the entry corresponding to (arg0 or 0) and (arg1 or 0).

Parameters:
  • arg0 (int, None) – The arg0 value that we are looking for; None serves as a wildcard

  • arg1 (int, None) – The arg1 value that we are looking for; None serves as a wildcard

Returns:

The first matching (arg0, arg1) pair that was found in the dictionary of dictionaries, or None if no match was found

Return type:

tuple[int, int], None

get(arg0, arg1)[source]

Get the next entry from the queue for arg0 and arg1.

This function assumes you have already checked that (arg0, arg1) in self.

Parameters:
Returns:

  • cmd (bytes) – The ADB packet’s command

  • arg0 (int) – The arg0 value from the returned packet

  • arg1 (int) – The arg1 value from the returned packet

  • data (bytes) – The ADB packet’s data

put(arg0, arg1, cmd, data)[source]

Add an entry to the queue for arg0 and arg1.

Note that a new dictionary entry will not be created if cmd == constants.CLSE.

Parameters:
class adb_shell.hidden_helpers._AdbTransactionInfo(local_id, remote_id, transport_timeout_s=None, read_timeout_s=10.0, timeout_s=None)[source]

Bases: object

A class for storing info and settings used during a single ADB “transaction.”

Note that if timeout_s is not None, then:

self.transport_timeout_s <= self.read_timeout_s <= self.timeout_s

If timeout_s is None, the first inequality still applies.

Parameters:
local_id

The ID for the sender (i.e., the device running this code)

Type:

int

read_timeout_s

The total time in seconds to wait for data and packets from the device

Type:

float

remote_id

The ID for the recipient

Type:

int

timeout_s

The total time in seconds to wait for the ADB command to finish

Type:

float, None

transport_timeout_s

Timeout in seconds for sending and receiving data, or None; see BaseTransport.bulk_read(), BaseTransport.bulk_write(), BaseTransportAsync.bulk_read(), and BaseTransportAsync.bulk_write()

Type:

float, None

args_match(arg0, arg1, allow_zeros=False)[source]

Check if arg0 and arg1 match this object’s remote_id and local_id attributes, respectively.

Parameters:
  • arg0 (int) – The arg0 value from an ADB packet, which will be compared to this object’s remote_id attribute

  • arg1 (int) – The arg1 value from an ADB packet, which will be compared to this object’s local_id attribute

  • allow_zeros (bool) – Whether to check if arg0 and arg1 match 0, in addition to this object’s local_id and remote_id attributes

Returns:

Whether arg0 and arg1 match this object’s local_id and remote_id attributes

Return type:

bool

class adb_shell.hidden_helpers._FileSyncTransactionInfo(recv_message_format, maxdata=1048576)[source]

Bases: object

A class for storing info used during a single FileSync “transaction.”

Parameters:
  • recv_message_format (bytes) – The FileSync message format

  • maxdata (int) – Maximum amount of data in an ADB packet

_maxdata

Maximum amount of data in an ADB packet

Type:

int

recv_buffer

A buffer for storing received data

Type:

bytearray

recv_message_format

The FileSync message format

Type:

bytes

recv_message_size

The FileSync message size

Type:

int

send_buffer

A buffer for storing data to be sent

Type:

bytearray

send_idx

The index in recv_buffer that will be the start of the next data packet sent

Type:

int

can_add_to_send_buffer(data_len)[source]

Determine whether data_len bytes of data can be added to the send buffer without exceeding constants.MAX_ADB_DATA.

Parameters:

data_len (int) – The length of the data to be potentially added to the send buffer (not including the length of its header)

Returns:

Whether data_len bytes of data can be added to the send buffer without exceeding constants.MAX_ADB_DATA

Return type:

bool

adb_shell.hidden_helpers.get_banner()[source]

Get the banner that will be signed in adb_shell.adb_device.AdbDevice.connect() / adb_shell.adb_device_async.AdbDeviceAsync.connect().

Returns:

The hostname, or “unknown” if it could not be determined

Return type:

bytearray

adb_shell.hidden_helpers.get_files_to_push(local_path, device_path)[source]

Get a list of the file(s) to push.

Parameters:
  • local_path (str) – A path to a local file or directory

  • device_path (str) – A path to a file or directory on the device

Returns:

  • local_path_is_dir (bool) – Whether or not local_path is a directory

  • local_paths (list[str]) – A list of the file(s) to push

  • device_paths (list[str]) – A list of destination paths on the device that corresponds to local_paths