Back to All Articles
Mobile Testing

ADB Shell Commands — Complete Guide for Android Testing

Honnesh Muppala May 5, 2026 10 min read

What is ADB?

ADB (Android Debug Bridge) is a command-line tool that lets you communicate with an Android device from your computer. It is part of the Android SDK platform tools and is essential for mobile testers, developers, and anyone working with Android devices professionally.

ADB enables you to install apps, capture logs, take screenshots, control device settings, and run shell commands — all from your terminal. In my work at Amazon and Virtusa testing Android, Fire OS, and IoT devices, ADB was a daily tool.

Prerequisites: Install Android SDK Platform Tools on your computer. On Mac, run brew install android-platform-tools. On Windows, download from the Android developer site. Then enable USB Debugging on your device (steps below).

Steps to Enable USB Debugging

Before using ADB, you must enable Developer Options and USB Debugging on your Android device:

  1. Connect your device to the computer via USB cable.
  2. On your device, open the Settings app.
  3. Search for Build Number (usually under About Phone).
  4. Tap Build Number 7 times — you'll see "You are now a developer!"
  5. Enter your PIN or password if prompted.
  6. Go back to Settings and search for USB Debugging.
  7. Toggle USB Debugging ON.
  8. A pop-up will ask "Allow USB Debugging?" — tap OK.

Basic ADB Commands

These are the foundational commands every mobile tester should know.

CommandDescription
adb devicesLists all Android devices currently connected to the computer via USB
adb devices -lLists attached devices with detailed information
adb shellOpens an interactive shell on the device — gives you a command-line interface to interact with the Android OS
adb start-serverStarts the ADB server
adb kill-serverStops the ADB server — useful when the device is not detected
adb rebootRestarts the connected Android device

Device Info Commands

These commands retrieve key information about the device — useful at the start of any test session to confirm the build and environment.

# Get Android OS version
adb shell getprop ro.build.version.release

# Get SDK version
adb shell getprop ro.build.version.sdk

# Get device serial number
adb shell getprop ro.serialno

# Get all device properties (useful for full device fingerprint)
adb shell getprop
Real-world use: Before executing any test run, I always capture the build version and SDK to confirm the correct firmware is flashed. This is especially important in IoT device testing at Amazon where multiple build versions were in rotation simultaneously.

Network Commands

These commands help you test and manage network connectivity on the device — essential for IoT and connectivity testing.

CommandDescription
ping 8.8.8.8Tests network stability and connectivity to Google's DNS server (8.8.8.8)
ping google.comTests connectivity and DNS resolution to Google's web server
wpa_cliCommand-line interface for connecting to and managing wireless networks
adb shell svc wifi enableEnables Wi-Fi on the device
adb shell svc wifi disableDisables Wi-Fi on the device
adb shell svc bluetooth enableEnables Bluetooth on the device
adb shell svc bluetooth disableDisables Bluetooth on the device
adb shell settings get global mobile_dataRetrieves whether mobile data is enabled (1) or disabled (0)
What is 8.8.8.8? It is Google's Public DNS server. Pinging it tests raw network connectivity without depending on any specific website being up. If ping 8.8.8.8 passes but ping google.com fails, you have a DNS issue — not a network connectivity issue.

Wireless ADB via TCP/IP

You can connect to your device wirelessly over Wi-Fi without a USB cable — very useful when testing in environments where USB access is restricted.

Steps to connect via TCP/IP

  1. Make sure the device and computer are on the same Wi-Fi network.
  2. Connect the device to the computer via USB cable first.
  3. Verify connection: adb devices
  4. Set the device to listen on a TCP/IP port:
    adb tcpip 2211 (any 4-digit port number works)
  5. Hit Enter — you'll see "restarting in TCP mode port: 2211"
  6. Remove the USB cable.
  7. Find the device's IP address (Settings → Wi-Fi → tap your network → IP Address).
  8. Connect wirelessly:
    adb connect 192.168.1.X:2211
  9. Verify the wireless connection:
    adb devices
# Full TCP/IP workflow
adb tcpip 2211
# Remove USB cable, then:
adb connect 192.168.1.100:2211
adb devices
# Output: 192.168.1.100:2211   device

Screen Commands

ADB lets you capture screenshots and screen recordings directly from the terminal — essential for documenting bugs and test evidence.

