androidtv.adb_manager.adb_manager_async module

Classes to manage ADB connections.

  • ADBPythonAsync utilizes a Python implementation of the ADB protocol.

  • ADBServerAsync utilizes an ADB server to communicate with the device.

class androidtv.adb_manager.adb_manager_async.ADBPythonAsync(host, port, adbkey='', signer=None)[source]

Bases: object

A manager for ADB connections that uses a Python implementation of the ADB protocol.

Parameters:
  • host (str) – The address of the device; may be an IP address or a host name

  • port (int) – The device port to which we are connecting (default is 5555)

  • adbkey (str) – The path to the adbkey file for ADB authentication

  • signer (PythonRSASigner, None) – The signer for the ADB keys, as loaded by ADBPythonAsync.load_adbkey()

property available

Check whether the ADB connection is intact.

Returns:

Whether or not the ADB connection is intact

Return type:

bool

async close()[source]

Close the ADB socket connection.

async connect(log_errors=True, auth_timeout_s=10.0, transport_timeout_s=1.0)[source]

Connect to an Android TV / Fire TV device.

Parameters:
  • log_errors (bool) – Whether errors should be logged

  • auth_timeout_s (float) – Authentication timeout (in seconds)

  • transport_timeout_s (float) – Transport timeout (in seconds)

Returns:

Whether or not the connection was successfully established and the device is available

Return type:

bool

async static load_adbkey(adbkey)[source]

Load the ADB keys.

Parameters:

adbkey (str) – The path to the adbkey file for ADB authentication

Returns:

The PythonRSASigner with the key files loaded

Return type:

PythonRSASigner

async pull(local_path, device_path)[source]

Pull a file from the device using the Python ADB implementation.

Parameters:
  • local_path (str) – The path where the file will be saved

  • device_path (str) – The file on the device that will be pulled

async push(local_path, device_path)[source]

Push a file to the device using the Python ADB implementation.

Parameters:
  • local_path (str) – The file that will be pushed to the device

  • device_path (str) – The path where the file will be saved on the device

async screencap()[source]

Take a screenshot using the Python ADB implementation.

Returns:

The screencap as a binary .png image

Return type:

bytes

async shell(cmd)[source]

Send an ADB command using the Python ADB implementation.

Parameters:

cmd (str) – The ADB command to be sent

Returns:

The response from the device, if there is a response

Return type:

str, None

class androidtv.adb_manager.adb_manager_async.ADBServerAsync(host, port=5555, adb_server_ip='', adb_server_port=5037)[source]

Bases: object

A manager for ADB connections that uses an ADB server.

Parameters:
  • host (str) – The address of the device; may be an IP address or a host name

  • port (int) – The device port to which we are connecting (default is 5555)

  • adb_server_ip (str) – The IP address of the ADB server

  • adb_server_port (int) – The port for the ADB server

property available

Check whether the ADB connection is intact.

Returns:

Whether or not the ADB connection is intact

Return type:

bool

async close()[source]

Close the ADB server socket connection.

Currently, this doesn’t do anything except set self._available = False.

async connect(log_errors=True)[source]

Connect to an Android TV / Fire TV device.

Parameters:

log_errors (bool) – Whether errors should be logged

Returns:

Whether or not the connection was successfully established and the device is available

Return type:

bool

async pull(local_path, device_path)[source]

Pull a file from the device using an ADB server.

Parameters:
  • local_path (str) – The path where the file will be saved

  • device_path (str) – The file on the device that will be pulled

async push(local_path, device_path)[source]

Push a file to the device using an ADB server.

Parameters:
  • local_path (str) – The file that will be pushed to the device

  • device_path (str) – The path where the file will be saved on the device

async screencap()[source]

Take a screenshot using an ADB server.

Returns:

The screencap as a binary .png image, or None if there was an IndexError exception

Return type:

bytes, None

async shell(cmd)[source]

Send an ADB command using an ADB server.

Parameters:

cmd (str) – The ADB command to be sent

Returns:

The response from the device, if there is a response

Return type:

str, None

class androidtv.adb_manager.adb_manager_async.AdbDeviceUsbAsync(serial=None, port_path=None, default_transport_timeout_s=None, banner=None)[source]

Bases: object

An async wrapper for the adb-shell AdbDeviceUsb class.

property available

Whether or not an ADB connection to the device has been established.

async close()[source]

Close the connection via the provided transport’s close() method.

async connect(rsa_keys=None, transport_timeout_s=None, auth_timeout_s=10.0, read_timeout_s=10.0, auth_callback=None)[source]

Establish an ADB connection to the device.

async pull(device_path, local_path, progress_callback=None, transport_timeout_s=None, read_timeout_s=10.0)[source]

Pull a file from the device.

async push(local_path, device_path, st_mode=33272, mtime=0, progress_callback=None, transport_timeout_s=None, read_timeout_s=10.0)[source]

Push a file or directory to the device.

async shell(command, transport_timeout_s=None, read_timeout_s=10.0, timeout_s=None, decode=True)[source]

Send an ADB shell command to the device.

class androidtv.adb_manager.adb_manager_async.ClientAsync(host, port)[source]

Bases: object

An async wrapper for the pure-python-adb Client class.

async device(serial)[source]

Get a DeviceAsync instance.

class androidtv.adb_manager.adb_manager_async.DeviceAsync(device)[source]

Bases: object

An async wrapper for the pure-python-adb Device class.

async pull(device_path, local_path)[source]

Download a file.

async push(local_path, device_path)[source]

Upload a file.

async screencap()[source]

Take a screencap.

async shell(cmd)[source]

Send a shell command.

androidtv.adb_manager.adb_manager_async._acquire(lock, timeout=3.0)[source]

Handle acquisition and release of an asyncio.Lock object with a timeout.

Parameters:
  • lock (asyncio.Lock) – The lock that we will try to acquire

  • timeout (float) – The timeout in seconds

Yields:

acquired (bool) – Whether or not the lock was acquired

Raises:

LockNotAcquiredException – Raised if the lock was not acquired