Initializes and starts the persistent shell session. :param adb_path: Path to the adb executable. :param device_id: The ID of the target device.
(self, adb_path: str, device_id: Optional[str] = None)
| 29 | """ |
| 30 | |
| 31 | def __init__(self, adb_path: str, device_id: Optional[str] = None): |
| 32 | """ |
| 33 | Initializes and starts the persistent shell session. |
| 34 | :param adb_path: Path to the adb executable. |
| 35 | :param device_id: The ID of the target device. |
| 36 | """ |
| 37 | self.adb_path = adb_path |
| 38 | self.device_id = device_id |
| 39 | # A unique marker to detect the end of a command's output. |
| 40 | # This is a reliable way to read output without trying to parse |
| 41 | # shell prompts, which can change and are unreliable. |
| 42 | self._end_marker = f"END_OF_COMMAND_{''.join(random.choices(string.ascii_letters + string.digits, k=32))}" |
| 43 | self._process = self._start_shell() |
| 44 | # Read and discard any initial startup messages or the first prompt. |
| 45 | self._consume_initial_prompt() |
| 46 | |
| 47 | def _start_shell(self) -> subprocess.Popen: |
| 48 | """Starts the underlying 'adb shell' process.""" |
nothing calls this directly
no test coverage detected