CommandDescription
adb shell screencap /sdcard/screenshot.pngCaptures a screenshot and saves it to the device's storage as a PNG file
adb pull /sdcard/screenshot.pngPulls the screenshot from the device to your computer
adb shell screenrecord --verbose /sdcard/recording.mp4Records the device screen and saves it as an MP4 file on the device
adb pull /sdcard/recording.mp4Pulls the screen recording from the device to your computer
adb shell wm sizeRetrieves the display resolution of the device screen
adb shell wm densityRetrieves the screen density (DPI) of the device
# Full screenshot workflow
adb shell screencap /sdcard/bug_screenshot.png
adb pull /sdcard/bug_screenshot.png ~/Desktop/bug_screenshot.png

# Full screen recording workflow
adb shell screenrecord --verbose /sdcard/test_recording.mp4
# Press Ctrl+C to stop recording, then:
adb pull /sdcard/test_recording.mp4 ~/Desktop/test_recording.mp4

Logcat Commands

Logcat is one of the most powerful tools for Android testing. It captures all system logs from the device in real time, letting you filter and trace bugs to their root cause.

CommandDescription
adb logcat -v time -b all > logs.txtCaptures all logs with timestamps from all buffers and saves to a file
adb logcat -v time -b all | grep -i buildFilters logs to show only lines containing "build"
adb logcat -v time -b all | grep -i wifidiagsFilters logs to show only Wi-Fi diagnostic entries
adb logcat -v time -b all | grep -i unifiedFilters logs to show only lines containing "unified"
adb logcat -v time -b color -dRetrieves and displays recent logs with colour highlighting
adb logcat -v time -b all -color -dRetrieves all buffer logs with colour highlighting
# Save full logs to a file for bug reporting
adb logcat -v time -b all > test_session_logs.txt

# Real-time Wi-Fi issue filtering
adb logcat -v time -b all | grep -i wifidiags

# Filter for build info in logs
adb logcat -v time -b all | grep -i build
From Experience: When testing inflight connectivity at Viasat and Wi-Fi coexistence at Amazon, logcat was how we pinpointed root causes. Piping logcat through grep with the right keyword cuts through thousands of log lines to find exactly what you need in seconds.

Package Management Commands

These commands let you inspect, list, and manage all apps installed on the device.

CommandDescription
adb shell pm list packagesLists all installed packages on the device
adb shell pm list packages -dLists only disabled packages
adb shell pm list packages -3Lists only third-party (user-installed) packages
adb shell pm list packages -fLists all packages along with their APK file paths on the device
adb shell pm list permissionsLists all permissions declared by installed packages
# Find a specific app's package name
adb shell pm list packages | grep -i netflix

# List all third-party apps
adb shell pm list packages -3

# Get full path of an APK
adb shell pm list packages -f | grep -i myapp

Settings Commands

ADB can read and write Android system settings directly — useful for automating device configuration in test setups.

CommandDescription
adb shell settings list systemLists all system settings on the device
adb shell settings get system volume_systemGets the current system volume value
adb shell settings list globalLists all global (device-wide) settings
adb shell settings list secure android_idGets the Android ID — a unique identifier assigned to each device
adb shell settings list secure bluetooth_addressGets the Bluetooth MAC address of the device

Battery Commands

These dumpsys battery commands are extremely useful for testing low-battery scenarios, charging behaviour, and power-sensitive features without draining the physical battery.

CommandDescription
adb shell dumpsys battery set level 10Simulates a battery level of 10% — useful for testing low battery warnings
adb shell dumpsys battery set level 100Simulates a full battery level
adb shell dumpsys battery resetResets battery info back to the actual device state
adb shell dumpsys battery set usb 0Simulates USB disconnected — device will not charge
adb shell dumpsys battery set usb 1Simulates USB connected — device will charge
# Test low battery behaviour
adb shell dumpsys battery set level 5

# Test charging connected / disconnected states
adb shell dumpsys battery set usb 1   # charging
adb shell dumpsys battery set usb 0   # not charging

# Always reset after testing
adb shell dumpsys battery reset
Note: Battery level values above 100 (e.g. 1000) are invalid and may cause unexpected behaviour. Always use values between 0–100 for reliable simulation. Always run adb shell dumpsys battery reset at the end of your test to restore real battery readings.

File Operations via ADB Shell

You can create, read, and manage files on the device directly through ADB Shell — useful for preparing test data or verifying file system behaviour.

Steps to create a file on the device

# Enter ADB shell
adb shell

# Navigate to the SD card
cd /sdcard

# Confirm current directory
pwd

# Create a new empty file
touch TestFile.txt

# Write content to the file
echo "Hello, ADB Shell!" > TestFile.txt

# Read the file contents
cat TestFile.txt

# Exit the shell
exit

Pulling files from device to computer

# Pull any file from device to your Desktop
adb pull /sdcard/TestFile.txt ~/Desktop/TestFile.txt

