anadroid.device package

Submodules

anadroid.device.AbstractDevice module

class anadroid.device.AbstractDevice.ADB_CONN(value)[source]

Bases: Enum

Class to enumerate different connectivity alternatives using ADB.

USB = 'USB'
WIFI = 'WIFI'
class anadroid.device.AbstractDevice.AbstractDevice(serial_nr)[source]

Bases: ABC

Provides basic interface and functionality to interact with devices.

serial_nr

device serial number / uuid.

Type:

str

conn_type

type of connection.

Type:

ADB_CONN

abstract execute_command(cmd, args=[], shell=False)[source]

execute remote shell command with args on device. :returns: result of command. :rtype: res(COMMAND_RESULT)

abstract execute_root_command(cmd, args=[], shell=True)[source]

execute remote shell command with args on device in superuser mode. :returns: result of command. :rtype: res(COMMAND_RESULT)

abstract get_device_android_version()[source]

returns device android version. Retrieves value of ro.build.version.release property. :returns: android version. :rtype: DefaultSemanticVersion

abstract install_apks(apk_paths)[source]
abstract is_screen_dreaming()[source]

Checks if screen is dreaming. :returns: True if dreaming, False otherwise. :rtype: bool

abstract is_screen_unlocked()[source]

Checks if screen is unlocked. :returns: True if unlocked, False otherwise. :rtype: bool

abstract list_installed_packages()[source]
abstract lock_screen()[source]

Checks if screen is locked. :returns: True if locked, False otherwise. :rtype: bool

press_lock_button()[source]
reboot()[source]
touch_screen(x_coord=500, y_coord=500)[source]
abstract uninstall_pkg(pkg_name)[source]
abstract unlock_screen(pwd=None)[source]

unlock device screen. Tries several approaches to unlock screen. It starts by trying to press lock button, followed by trying to type a password if a password is required. If none of these worked, tries to press menu button and finally, it tries to perform a swipe up. :param pwd: password to provide if devices requires password to be unlocked.

anadroid.device.Device module

class anadroid.device.Device.Device(serial_nr, conn_type=ADB_CONN.USB)[source]

Bases: AbstractDevice

Class that extends AbstractDevice to handle interaction with devices connected via ADB.

clear_logcat()[source]

clear device logs.

contains_file(filepath)[source]

checks if device has a file in a given filepath. :param filepath: path of file to check.

Returns:

True if file exists, False otherwise.

Return type:

bool

dump_logcat_to_file(filename='logcat.out')[source]

dumps device logs to file with path filename. :param filename: path or name of file.

execute_command(cmd, args=[], shell=False)[source]

execute remote shell command with args on device. :returns: result of command. :rtype: res(COMMAND_RESULT)

execute_root_command(cmd, args=[], shell=False)[source]

execute remote shell command with args on device in superuser mode. :returns: result of command. :rtype: res(COMMAND_RESULT)

get_device_android_version()[source]

returns device android version. Retrieves value of ro.build.version.release property. :returns: android version. :rtype: DefaultSemanticVersion

get_device_brand()[source]
get_device_cores()[source]
get_device_info()[source]
get_device_max_cpu_freq()[source]
get_device_model()[source]
get_device_props()[source]

returns props dict containing device properties that were obtained using getprop command. :returns: dict with properties. :rtype: props(dict)

get_device_ram()[source]
get_device_sdk_version()[source]

returns device sdk version. Gets ro.build.version.sdk. :returns: major min sdk version. :rtype: int

get_device_specs()[source]
get_kernel_version()[source]
get_min_sdk_version()[source]

returns min sdk version of device. Gets ro.build.version.min_supported_target_sdk property. :returns: major min sdk version. :rtype: int

get_new_installed_pkgs()[source]

if a new pkg was installed, retrieves a list of the new installed packages. :returns: list of new packages. :rtype: new_pkgs(list of str)

get_package_matching(pkg_aprox_name)[source]

gets installed package more alike with a given pkg name. :param pkg_aprox_name: name of the package.

Returns:

the most alike installed pkg name.

Return type:

str

get_prop(key)[source]
has_package_installed(pack_name)[source]

checks if a given package is installed on device. :param pack_name: package name.

Returns:

True if installed, False otherwise.

Return type:

bool

install_apk(apk_path, accept_install=True)[source]

