Infrastructure Layer

The TrigDroid infrastructure layer provides the core services and abstractions.

Interfaces

Core abstractions and protocol definitions.

Core interfaces for TrigDroid following SOLID principles.

This module defines the core abstractions that enable dependency inversion and make the system more maintainable and testable.

class TrigDroid_Infrastructure.interfaces.LogLevel(value)[source]

Bases: Enum

Logging levels for the application.

DEBUG = 'DEBUG'
INFO = 'INFO'
WARNING = 'WARNING'
ERROR = 'ERROR'
CRITICAL = 'CRITICAL'
class TrigDroid_Infrastructure.interfaces.TestResult(value)[source]

Bases: Enum

Result of test execution.

SUCCESS = 'SUCCESS'
FAILURE = 'FAILURE'
SKIPPED = 'SKIPPED'
class TrigDroid_Infrastructure.interfaces.DeviceConnectionState(value)[source]

Bases: Enum

Android device connection states.

CONNECTED = 'CONNECTED'
DISCONNECTED = 'DISCONNECTED'
UNAUTHORIZED = 'UNAUTHORIZED'
class TrigDroid_Infrastructure.interfaces.ILogger(*args, **kwargs)[source]

Bases: Protocol

Logger interface for dependency inversion.

debug(message, *args)[source]
Parameters:
Return type:

None

info(message, *args)[source]
Parameters:
Return type:

None

warning(message, *args)[source]
Parameters:
Return type:

None

error(message, *args)[source]
Parameters:
Return type:

None

critical(message, *args)[source]
Parameters:
Return type:

None

__init__(*args, **kwargs)
class TrigDroid_Infrastructure.interfaces.IConfigurationProvider(*args, **kwargs)[source]

Bases: Protocol

Configuration provider interface.

get_value(key)[source]
Parameters:

key (str)

Return type:

str | int | bool | List[str] | None

set_value(key, value)[source]
Parameters:
Return type:

None

has_key(key)[source]
Parameters:

key (str)

Return type:

bool

validate()[source]
Return type:

bool

__init__(*args, **kwargs)
class TrigDroid_Infrastructure.interfaces.IConfigurationValidator(*args, **kwargs)[source]

Bases: Protocol

Configuration validation interface.

validate_config(config)[source]
Parameters:

config (Dict[str, str | int | bool | List[str] | None])

Return type:

List[str]

is_valid(key, value)[source]
Parameters:
Return type:

bool

__init__(*args, **kwargs)
class TrigDroid_Infrastructure.interfaces.IAndroidDevice(*args, **kwargs)[source]

Bases: Protocol

Android device interface.

execute_command(command)[source]
Parameters:

command (str)

Return type:

ICommandResult

install_app(apk_path)[source]
Parameters:

apk_path (str)

Return type:

bool

uninstall_app(package_name)[source]
Parameters:

package_name (str)

Return type:

bool

start_app(package_name)[source]
Parameters:

package_name (str)

Return type:

bool

stop_app(package_name)[source]
Parameters:

package_name (str)

Return type:

bool

is_app_installed(package_name)[source]
Parameters:

package_name (str)

Return type:

bool

get_device_info()[source]
Return type:

Dict[str, str]

__init__(*args, **kwargs)
class TrigDroid_Infrastructure.interfaces.ICommandResult(*args, **kwargs)[source]

Bases: Protocol

Command execution result interface.

property return_code: int
property stdout: bytes
property stderr: bytes
property success: bool
__init__(*args, **kwargs)
class TrigDroid_Infrastructure.interfaces.ITestRunner(*args, **kwargs)[source]

Bases: Protocol

Test runner interface for different test types.

can_run(test_type)[source]
Parameters:

test_type (str)

Return type:

bool

execute(context)[source]
Parameters:

context (ITestContext)

Return type:

TestResult

setup()[source]
Return type:

bool

teardown()[source]
Return type:

bool

