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
- 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 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 lock_screen()[source]
Checks if screen is locked. :returns: True if locked, False otherwise. :rtype: bool
- 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.
- 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_props()[source]
returns props dict containing device properties that were obtained using getprop command. :returns: dict with properties. :rtype: props(dict)
- get_device_sdk_version()[source]
returns device sdk version. Gets ro.build.version.sdk. :returns: major min sdk version. :rtype: int
- 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
ofstr
)
- 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
- 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:
- 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
ofstr
)
- 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
- 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.
- 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.
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.
- 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_mobile_data_state()[source]
retrieve mobile data state. :returns: 0 if off, 1 otherwise. :rtype: int
- 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_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_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.
- 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_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_lock_state(state=0)[source]
set screen lock state. if state = 0, unlocks screen. Otherwise, it locks the screen. :param state: lock state.
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: