TrigDroid Module
The main TrigDroid public API module provides classes and functions for interacting with the framework.
Main API
Configuration
Configuration classes for TrigDroid API.
- class trigdroid.api.config.TestConfiguration(package='', device_id=None, min_runtime=1, background_time=0, acceleration=0, gyroscope=0, light=0, pressure=0, battery_rotation=0, wifi=None, data=None, bluetooth=None, bluetooth_mac=None, install_dummy_apps=<factory>, uninstall_apps=<factory>, grant_permissions=<factory>, revoke_permissions=<factory>, frida_hooks=False, frida_constants=None, adb_enabled=None, uptime_offset=0, geolocation=None, language=None, baseband=None, build_properties=<factory>, log_level=LogLevel.INFO, log_file=None, suppress_console_logs=False, extended_log_format=False, log_filter_include=<factory>, log_filter_exclude=<factory>, disable_changelog=False, changelog_file='changelog.txt', interaction=False, no_unroot=False)[source]
Bases:
object
Test configuration for TrigDroid API.
This class provides a clean, type-safe interface for configuring TrigDroid tests programmatically. All parameters have sensible defaults for quick setup.
Examples
# Minimal configuration config = TestConfiguration(package=’com.example.app’)
# Full configuration config = TestConfiguration(
package=’com.example.app’, device_id=’emulator-5554’, acceleration=5, gyroscope=3, battery_rotation=4, min_runtime=5, log_level=LogLevel.DEBUG, frida_hooks=True, install_dummy_apps=[‘com.dummy.app1’, ‘com.dummy.app2’]
)
# Load from file config = TestConfiguration.from_yaml_file(‘config.yaml’)
# Convert to dictionary config_dict = config.to_dict()
- Parameters:
package (str)
device_id (str | None)
min_runtime (int)
background_time (int)
acceleration (int)
gyroscope (int)
light (int)
pressure (int)
battery_rotation (int)
wifi (bool | None)
data (bool | None)
bluetooth (bool | None)
bluetooth_mac (str | None)
frida_hooks (bool)
frida_constants (str | None)
adb_enabled (bool | None)
uptime_offset (int)
geolocation (str | None)
language (str | None)
baseband (str | None)
log_level (LogLevel)
log_file (str | None)
suppress_console_logs (bool)
extended_log_format (bool)
disable_changelog (bool)
changelog_file (str)
interaction (bool)
no_unroot (bool)
- is_valid()[source]
Check if configuration is valid.
- Returns:
True if valid, False otherwise
- Return type:
- property validation_errors: List[str]
Get list of validation errors.
- Returns:
List of validation error messages
- classmethod from_dict(data)[source]
Create configuration from dictionary.
- classmethod from_yaml_file(file_path)[source]
Load configuration from YAML file.
- Parameters:
file_path (str) – Path to YAML configuration file
- Returns:
TestConfiguration instance
- Raises:
ConfigurationError – If file cannot be loaded or parsed
- Return type:
- classmethod from_command_line(args)[source]
Create configuration from command line arguments.
- Parameters:
- Returns:
TestConfiguration instance
- Return type:
- merge_with(other)[source]
Merge this configuration with another, with other taking precedence.
- Parameters:
other (TestConfiguration) – Configuration to merge with
- Returns:
New TestConfiguration instance with merged values
- Return type:
- copy()[source]
Create a copy of this configuration.
- Returns:
New TestConfiguration instance
- Return type:
- __init__(package='', device_id=None, min_runtime=1, background_time=0, acceleration=0, gyroscope=0, light=0, pressure=0, battery_rotation=0, wifi=None, data=None, bluetooth=None, bluetooth_mac=None, install_dummy_apps=<factory>, uninstall_apps=<factory>, grant_permissions=<factory>, revoke_permissions=<factory>, frida_hooks=False, frida_constants=None, adb_enabled=None, uptime_offset=0, geolocation=None, language=None, baseband=None, build_properties=<factory>, log_level=LogLevel.INFO, log_file=None, suppress_console_logs=False, extended_log_format=False, log_filter_include=<factory>, log_filter_exclude=<factory>, disable_changelog=False, changelog_file='changelog.txt', interaction=False, no_unroot=False)
- Parameters:
package (str)
device_id (str | None)
min_runtime (int)
background_time (int)
acceleration (int)
gyroscope (int)
light (int)
pressure (int)
battery_rotation (int)
wifi (bool | None)
data (bool | None)
bluetooth (bool | None)
bluetooth_mac (str | None)
frida_hooks (bool)
frida_constants (str | None)
adb_enabled (bool | None)
uptime_offset (int)
geolocation (str | None)
language (str | None)
baseband (str | None)
log_level (LogLevel)
log_file (str | None)
suppress_console_logs (bool)
extended_log_format (bool)
disable_changelog (bool)
changelog_file (str)
interaction (bool)
no_unroot (bool)
- Return type:
None
Device Management
Device management classes for TrigDroid API.
- class trigdroid.api.devices.AndroidDevice(device_id, logger=None)[source]
Bases:
object
Represents an Android device for testing.
This class provides a simplified interface over the more complex infrastructure AndroidDevice class.
- class trigdroid.api.devices.DeviceManager(logger=None)[source]
Bases:
object
Manages Android device connections and discovery.
- Parameters:
logger (Logger | None)
- connect_to_device(device_id=None)[source]
Connect to a specific device or auto-select if only one available.
- Parameters:
device_id (str | None) – Specific device ID to connect to, or None for auto-select
- Returns:
AndroidDevice instance or None if connection fails
- Return type:
AndroidDevice | None
- wait_for_device(device_id=None, timeout=30)[source]
Wait for a device to become available.
- Parameters:
- Returns:
AndroidDevice instance or None if timeout
- Return type:
AndroidDevice | None
Test Results
Test result classes for TrigDroid API.
- class trigdroid.api.results.TestResult(success, phase, error=None, config=None, start_time=<factory>, end_time=None, duration_seconds=None, device_info=<factory>, tests_run=<factory>, tests_passed=<factory>, tests_failed=<factory>, tests_skipped=<factory>, frida_hooks_loaded=0, frida_hooks_active=0, frida_errors=<factory>, sensor_tests_executed=<factory>, sensor_values_changed=<factory>, network_state_changes=<factory>, app_started=False, app_crashed=False, app_background_time=0.0, log_file_path=None, changelog_file_path=None, screenshot_paths=<factory>)[source]
Bases:
object
Result of a TrigDroid test execution.
Contains all information about test execution including success status, timing information, configuration used, and any errors encountered.
Examples
# Successful test result = TestResult(success=True, phase=TestPhase.EXECUTION)
# Failed test result = TestResult(
success=False, phase=TestPhase.SETUP, error=”Device connection failed”, config=config
)
- Parameters:
success (bool)
phase (TestPhase)
error (str | None)
config (TestConfiguration | None)
start_time (datetime)
end_time (datetime | None)
duration_seconds (float | None)
frida_hooks_loaded (int)
frida_hooks_active (int)
app_started (bool)
app_crashed (bool)
app_background_time (float)
log_file_path (str | None)
changelog_file_path (str | None)
- config: TestConfiguration | None = None
- mark_completed(success=None)[source]
Mark the test as completed.
- Parameters:
success (bool | None) – Optional override for success status
- Return type:
None
- property result_enum: TestResult
Get the result as an enum value.
- summary()[source]
Get a human-readable summary of the results.
- Returns:
Summary string
- Return type:
- __init__(success, phase, error=None, config=None, start_time=<factory>, end_time=None, duration_seconds=None, device_info=<factory>, tests_run=<factory>, tests_passed=<factory>, tests_failed=<factory>, tests_skipped=<factory>, frida_hooks_loaded=0, frida_hooks_active=0, frida_errors=<factory>, sensor_tests_executed=<factory>, sensor_values_changed=<factory>, network_state_changes=<factory>, app_started=False, app_crashed=False, app_background_time=0.0, log_file_path=None, changelog_file_path=None, screenshot_paths=<factory>)
- Parameters:
success (bool)
phase (TestPhase)
error (str | None)
config (TestConfiguration | None)
start_time (datetime)
end_time (datetime | None)
duration_seconds (float | None)
frida_hooks_loaded (int)
frida_hooks_active (int)
app_started (bool)
app_crashed (bool)
app_background_time (float)
log_file_path (str | None)
changelog_file_path (str | None)
- Return type:
None
Test Runners
Quick Start
Command Line Interface
Core Utilities
Core enumerations for TrigDroid.
- class trigdroid.core.enums.LogLevel(value)[source]
Bases:
Enum
Logging levels.
- DEBUG = 'DEBUG'
- INFO = 'INFO'
- WARNING = 'WARNING'
- ERROR = 'ERROR'
- CRITICAL = 'CRITICAL'
- class trigdroid.core.enums.TestPhase(value)[source]
Bases:
Enum
Test execution phases.
- SETUP = 'setup'
- EXECUTION = 'execution'
- TEARDOWN = 'teardown'
- class trigdroid.core.enums.TestResult(value)[source]
Bases:
Enum
Test execution results.
- SUCCESS = 'success'
- FAILURE = 'failure'
- SKIPPED = 'skipped'
- ERROR = 'error'
- class trigdroid.core.enums.DeviceConnectionState(value)[source]
Bases:
Enum
Android device connection states.
- CONNECTED = 'connected'
- DISCONNECTED = 'disconnected'
- UNAUTHORIZED = 'unauthorized'
- OFFLINE = 'offline'
- class trigdroid.core.enums.SensorType(value)[source]
Bases:
Enum
Android sensor types.
- ACCELEROMETER = 'accelerometer'
- GYROSCOPE = 'gyroscope'
- LIGHT = 'light'
- PRESSURE = 'pressure'
- MAGNETOMETER = 'magnetometer'
- TEMPERATURE = 'temperature'
- PROXIMITY = 'proximity'
- class trigdroid.core.enums.ConnectionType(value)[source]
Bases:
Enum
Network connection types.
- WIFI = 'wifi'
- DATA = 'data'
- BLUETOOTH = 'bluetooth'
- NFC = 'nfc'
- class trigdroid.core.enums.BatteryRotationLevel(value)[source]
Bases:
IntEnum
Battery rotation elaborateness levels.
- DISABLED = 0
- SUPER_FAST = 1
- FAST = 2
- DETAILED = 3
- SUPER_DETAILED = 4
- class trigdroid.core.enums.SensorElaboratenessLevel(value)[source]
Bases:
IntEnum
Sensor test elaborateness levels.
- DISABLED = 0
- MINIMAL = 1
- LOW = 2
- MEDIUM = 3
- HIGH = 4
- VERY_HIGH = 5
- EXTREME = 6
- MAXIMUM = 7
- ULTRA = 8
- INSANE = 9
- ULTIMATE = 10
- class trigdroid.core.enums.PhoneType(value)[source]
Bases:
IntEnum
Phone types from Android TelephonyManager.
- NONE = 0
- GSM = 1
- CDMA = 2
- SIP = 3
- class trigdroid.core.enums.NetworkType(value)[source]
Bases:
IntEnum
Network types from Android TelephonyManager.
- UNKNOWN = 0
- GPRS = 1
- EDGE = 2
- UMTS = 3
- CDMA = 4
- EVDO_0 = 5
- EVDO_A = 6
- RTT = 7
- HSDPA = 8
- HSUPA = 9
- HSPA = 10
- IDEN = 11
- EVDO_B = 12
- LTE = 13
- EHRPD = 14
- HSPAP = 15
- GSM = 16
- TD_SCDMA = 17
- IWLAN = 18
- NR = 20
Resource cleanup handlers for TrigDroid.
- class trigdroid.core.cleanup.CleanupManager(logger=None)[source]
Bases:
object
Manages cleanup of resources during TrigDroid execution.
This class ensures that temporary files, processes, and other resources are properly cleaned up when TrigDroid exits, even if execution is interrupted.
Examples
# Register a cleanup function cleanup = CleanupManager() cleanup.register_file(“/tmp/trigdroid_temp.log”) cleanup.register_callback(lambda: print(“Cleaning up…”))
# Use as context manager with CleanupManager() as cleanup:
cleanup.register_file(temp_file) # … do work …
# Cleanup happens automatically
- Parameters:
logger (Logger | None)
- register_file(file_path)[source]
Register a file for cleanup.
- Parameters:
file_path (str) – Path to file to delete on cleanup
- Return type:
None
- register_directory(dir_path)[source]
Register a directory for cleanup.
- Parameters:
dir_path (str) – Path to directory to delete on cleanup
- Return type:
None
- register_process(process)[source]
Register a process for termination.
- Parameters:
process (Any) – Process object with terminate() method
- Return type:
None
- register_frida_session(session)[source]
Register a Frida session for detachment.
- Parameters:
session (Any) – Frida session object
- Return type:
None
- create_temp_file(suffix='', prefix='trigdroid_')[source]
Create a temporary file that will be cleaned up.
- trigdroid.core.cleanup.get_global_cleanup_manager()[source]
Get the global cleanup manager instance.
- Returns:
Global CleanupManager instance
- Return type:
- trigdroid.core.cleanup.register_cleanup_file(file_path)[source]
Register a file for cleanup using the global manager.
- Parameters:
file_path (str) – Path to file to delete on cleanup
- Return type:
None
- trigdroid.core.cleanup.register_cleanup_dir(dir_path)[source]
Register a directory for cleanup using the global manager.
- Parameters:
dir_path (str) – Path to directory to delete on cleanup
- Return type:
None
- trigdroid.core.cleanup.register_cleanup_callback(callback)[source]
Register a callback for cleanup using the global manager.
- trigdroid.core.cleanup.create_temp_file(suffix='', prefix='trigdroid_')[source]
Create a temporary file using the global cleanup manager.
- trigdroid.core.cleanup.create_temp_dir(prefix='trigdroid_')[source]
Create a temporary directory using the global cleanup manager.
- class trigdroid.core.cleanup.TempResource(cleanup_manager=None)[source]
Bases:
object
Context manager for temporary resources with automatic cleanup.
Examples
# Temporary file with TempResource.file() as temp_file:
temp_file.write_text(“test data”) # … use file …
# File is automatically deleted
# Temporary directory with TempResource.dir() as temp_dir:
(temp_dir / “test.txt”).write_text(“test”) # … use directory …
# Directory is automatically deleted
- Parameters:
cleanup_manager (CleanupManager | None)
- __init__(cleanup_manager=None)[source]
- Parameters:
cleanup_manager (CleanupManager | None)
- classmethod file(suffix='', prefix='trigdroid_')[source]
Create a temporary file resource.
- Parameters:
- Returns:
TempFileResource context manager
- Return type:
Exceptions
Exception classes for TrigDroid.
- exception trigdroid.exceptions.TrigDroidError[source]
Bases:
Exception
Base exception for TrigDroid errors.
- exception trigdroid.exceptions.ConfigurationError[source]
Bases:
TrigDroidError
Configuration-related errors.
- exception trigdroid.exceptions.DeviceError[source]
Bases:
TrigDroidError
Android device-related errors.
- exception trigdroid.exceptions.TestExecutionError[source]
Bases:
TrigDroidError
Test execution errors.
- exception trigdroid.exceptions.FridaError[source]
Bases:
TrigDroidError
Frida-related errors.
- exception trigdroid.exceptions.HookError[source]
Bases:
FridaError
Hook compilation or injection errors.
- exception trigdroid.exceptions.NetworkError[source]
Bases:
TrigDroidError
Network communication errors.
- exception trigdroid.exceptions.PermissionError[source]
Bases:
DeviceError
Permission-related errors.
- exception trigdroid.exceptions.PackageError[source]
Bases:
DeviceError
Package installation/management errors.