diff --git a/android_env/components/adb_controller.py b/android_env/components/adb_controller.py index 53191f4..1e0b5dd 100644 --- a/android_env/components/adb_controller.py +++ b/android_env/components/adb_controller.py @@ -30,11 +30,8 @@ class AdbController: def __init__(self, config: config_classes.AdbControllerConfig): """Instantiates an AdbController object.""" - self._device_name = config.device_name - self._adb_path = os.path.expandvars(config.adb_path) - self._adb_server_port = str(config.adb_server_port) - self._default_timeout = config.default_timeout - logging.info('adb_path: %r', self._adb_path) + self._config = config + logging.info('config: %r', self._config) # Unset problematic environment variables. ADB commands will fail if these # are set. They are normally exported by AndroidStudio. @@ -52,9 +49,13 @@ def __init__(self, config: config_classes.AdbControllerConfig): def command_prefix(self, include_device_name: bool = True) -> list[str]: """The command for instantiating an adb client to this server.""" - command_prefix = [self._adb_path, '-P', self._adb_server_port] + command_prefix = [ + self._config.adb_path, + '-P', + str(self._config.adb_server_port), + ] if include_device_name: - command_prefix.extend(['-s', self._device_name]) + command_prefix.extend(['-s', self._config.device_name]) return command_prefix def init_server(self, timeout: float | None = None): @@ -108,7 +109,7 @@ def execute_command( Returns: The output of running such command as a binary string. """ - timeout = self._default_timeout if timeout is None else timeout + timeout = self._config.default_timeout if timeout is None else timeout command = self.command_prefix(include_device_name=device_specific) + args command_str = 'adb ' + ' '.join(command[1:]) diff --git a/android_env/components/config_classes.py b/android_env/components/config_classes.py index 49e0eba..d443e2b 100644 --- a/android_env/components/config_classes.py +++ b/android_env/components/config_classes.py @@ -22,14 +22,17 @@ class AdbControllerConfig: """Settings for instatiating an `AdbController` instance.""" - # Name of the device to communicate with. - device_name: str = '' # Filesystem path to the `adb` binary. + # NOTE: This must be a full path and must not contain environment variables + # or user folder shorthands (e.g. `~/some/path/to/adb`) since they will not be + # expanded internally by AndroidEnv. adb_path: str = 'adb' # Port for adb server. adb_server_port: int = 5037 # Default timeout in seconds for internal commands. default_timeout: float = 120.0 + # Name of the device to communicate with. + device_name: str = '' @dataclasses.dataclass diff --git a/android_env/components/simulators/emulator/emulator_launcher.py b/android_env/components/simulators/emulator/emulator_launcher.py index 22c4932..951d5c0 100644 --- a/android_env/components/simulators/emulator/emulator_launcher.py +++ b/android_env/components/simulators/emulator/emulator_launcher.py @@ -69,10 +69,6 @@ def __init__( """ self._adb_controller_config = adb_controller_config - self._adb_controller_config.adb_path = os.path.expandvars( - self._adb_controller_config.adb_path - ) - self._adb_port = adb_port self._emulator_console_port = emulator_console_port self._grpc_port = grpc_port