__init__(*args, **kwargs)
class TrigDroid_Infrastructure.interfaces.ITestContext(*args, **kwargs)[source]

Bases: Protocol

Test execution context interface.

property device: IAndroidDevice
property config: IConfigurationProvider
property logger: ILogger
property package_name: str
__init__(*args, **kwargs)
class TrigDroid_Infrastructure.interfaces.IFridaHookProvider(*args, **kwargs)[source]

Bases: Protocol

Frida hook provider interface.

get_hook_script()[source]
Return type:

str

get_hook_config()[source]
Return type:

Dict[str, Any]

supports_hook(hook_name)[source]
Parameters:

hook_name (str)

Return type:

bool

__init__(*args, **kwargs)
class TrigDroid_Infrastructure.interfaces.IChangelogWriter(*args, **kwargs)[source]

Bases: Protocol

Changelog writer interface.

write_entry(property_name, old_value, new_value, description='')[source]
Parameters:
  • property_name (str)

  • old_value (str)

  • new_value (str)

  • description (str)

Return type:

None

flush()[source]
Return type:

None

__init__(*args, **kwargs)
class TrigDroid_Infrastructure.interfaces.IApplicationOrchestrator(*args, **kwargs)[source]

Bases: Protocol

Main application orchestrator interface.

setup()[source]
Return type:

bool

execute_tests()[source]
Return type:

bool

teardown()[source]
Return type:

bool

__init__(*args, **kwargs)
class TrigDroid_Infrastructure.interfaces.TestRunnerBase(logger)[source]

Bases: ABC

Base class for test runners implementing common functionality.

Parameters:

logger (ILogger)

__init__(logger)[source]
Parameters:

logger (ILogger)

abstract can_run(test_type)[source]

Check if this runner can handle the given test type.

Parameters:

test_type (str)

Return type:

bool

execute(context)[source]

Execute the test with proper error handling.

Parameters:

context (ITestContext)

Return type:

TestResult

setup()[source]

Setup the test runner.

Return type:

bool

teardown()[source]

Cleanup after test execution.

Return type:

bool

class TrigDroid_Infrastructure.interfaces.ConfigurationProviderBase(logger)[source]

Bases: ABC

Base class for configuration providers.

Parameters:

logger (ILogger)

__init__(logger)[source]
Parameters:

logger (ILogger)

get_value(key)[source]

Get configuration value by key.

Parameters:

key (str)

Return type:

str | int | bool | List[str] | None

set_value(key, value)[source]

Set configuration value.

Parameters:
Return type:

None

has_key(key)[source]

Check if configuration key exists.

Parameters:

key (str)

Return type:

bool

Application Layer

Main application orchestration and workflow coordination.

Infrastructure Services

Core infrastructure services including dependency injection, logging, and configuration.

Dependency Injection

Dependency Injection Container for TrigDroid.

This module implements a simple but effective dependency injection container that follows the Dependency Inversion Principle and enables loose coupling between components.

class TrigDroid_Infrastructure.infrastructure.dependency_injection.DIContainer[source]

Bases: object

Simple dependency injection container.

__init__()[source]
register_singleton(interface, implementation, name=None)[source]

Register a singleton service.

Parameters:
Return type:

DIContainer

register_transient(interface, implementation, name=None)[source]

Register a transient service (new instance every time).

Parameters:
Return type:

DIContainer

register_instance(interface, instance, name=None)[source]

Register a specific instance.

Parameters:
  • interface (Type[T])

  • instance (T)

  • name (str | None)

Return type:

DIContainer

resolve(interface, name=None)[source]

Resolve a service instance.

Parameters:
  • interface (Type[T])

  • name (str | None)

Return type:

T

has_service(interface, name=None)[source]

Check if a service is registered.

Parameters:
  • interface (Type[T])

  • name (str | None)

Return type:

bool

class TrigDroid_Infrastructure.infrastructure.dependency_injection.ServiceLocator[source]