installs apk located in apk_path :param apk_path: apk path. :type apk_path: str

Returns:

result of installation command.

Return type:

COMMAND_RESULT

install_apks(andr_proj, build_type=BUILD_TYPE.RELEASE, accept_install=False, install_test_apks=False, retry=True)[source]

install apks of type build_type of android project andr_proj. :param andr_proj: :type andr_proj: AndroidProject :param build_type: build type. :type build_type: BUILD_TYPE :param install_test_apks: if test apk installation has to be performed. :type install_test_apks: bool

Returns:

set of installed packages.

Return type:

installed_packages(set)

is_rooted()[source]

check if it is a rooted device. :returns: True if is rooted, False otherwise. :rtype: bool

is_screen_dreaming()[source]

Checks if screen is dreaming. :returns: True if dreaming, False otherwise. :rtype: bool

is_screen_unlocked()[source]

Checks if screen is unlocked. :returns: True if unlocked, False otherwise. :rtype: bool

list_installed_packages()[source]

returns list of device’s installed packages. :returns: list of packages. :rtype: vals(list of str)

load_device_state(filepath)[source]

load device state from a file located in filepath :param filepath: location of file with the state.

Returns:

dict with state.

Return type:

json_def(dict)

lock_screen()[source]

Checks if screen is locked. :returns: True if locked, False otherwise. :rtype: bool

save_device_info(filepath)[source]
save_device_specs(filepath)[source]
save_device_state(filepath='state.json')[source]
set_device_state(state_cfg=DEVICE_STATE_ENFORCE.TEST, perm_json=None)[source]

enforces a given device state. :param state_cfg: type of state to enforce :type state_cfg: DEVICE_STATE_ENFORCE :param perm_json: set of states to enforce according to the permission to give in such state.

set_log_size(log_size_bytes=16384)[source]

sets log size through persist.logd.size property. :param log_size_bytes: size in bytes.

uninstall_pkg(pkg_name)[source]
unlock_screen(password=None)[source]

unlock device screen. Tries several approaches to unlock screen. It starts by trying to press lock button, followed by trying to type a password if a password is required. If none of these worked, tries to press menu button and finally, it tries to perform a swipe up. :param pwd: password to provide if devices requires password to be unlocked.

exception anadroid.device.Device.DeviceNotFoundError[source]

Bases: Exception

anadroid.device.Device.background_installer(serial_nr)[source]
anadroid.device.Device.click_to_install(serial_nr)[source]
anadroid.device.Device.get_first_connected_device(conn_type='USB')[source]

Retrieves the first connected device that it founds using adb. Retrieves the first device of the list retrieved by adb devices -l command. :param conn_type:

Returns:

first device found.

Return type:

Device

anadroid.device.Device.has_to_click_to_install(serial_nr)[source]
anadroid.device.Device.set_device_conn(conn_type, device_id=None)[source]

sets connection of type conn_type with a connected device or a device with id == device_id. :param conn_type: connection type. :type conn_type: ADB_CONN :param device_id: device id.

anadroid.device.DeviceState module

class anadroid.device.DeviceState.DEVICE_STATE_ENFORCE(value)[source]

Bases: Enum

Enumerates different states of device during benchmarking activity

APP = 'App conditions'
IDLE = 'Idle'
TEST = 'Test conditions'
class anadroid.device.DeviceState.DeviceState(device)[source]

Bases: object

class that stores and represents the state of device components.

device

device.

Type:

Device

screen_locked

1 if screen locked, 0 otherwise.

Type:

int

screen_brightness

screen brightness value (0-255).

Type:

int

screen_always_on

if the screen should be always on.

Type:

int

screen_auto_rotate

if the screen should rotate automatically.

Type:

int

screen_orientation

screen orientation.

Type:

int

bluetooth

state of bluetooth.

Type:

int

wifi

wifi state.

Type:

int

gps

gps state.

Type:

int

nfc_state

nfc_state state.

Type:

int

mobile_data_state

mobile_data_state state.

Type:

int

speakers_state

speakers_state state.

Type:

int

flashlight

flashlight state.

Type:

int

change_speaker_state(value=0)[source]

set speaker state. if state = 1 enables speakers. Otherwise, disables it. :param value: state value.

enforce_state(key, val)[source]

enforces a component state. :param key: component uid/key. :param val: state value.

get_bluetooth_state()[source]

