anadroid.application package

Submodules

anadroid.application.AbstractApplication module

class anadroid.application.AbstractApplication.AbstractApplication(package_name, version='0.0')[source]

Bases: ABC

Abstract base class representing a mobile application and defining an interface to interact with the application on the device.

package_name

The package name of the app.

Type:

str

version

The version number of the app (default is ‘0.0’).

Type:

str

on_fg

A flag indicating whether the app is in the foreground.

Type:

bool

get_app_id()[source]

Get the unique app identifier.

Returns:

The app identifier in the format ‘<package_name>_<version>’.

Return type:

str

abstract kill()[source]

Abstract method to kill the application.

abstract perform_action(act)[source]

Abstract method to perform a specific action within the application.

Parameters:

act – The action to be performed within the application.

abstract start()[source]

Abstract method to start the application.

abstract stop()[source]

Abstract method to stop the application.

anadroid.application.AndroidProject module

class anadroid.application.AndroidProject.AndroidProject(projname, projdir, results_dir='anadroid_results', clean_instrumentations=False)[source]

Bases: Project

Class that abstracts Android Projects.

projname

Project name.

Type:

str

projir

Project directory.

Type:

str

results_dir

Directory where to store project’s results.

Type:

str

root_build_file

Project-level gradle file.

Type:

str

main_manif_file

Project manifest file.

Type:

str

tests_manif_file

Manifest of the test project.

add_apk(apk_path, build_type)[source]

Adds an APK path of the specified build type to the known list of APKs for the project.

Parameters:
  • apk_path (str) – Path to APK.

  • build_type (BUILD_TYPE) – APK build type (test, release, custom).

create_inner_folder(name='libs')[source]

Creates a folder inside the project.

Parameters:

name (str) – Name of the folder to be created.

Returns:

Path of the created folder.

Return type:

path (str)

get_apks(build_type=BUILD_TYPE.DEBUG)[source]

Get APKs of a specific build type.

Parameters:

build_type (BUILD_TYPE) – Build type.

Returns:

List of APK paths.

Return type:

apk_list (list of str)

get_build_files()[source]

Returns build.gradle files of the project.

Returns:

List of file paths.

Return type:

files_list (list of str)

get_gradle_plugin()[source]

Returns the gradle plugin version.

Parses gradle plugin version from the root build file.

Returns:

Gradle plugin version.

Return type:

gradle_plugin_version (str)

get_gradle_settings()[source]

Returns settings.gradle file.

Returns:

Path of the settings.gradle file.

Return type:

file_path (str)

get_main_manif_file()[source]

Returns project’s main manifest file.

Returns:

Path of the main manifest file.

Return type:

file_path (str)

get_proj_json()[source]

Get a dictionary containing project information.

Returns:

A dictionary containing project details.

Return type:

dict

get_root_build_file()[source]

Returns project-level build.gradle file.

Assumes that it is the one with the shortest path. Gets the list of the build.gradle file paths and returns the shortest one.

Returns:

Path of gradle file.

Return type:

file_path (str)

get_test_apks()[source]

Returns test APKs.

Returns:

List of test APK paths.

Return type:

apk_list (list of str)

has_gradle_wrapper()[source]

Determine if the project is ready to be built with gradle wrapper.

Returns:

True if gradlew file is found in project’s sources, False otherwise.

Return type:

bool

save_proj_json(path)[source]

Save the project information to a JSON file.

Parameters:

path (str) – Path where the JSON file will be saved.

set_version(build_type)[source]

Set the project version based on the specified build type.

Parameters:

build_type (BUILD_TYPE) – Build type.

class anadroid.application.AndroidProject.BUILD_FLAVOR(value)[source]

Bases: Enum

An enumeration.

CUSTOM = 'Custom'
DEMO = 'Demo'
FULL = 'full'
NONE = 'None'
class anadroid.application.AndroidProject.BUILD_TYPE(value)[source]

Bases: Enum

An enumeration.

CUSTOM = 'Custom'
DEBUG = 'Debug'
RELEASE = 'Release'
class anadroid.application.AndroidProject.Project(projname, projdir, results_dir='anadroid_results')[source]

Bases: object

Class that abstracts software projects.

projname

Project name.

Type:

str

projir