Bases: object

Service locator pattern implementation.

classmethod set_container(container)[source]

Set the global container.

Parameters:

container (DIContainer)

Return type:

None

classmethod get_service(interface, name=None)[source]

Get a service from the global container.

Parameters:
  • interface (Type[T])

  • name (str | None)

Return type:

T

class TrigDroid_Infrastructure.infrastructure.dependency_injection.Injectable[source]

Bases: ABC

Base class for injectable services.

__init__()[source]
set_container(container)[source]

Set the DI container for this service.

Parameters:

container (DIContainer)

Return type:

None

get_service(interface, name=None)[source]

Get a service from the container.

Parameters:
  • interface (Type[T])

  • name (str | None)

Return type:

T

TrigDroid_Infrastructure.infrastructure.dependency_injection.configure_container()[source]

Configure the dependency injection container with TrigDroid services.

Return type:

DIContainer

TrigDroid_Infrastructure.infrastructure.dependency_injection.inject(**dependencies)[source]

Decorator to inject dependencies into a class constructor.

TrigDroid_Infrastructure.infrastructure.dependency_injection.inject_service(interface, name=None)[source]

Decorator to inject a single service.

Parameters:
  • interface (Type[T])

  • name (str | None)

Android Integration

Android device abstraction following SOLID principles.

This module provides a clean abstraction over ADB operations that can be easily tested and extended.

class TrigDroid_Infrastructure.infrastructure.android.CommandResult(return_code, stdout, stderr)[source]

Bases: ICommandResult

Implementation of command result interface.

Parameters:
__init__(return_code, stdout, stderr)[source]
Parameters:
property return_code: int

Return code of the command.

property stdout: bytes

Standard output.

property stderr: bytes

Standard error output.

property success: bool

Whether the command was successful.

class TrigDroid_Infrastructure.infrastructure.android.AndroidDevice(logger, device_id=None)[source]

Bases: IAndroidDevice, Injectable

Android device implementation using ADB.

Parameters:
__init__(logger, device_id=None)[source]
Parameters:
execute_command(command)[source]

Execute an ADB command.

Parameters:

command (str)

Return type:

ICommandResult

install_app(apk_path)[source]

Install an APK file.

Parameters:

apk_path (str)

Return type:

bool

uninstall_app(package_name)[source]

Uninstall an application.

Parameters:

package_name (str)

Return type:

bool

start_app(package_name=None)[source]

Start an application.

Parameters:

package_name (str | None)

Return type:

bool

stop_app(package_name=None)[source]

Stop an application.

Parameters:

package_name (str | None)

Return type:

bool

is_app_installed(package_name)[source]

Check if an application is installed.

Parameters:

package_name (str)

Return type:

bool

get_device_info()[source]

Get device information.

Return type:

Dict[str, str]

set_current_package(package_name)[source]

Set the current test package.

Parameters:

package_name (str)

Return type:

None

get_connection_state()[source]

Get the device connection state.

Return type:

DeviceConnectionState

grant_permission(package_name, permission)[source]

Grant a permission to an app.

Parameters:
  • package_name (str)

  • permission (str)

Return type:

bool

revoke_permission(package_name, permission)[source]

Revoke a permission from an app.

Parameters:
  • package_name (str)

  • permission (str)

Return type:

bool

push_file(local_path, remote_path)[source]

Push a file to the device.

Parameters:
  • local_path (str)

  • remote_path (str)

Return type:

bool

pull_file(remote_path, local_path)[source]

Pull a file from the device.

Parameters:
  • remote_path (str)

  • local_path (str)

Return type:

bool

root()[source]

Root the ADB connection.

Return type:

bool

unroot()[source]

Unroot the ADB connection.

Return type:

bool

class TrigDroid_Infrastructure.infrastructure.android.DeviceManager(logger)[source]

Bases: object

Manager for discovering and connecting to Android devices.

Parameters:

logger (ILogger)

