pymllm.utils.adb ================ .. py:module:: pymllm.utils.adb Classes ------- .. autoapisummary:: pymllm.utils.adb.ShellContext pymllm.utils.adb.ADBToolkit Module Contents --------------- .. py:class:: 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. .. rubric:: 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. .. py:attribute:: adb_path .. py:attribute:: device_id :value: None .. py:method:: 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. .. py:method:: close() Terminates the shell session and cleans up resources. .. py:method:: is_alive() Checks if the shell process is still running. .. py:method:: __enter__() Enter the context manager. .. py:method:: __exit__(exc_type, exc_val, exc_tb) Exit the context manager, ensuring the shell is closed. .. py:class:: ADBToolkit(adb_path = 'adb') .. py:attribute:: adb_path :value: 'adb' .. py:method:: 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. :param device_id: Target device ID. If None, and only one device is connected, it will be used automatically. :return: A ShellContext instance. .. py:method:: get_devices() Get list of connected devices .. py:method:: install_apk(apk_path, device_id = None) Install APK file on device .. py:method:: uninstall_app(package_name, device_id = None) Uninstall application from device .. py:method:: push_file(local_path, device_path, device_id = None) Push file to device .. py:method:: pull_file(device_path, local_path, device_id = None) Pull file from device .. py:method:: take_screenshot(save_path, device_id = None) Capture device screenshot .. py:method:: record_screen(save_path, duration = 60, device_id = None) Record device screen .. py:method:: 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(). .. py:method:: get_device_info(device_id = None) Get device information .. py:method:: reboot_device(device_id = None) Reboot device