Project directory.

Type:

str

results_dir

Directory where to store project’s results.

Type:

str

clean_transformations()[source]

Removes previous project transformations from project sources.

init_results_dir(app_id)[source]

Initializes results directory. Creates directory if it does not exist.

Parameters:

app_id (str) – Project’s app id.

save_proj_json(path)[source]

Saves project details to a JSON file.

Parameters:

path (str) – Path where the JSON file will be saved.

anadroid.application.AndroidProject.is_android_project(dirpath)[source]

Determines if a given directory is an Android Project. Looks for settings.gradle files.

Parameters:

dirpath (str) – Path of the directory.

Returns:

True if file is in the directory, False otherwise.

Return type:

bool

anadroid.application.AndroidProject.mk_ma_dir(path)[source]

anadroid.application.Application module

class anadroid.application.Application.App(device, proj, package_name, apk_path, local_res_dir, app_name='app', version=None)[source]

Bases: AbstractApplication

Main class that abstracts an Android App.

device

Device where the app is installed.

Type:

Device

proj

Respective Android project.

Type:

AndroidProject

package_name

Package name of the app.

Type:

str

local_res_dir

Local results directory.

Type:

str

app_name

Name of the app.

Type:

str

version

App version.

Type:

DefaultSemanticVersion

clean_cache()[source]

Cleans the app cache.

Cleans the app cache on the device using the package manager.

get_app_json()[source]

Get a JSON representation of the app.

Returns:

JSON representation of the app.

Return type:

dict

get_permissions_json()[source]

Get the permissions JSON file.

Returns:

Path to the permissions JSON file or None if it doesn’t exist.

Return type:

str

init_local_test_(testing_framework, inst_type)[source]

Initializes a directory for a current test being run with the specified testing framework and instrumented with the specified instrumentation type.

Parameters:
kill()[source]

Kills the running app.

Not yet implemented.

performAction(act)[source]

Performs an action (Not yet implemented).

set_immersive_mode()[source]

Sets immersive mode for this app if the Android version < 11.

This feature is only available for devices running Android 10 or lower.

start()[source]

Starts the application on the device.

Starts the app by calling monkey -p <pkg_name> 1.

stop()[source]

Stops the running app.

Stops the app via the activity manager (force-stop command).

anadroid.application.Application.get_prefix(testing_framework, inst_type)[source]

Gets an adequate prefix for a folder, given the testing framework and instrumentation type.

Parameters:
Returns:

Prefix for the folder.

Return type:

prefix (str)

anadroid.application.Dependency module

class anadroid.application.Dependency.BuildDependency(name, dep_type=DependencyType.REMOTE, version=None, bin_type=None)[source]

Bases: object

Represents an app build dependency referred in build files.

name

Dependency name.

Type:

str

dep_type

Type of dependency.

Type:

DependencyType

version

Dependency version.

Type:

str

bin_type

Binary type, used when it is a local dependency, such as an .aar.

Type:

str

class anadroid.application.Dependency.DependencyType(value)[source]

Bases: Enum

Represents build dependencies’ type.

CLASSPATH = 'Classpath'
LOCAL_BINARY = 'Local Binary'
LOCAL_MODULE = 'Local Module'
REMOTE = 'Remote'

anadroid.application.ProjectModule module

class anadroid.application.ProjectModule.MODULE_TYPE(value)[source]

Bases: Enum

Project Module types.

APP = 'App'
LIBRARY = 'Library'
class anadroid.application.ProjectModule.ProjectModule(name, mod_dir)[source]

Bases: object

Represents an Android Project Module.

mod_name

Module name.

Type:

str

mod_dir

Module directory.

Type:

str

build_file

Path to the build.gradle file of the module.

Type:

str

module_type

Type of the module (LIBRARY or APP).

Type:

MODULE_TYPE

manifest

Path to the AndroidManifest.xml file of the module.

Type:

str

dependencies

Set of module dependencies.

Type:

set

gen_apks

Generated APKs within the module.

Type:

dict

gen_aars

Generated AARs within the module.

Type:

dict

create_inner_folder(name='libs')[source]

Creates a directory inside the module.

Parameters:

name (str) – Directory name.

Returns:

Directory’s path.

Return type:

str

Module contents