__init__(logger)[source]
Parameters:

logger (ILogger)

list_devices()[source]

List all connected devices.

Return type:

List[str]

connect_to_device(device_id=None)[source]

Connect to a specific device or auto-select if only one available.

Parameters:

device_id (str | None)

Return type:

AndroidDevice | None

Configuration Management

Configuration system refactored to follow SOLID principles.

This module provides a clean separation between configuration sources, validation, and consumption following the Single Responsibility Principle.

exception TrigDroid_Infrastructure.infrastructure.configuration.ConfigurationError[source]

Bases: Exception

Configuration-related errors.

class TrigDroid_Infrastructure.infrastructure.configuration.CommandLineConfigProvider(parser=None)[source]

Bases: IConfigurationProvider

Configuration provider for command line arguments.

Parameters:

parser (ArgumentParser | None)

__init__(parser=None)[source]
Parameters:

parser (ArgumentParser | None)

get_value(key)[source]

Get configuration value by key.

Parameters:

key (str)

Return type:

str | int | bool | List[str] | None

set_value(key, value)[source]

Set configuration value.

Parameters:
Return type:

None

has_key(key)[source]

Check if configuration key exists.

Parameters:

key (str)

Return type:

bool

validate()[source]

Validate the configuration.

Return type:

bool

class TrigDroid_Infrastructure.infrastructure.configuration.YamlConfigProvider(config_path=None)[source]

Bases: IConfigurationProvider

Configuration provider for YAML files.

Parameters:

config_path (str | None)

__init__(config_path=None)[source]
Parameters:

config_path (str | None)

get_value(key)[source]

Get configuration value by key.

Parameters:

key (str)

Return type:

str | int | bool | List[str] | None

set_value(key, value)[source]

Set configuration value.

Parameters:
Return type:

None

has_key(key)[source]

Check if configuration key exists.

Parameters:

key (str)

Return type:

bool

validate()[source]

Validate the YAML structure.

Return type:

bool

set_config_path(path)[source]

Set the configuration file path.

Parameters:

path (str)

Return type:

None

class TrigDroid_Infrastructure.infrastructure.configuration.CompositeConfigurationProvider(providers)[source]

Bases: IConfigurationProvider

Configuration provider that merges multiple sources.

Parameters:

providers (List[IConfigurationProvider])

__init__(providers)[source]
Parameters:

providers (List[IConfigurationProvider])

get_value(key)[source]

Get configuration value, checking providers in order.

Parameters:

key (str)

Return type:

str | int | bool | List[str] | None

set_value(key, value)[source]

Set value in the first provider.

Parameters:
Return type:

None

has_key(key)[source]

Check if any provider has the key.

Parameters:

key (str)

Return type:

bool

validate()[source]

Validate all providers.

Return type:

bool

class TrigDroid_Infrastructure.infrastructure.configuration.ConfigurationValidator(logger)[source]

Bases: IConfigurationValidator, Injectable

Validates configuration values according to rules.

Parameters:

logger (ILogger)

__init__(logger)[source]
Parameters:

logger (ILogger)

validate_config(config)[source]

Validate entire configuration and return list of errors.

Parameters:

config (Dict[str, str | int | bool | List[str] | None])

Return type:

List[str]

is_valid(key, value)[source]

Check if a single value is valid.

Parameters:
Return type:

bool

class TrigDroid_Infrastructure.infrastructure.configuration.ConfigurationManager(config_provider, validator, logger)[source]

Bases: Injectable

High-level configuration manager that coordinates providers and validation.

Parameters:
__init__(config_provider, validator, logger)[source]
Parameters:
get_value(key, default=None)[source]

Get a configuration value with optional default.

Parameters:
Return type:

str | int | bool | List[str] | None

get_required_value(key)[source]

Get a required configuration value, raising error if missing.

Parameters:

key (str)

Return type:

str | int | bool | List[str] | None

validate_configuration()[source]

Validate the entire configuration.