retrieve bluetooh state. :returns: 0 if off, 1 otherwise. :rtype: int

get_device_state()[source]
get_gps_state()[source]

retrieve gps state. :returns: 0 if off, 1 otherwise. :rtype: int

get_hotspot_state()[source]

retrieve hotspot state. :returns: 0 if off, 1 otherwise. :rtype: int

get_mobile_data_state()[source]

retrieve mobile data state. :returns: 0 if off, 1 otherwise. :rtype: int

get_nfc_state()[source]

retrieve nfc state. :returns: 0 if off, 1 otherwise. :rtype: int

get_nr_processes_running()[source]
get_screen_always_on()[source]

retrieve screen always on state. gets value of stay_on_while_plugged_in setting. :returns: value. :rtype: int

get_screen_auto_rotate()[source]

retrieve screen auto rotation state. gets value of system setting accelerometer_rotation. :returns: value. :rtype: int

get_screen_brightness()[source]

retrieve screen brightness value. :returns: 0 - 255. :rtype: int

get_screen_lock_state()[source]

retrieve screen lock state. :returns: 0 if unlocked, 1 otherwise. :rtype: int

get_screen_orientation()[source]

retrieve screen orientation state. gets value of system setting user_rotation. :returns: value. :rtype: int

get_speakers_state()[source]

retrieve speakers state. :returns: 0 if off, 1 otherwise. :rtype: int

get_state(key)[source]

given a component uid/key, returns the current state of such component. :param key: component uid/key.

Returns:

value.

Return type:

int

get_states_from_permission(perm_id)[source]

infers needed state changes from permission. :param perm_id: permission key.

get_used_cpu_averages()[source]
get_used_ram_kernel()[source]
get_used_ram_pss()[source]
get_wifi_state()[source]

retrieve wifi state. :returns: 0 if off, 1 otherwise. :rtype: int

set_bluetooth_state(value=0)[source]

set bluetooth state. if state = 1 enables bluetooth. Otherwise, disables it. :param value: state value.

set_gps_state(value=0)[source]

set gps state. if state = 1 enables gps. Otherwise, disables it. :param value: state value.

set_hotspot_state(value=0)[source]
set_mobile_data_state(value=0)[source]

set mobile date state. if state = 1 enables mobile data. Otherwise, disables it. :param value: state value.

set_nfc_state(value=0)[source]

set nfc state. if state = 1 enables nft. Otherwise, disables it. :param value: state value.

set_screen_always_on_while_plugged(value=0)[source]

set screen always on state. if state = 1 set stay on value. :param value: state value.

set_screen_auto_rotate(value=0)[source]

set screen auto rotate state. if state = 1 set auto rotate value as 1 (enable). :param value: state value.

set_screen_brightness(value=0)[source]

sets brightness value. :param value: value between 0-255.

set_screen_lock_state(state=0)[source]

set screen lock state. if state = 0, unlocks screen. Otherwise, it locks the screen. :param state: lock state.

set_screen_orientation(value=0)[source]

set screen orientation state. if state = 1, sets landscape mode. Otherwise, sets orientation as portrait mode. :param value: state value.

set_wifi_state(value=0)[source]

set wifi state. if state = 1 enables wifi. Otherwise, disables it. :param value: state value.

anadroid.device.DeviceState.get_known_state_keys()[source]

anadroid.device.MockedDevice module

class anadroid.device.MockedDevice.MockedDevice[source]

Bases: Device

Mocks a connected device. The main use case is to mock some devices with custom properties or when the framework is building apps without a connected device.

execute_command(cmd, args=[], shell=False)[source]

execute remote shell command with args on device. :returns: result of command. :rtype: res(COMMAND_RESULT)

execute_root_command(cmd, args=[], shell=True)[source]

execute remote shell command with args on device in superuser mode. :returns: result of command. :rtype: res(COMMAND_RESULT)

install_apk(apk_path, accept_install=True)[source]

installs apk located in apk_path :param apk_path: apk path. :type apk_path: str

Returns:

result of installation command.

Return type:

COMMAND_RESULT

is_screen_dreaming()[source]

Checks if screen is dreaming. :returns: True if dreaming, False otherwise. :rtype: bool

is_screen_unlocked()[source]

Checks if screen is unlocked. :returns: True if unlocked, False otherwise. :rtype: bool

Module contents