Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/nokia/moler/llms.txt

Use this file to discover all available pages before exploring further.

Moler provides ADB command support through a small set of purpose-built classes. All ADB commands inherit from GenericAdbCommand (moler.cmd.adb.generic_adb_command), which itself extends CommandTextualGeneric.
ADB commands assume the adb binary is on the system PATH and at least one Android device is connected or authorised via USB/TCP.

Command list

ClassModuleShell command
AdbShellmoler.cmd.adb.adb_shelladb shell / adb -s <serial> shell
GenericAdbCommandmoler.cmd.adb.generic_adb_command(abstract base)

Detailed reference

AdbShellmoler.cmd.adb.adb_shell

Opens an interactive adb shell session on the target Android device, changing the active prompt to the device shell prompt. Command failure indicators (command not found, error:, etc.) automatically set a CommandFailure exception.
connection
object
required
Moler connection to the host machine running adb.
serial_number
str
Device serial number as shown in adb devices. When provided, the command runs as adb -s <serial_number> shell.
prompt
str
Regex for the starting shell prompt (on the host). Defaults to generic detection.
expected_prompt
str | re.Pattern
Regex for the device shell prompt. If prompt_from_serial_number=True this is auto-generated.
set_timeout
str
Shell command sent after connection to set the session timeout.
set_prompt
str
Shell command sent after connection to customise the prompt (e.g. export PS1=...).
target_newline
str
Newline character(s) used on the Android device. Default "\n".
allowed_newline_after_prompt
bool
Allow extra newlines after the expected prompt. Default False.
prompt_from_serial_number
bool
When True, auto-generates an expected_prompt and set_prompt from serial_number
producing a unique prompt like adb_shell@<serial> $. Default False.
Return value AdbShell is a connection-changing command. It does not return a data dict; success means the active connection prompt has changed to the device shell. ret_required is False.
from moler.cmd.adb.adb_shell import AdbShell

cmd = AdbShell(
    connection=conn,
    expected_prompt=r'shell@device:/ \$',
)
cmd()  # prompt on `conn` is now the device shell
After AdbShell completes, the connection object now speaks to the Android device shell. You can then run Unix-style commands (from moler.cmd.unix) on the same connection.

Using ADB in a test scenario

from moler.cmd.adb.adb_shell import AdbShell
from moler.cmd.unix.ls import Ls
from moler.cmd.unix.ps import Ps

# 1. Open adb shell
open_shell = AdbShell(
    connection=conn,
    serial_number="emulator-5554",
    prompt_from_serial_number=True,
)
open_shell()

# 2. Now run Unix commands on the device
ls_cmd = Ls(connection=conn, options="-la", path="/data")
files = ls_cmd()

ps_cmd = Ps(connection=conn, options="-A")
processes = ps_cmd()

for proc in processes:
    print(proc.get('PID'), proc.get('NAME'))

Build docs developers (and LLMs) love