Return type:

bool

class TrigDroid_Infrastructure.infrastructure.configuration.ConfigurationBuilder[source]

Bases: object

Builder pattern for creating configuration managers.

__init__()[source]
add_command_line_provider(parser=None)[source]

Add command line configuration provider.

Parameters:

parser (ArgumentParser | None)

Return type:

ConfigurationBuilder

add_yaml_provider(config_path=None)[source]

Add YAML configuration provider.

Parameters:

config_path (str | None)

Return type:

ConfigurationBuilder

set_validator(validator)[source]

Set the configuration validator.

Parameters:

validator (IConfigurationValidator)

Return type:

ConfigurationBuilder

set_logger(logger)[source]

Set the logger.

Parameters:

logger (ILogger)

Return type:

ConfigurationBuilder

build()[source]

Build the configuration manager.

Return type:

ConfigurationManager

Logging Infrastructure

Logging infrastructure following SOLID principles.

This module provides a clean logging abstraction that can be easily extended and tested.

class TrigDroid_Infrastructure.infrastructure.logging.LogFormatter(extended_format=False)[source]

Bases: Formatter

Custom formatter for TrigDroid logs.

Parameters:

extended_format (bool)

__init__(extended_format=False)[source]

Initialize the formatter with specified format strings.

Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.

Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting, str.format() ({}) formatting or string.Template formatting in your format string.

Changed in version 3.2: Added the style parameter.

Parameters:

extended_format (bool)

class TrigDroid_Infrastructure.infrastructure.logging.StandardLogger(name='TrigDroid', level=LogLevel.INFO, log_file=None, suppress_console=False, extended_format=False)[source]

Bases: ILogger

Standard logger implementation using Python’s logging module.

Parameters:
__init__(name='TrigDroid', level=LogLevel.INFO, log_file=None, suppress_console=False, extended_format=False)[source]
Parameters:
debug(message, *args)[source]

Log debug message.

Parameters:
Return type:

None

info(message, *args)[source]

Log info message.

Parameters:
Return type:

None

warning(message, *args)[source]

Log warning message.

Parameters:
Return type:

None

error(message, *args)[source]

Log error message.

Parameters:
Return type:

None

critical(message, *args)[source]

Log critical message.

Parameters:
Return type:

None

set_level(level)[source]

Set the logging level.

Parameters:

level (LogLevel)

Return type:

None

class TrigDroid_Infrastructure.infrastructure.logging.FilteredLogger(base_logger, include_patterns=None, exclude_patterns=None)[source]

Bases: ILogger

Logger wrapper that applies include/exclude filters.

Parameters:
__init__(base_logger, include_patterns=None, exclude_patterns=None)[source]
Parameters:
debug(message, *args)[source]

Log debug message if it passes filters.

Parameters:
Return type:

None

info(message, *args)[source]

Log info message if it passes filters.

Parameters:
Return type:

None

warning(message, *args)[source]

Log warning message if it passes filters.

Parameters:
Return type:

None

error(message, *args)[source]

Log error message if it passes filters.

Parameters:
Return type:

None

critical(message, *args)[source]

Log critical message if it passes filters.

Parameters:
Return type:

None

class TrigDroid_Infrastructure.infrastructure.logging.NullLogger(*args, **kwargs)[source]

Bases: ILogger

Null object pattern logger for testing.

debug(message, *args)[source]

No-op debug.

Parameters:
Return type:

None

info(message, *args)[source]

No-op info.

Parameters:
Return type:

None

warning(message, *args)[source]

No-op warning.

Parameters:
Return type:

None

error(message, *args)[source]

No-op error.

Parameters:
Return type:

None

critical(message, *args)[source]

No-op critical.

Parameters:
Return type:

None

class TrigDroid_Infrastructure.infrastructure.logging.LoggerFactory[source]

Bases: object

Factory for creating different types of loggers.

