pymllm.utils.adb¶
Classes¶
Manages a persistent 'adb shell' session for a specific device. |
|
Module Contents¶
- class pymllm.utils.adb.ShellContext(adb_path, device_id=None)¶
Manages a persistent ‘adb shell’ session for a specific device. This allows running a series of commands that maintain state, such as environment variables or the current working directory.
It’s recommended to use this class as a context manager (with statement) to ensure the shell session is always closed properly.
Example
- with adb.get_shell_context(device_id) as shell:
shell.execute(“export MY_VAR=hello”) output = shell.execute(“echo $MY_VAR”) print(output) # Should print “hello”
Note: This class is not thread-safe. A single instance should only be used from one thread at a time.
- Parameters:
adb_path (str)
device_id (Optional[str])
- adb_path¶
- device_id = None¶
- execute(command)¶
Executes a command in the persistent shell. :param command: The shell command to execute. :return: The output (stdout and stderr) of the command.
- Parameters:
command (str)
- Return type:
str
- close()¶
Terminates the shell session and cleans up resources.
- is_alive()¶
Checks if the shell process is still running.
- Return type:
bool
- __enter__()¶
Enter the context manager.
- __exit__(exc_type, exc_val, exc_tb)¶
Exit the context manager, ensuring the shell is closed.
- class pymllm.utils.adb.ADBToolkit(adb_path='adb')¶
- Parameters:
adb_path (str)
- adb_path = 'adb'¶
- get_shell_context(device_id=None)¶
Get a persistent shell context to a device. This allows running commands that maintain state (e.g., environment variables). It is highly recommended to use this with a ‘with’ statement.
- Parameters:
device_id (Optional[str]) – Target device ID. If None, and only one device is connected, it will be used automatically.
- Returns:
A ShellContext instance.
- Return type:
- get_devices()¶
Get list of connected devices
- Return type:
List[Dict[str, str]]
- install_apk(apk_path, device_id=None)¶
Install APK file on device
- Parameters:
apk_path (str)
device_id (str)
- Return type:
bool
- uninstall_app(package_name, device_id=None)¶
Uninstall application from device
- Parameters:
package_name (str)
device_id (str)
- Return type:
bool
- push_file(local_path, device_path, device_id=None)¶
Push file to device
- Parameters:
local_path (str)
device_path (str)
device_id (str)
- Return type:
bool
- pull_file(device_path, local_path, device_id=None)¶
Pull file from device
- Parameters:
device_path (str)
local_path (str)
device_id (str)
- Return type:
bool
- take_screenshot(save_path, device_id=None)¶
Capture device screenshot
- Parameters:
save_path (str)
device_id (str)
- Return type:
bool
- record_screen(save_path, duration=60, device_id=None)¶
Record device screen
- Parameters:
save_path (str)
duration (int)
device_id (str)
- Return type:
bool
- execute_command(command, device_id=None)¶
Execute a single, stateless shell command on device. This command will NOT maintain context like environment variables. For stateful sessions, use get_shell_context().
- Parameters:
command (str)
device_id (str)
- Return type:
str
- get_device_info(device_id=None)¶
Get device information
- Parameters:
device_id (str)
- Return type:
Dict[str, str]
- reboot_device(device_id=None)¶
Reboot device
- Parameters:
device_id (str)
- Return type:
bool