# Pull a folder
adb pull /sdcard/DCIM ~/Desktop/DevicePhotos

ADB for Test Automation Integration

ADB is not just a manual debugging tool — it is a first-class component in automated test pipelines. Combining ADB commands with Python's subprocess.run() lets you control the device, capture evidence, and manage application state directly inside your test scripts without needing a third-party library.

Running ADB Commands from Python Test Scripts

The standard way to invoke ADB from Python is subprocess.run() with capture_output=True. This gives you the command's stdout and stderr as byte strings that you can decode and assert on:

import subprocess

def adb(cmd: list[str]) -> str:
    result = subprocess.run(
        ["adb"] + cmd,
        capture_output=True,
        text=True,
        timeout=30
    )
    if result.returncode != 0:
        raise RuntimeError(f"ADB command failed: {result.stderr.strip()}")
    return result.stdout.strip()

Taking a Screenshot and Pulling It to Host During a Pytest Test

Capturing a screenshot on test failure provides visual evidence for bug reports and is especially useful when tests run unattended in CI. The following pattern hooks into pytest's fixture system to pull a screenshot to the host whenever a test fails:

import subprocess
import pytest

@pytest.fixture(autouse=True)
def capture_screenshot_on_fail(request):
    yield  # test runs here
    if request.node.rep_call.failed:
        test_name = request.node.name
        device_path = f"/sdcard/fail_{test_name}.png"
        host_path = f"screenshots/fail_{test_name}.png"
        subprocess.run(["adb", "shell", "screencap", device_path])
        subprocess.run(["adb", "pull", device_path, host_path])
        print(f"[SCREENSHOT] Saved to {host_path}")

Clearing App Data Before Each Test

Starting every test from a clean application state is essential for test independence. Rather than manually navigating to Settings to clear data, use pm clear in your pytest setup fixture:

PACKAGE = "com.example.myapp"

@pytest.fixture(autouse=True)
def reset_app():
    subprocess.run(["adb", "shell", "pm", "clear", PACKAGE], check=True)
    yield

pm clear wipes all app data, cache, and shared preferences — equivalent to a fresh install without uninstalling and reinstalling the APK. This is significantly faster and ensures every test starts from an identical baseline.

Checking Whether an App Is Running

Before interacting with an app in a test, confirm it is actually running. adb shell pidof returns the process ID if the app is active, or an empty string if it is not:

def is_app_running(package: str) -> bool:
    result = subprocess.run(
        ["adb", "shell", "pidof", package],
        capture_output=True, text=True
    )
    return result.stdout.strip() != ""

Setting Up ADB in GitHub Actions CI

Running ADB-based tests in a GitHub Actions pipeline requires installing the Android SDK platform-tools, starting an emulator, and waiting for it to fully boot before the first test executes:

- name: Install Android SDK platform-tools
  run: sudo apt-get install -y android-sdk

- name: Start Android emulator
  run: |
    $ANDROID_HOME/emulator/emulator -avd test_avd -no-window -no-audio &

- name: Wait for emulator boot
  run: adb wait-for-device shell 'while [ "$(getprop sys.boot_completed)" != "1" ]; do sleep 2; done'

- name: Run tests
  run: pytest tests/ -v

adb wait-for-device blocks until ADB can see the emulator, but it does not mean the Android OS has finished booting. The getprop sys.boot_completed poll is the correct signal that the emulator is truly ready to receive app interactions.

Capturing Logcat During Tests

Starting logcat in the background during your test run and killing it after gives you a complete device log for any test that fails. Parse the output for specific tags or error keywords:

import subprocess, signal

logcat_proc = subprocess.Popen(
    ["adb", "logcat", "-v", "time", "-b", "all"],
    stdout=open("test_logcat.txt", "w"),
    stderr=subprocess.DEVNULL
)
# ... run tests ...
logcat_proc.send_signal(signal.SIGINT)  # stop logcat after tests finish

# Parse for crashes
with open("test_logcat.txt") as f:
    if "FATAL EXCEPTION" in f.read():
        print("[WARNING] Crash detected in logcat")

Common ADB Automation Pitfalls


Back to Blog
From Experience — Amazon: At Amazon's Device OS team, ADB shell was the primary tool for day-to-day device testing on Alexa, Echo, and Fire TV. We flashed 500+ new builds across the device pool during active release cycles. Having reliable ADB scripting for automated flash-and-verify sequences was the difference between a 2-hour release window and an all-day manual grind. I also used ADB logcat filtering extensively to isolate Wi-Fi and Bluetooth coexistence failures — the raw logs are noisy, but the right grep patterns surface the signal immediately.