static create_standard_logger(name='TrigDroid', level=LogLevel.INFO, log_file=None, suppress_console=False, extended_format=False)[source]

Create a standard logger.

Parameters:
Return type:

ILogger

static create_filtered_logger(base_logger, include_patterns=None, exclude_patterns=None)[source]

Create a filtered logger.

Parameters:
Return type:

ILogger

static create_null_logger()[source]

Create a null logger for testing.

Return type:

ILogger

static create_composite_logger(name='TrigDroid', level=LogLevel.INFO, log_file=None, suppress_console=False, extended_format=False, include_patterns=None, exclude_patterns=None)[source]

Create a logger with all features.

Parameters:
Return type:

ILogger

Test Runners

Pluggable test execution engines for different testing scenarios.

Base Test Runner

Sensor Test Runner

Sensor test runner implementation.

This module handles sensor-related test operations including accelerometer, gyroscope, light, and pressure sensor manipulations.

class TrigDroid_Infrastructure.test_runners.sensor_test_runner.SensorType(value)[source]

Bases: Enum

Supported sensor types.

ACCELEROMETER = 'accelerometer'
GYROSCOPE = 'gyroscope'
LIGHT = 'light'
PRESSURE = 'pressure'
MAGNETOMETER = 'magnetometer'
class TrigDroid_Infrastructure.test_runners.sensor_test_runner.SensorTestRunner(logger)[source]

Bases: TestRunnerBase

Test runner for sensor-based operations.

Parameters:

logger (ILogger)

SUPPORTED_TESTS = ['sensor_rotation', 'sensor_initial_values', 'sensor_power_manipulation', 'sensor_availability']
__init__(logger)[source]
Parameters:

logger (ILogger)

can_run(test_type)[source]

Check if this runner can handle the given test type.

Parameters:

test_type (str)

Return type:

bool

Frida Test Runner

Frida test runner implementation.

This module handles Frida-based instrumentation and hooking operations for runtime environment manipulation.

class TrigDroid_Infrastructure.test_runners.frida_test_runner.FridaTestRunner(logger, hook_provider)[source]

Bases: TestRunnerBase

Test runner for Frida-based instrumentation.

Parameters:
SUPPORTED_TESTS = ['frida_hooks', 'runtime_instrumentation', 'api_hooking', 'environment_spoofing']
__init__(logger, hook_provider)[source]
Parameters:
can_run(test_type)[source]

Check if this runner can handle the given test type.

Parameters:

test_type (str)

Return type:

bool

setup()[source]

Setup Frida server and prepare hook scripts.

Return type:

bool

teardown()[source]

Cleanup Frida server and temporary files.

Return type:

bool

is_frida_needed(context)[source]

Check if Frida is needed for the current configuration.

Parameters:

context (ITestContext)

Return type:

bool

class TrigDroid_Infrastructure.test_runners.frida_test_runner.FridaServerManager(logger)[source]

Bases: object

Manages Frida server lifecycle on Android devices.

Parameters:

logger (ILogger)

__init__(logger)[source]
Parameters:

logger (ILogger)

start_server(device_id=None, server_path='/data/local/tmp/frida-server')[source]

Start Frida server on the device.

Parameters:
  • device_id (str | None)

  • server_path (str)

Return type:

bool

stop_server()[source]

Stop the Frida server.

Return type:

bool

is_running()[source]

Check if the Frida server is running.

Return type:

bool

Test Context

Test context implementation for TrigDroid.

This module provides the test execution context that contains all necessary dependencies for test runners.

class TrigDroid_Infrastructure.test_runners.test_context.TestContext(device, config, logger, package_name)[source]

Bases: ITestContext

Implementation of test execution context.

Parameters:
__init__(device, config, logger, package_name)[source]
Parameters:
property device: IAndroidDevice

Get the Android device instance.

property config: IConfigurationProvider

Get the configuration provider.

property logger: ILogger

Get the logger instance.

property package_name: str

Get the package name being tested.