ADB Debugging
adb devices
# List of devices attached
adb devices
# List connected devices (-l for long output)
adb devices -l
adb forward
# List all forward socket connections
adb forward --list
# Set up port forwarding
adb forward tcp:6123 tcp:7123
# This sets up forwarding of computer port 6123
# to Android device port 7123
adb kill-server
# Terminates the adb server process
adb kill-server
# Notes: kill the server if it is running.
# (terminal adb.exe process)
Wireless
adb connect
# STEP 1.
# Set the target device to listen for a TCP/IP connection on port 5555
# Disconnect the USB cable from the Android device
adb tcpip 5555
# STEP 2.
# Connect to a device over Wi-Fi.
# Find your Android device IP address at
## Settings > About phone > Status > IP address
adb connect 192.168.100.12
# STEP 3.
# Confirm that your host computer is connected to the Android device over Wi-Fi
adb devices
List of devices attached
192.168.100.12:5555 device
adb usb
# Restarting in USB mode
adb usb
Package Manager
adb install
# App installation - push a single package to the device and install it
adb install test.apk
# App installation - push multiple APKs to the device for a single package and install them
adb install-multiple test.apk test2.apk
# App installation - push one or more packages to the device and install them atomically
adb install-multi-package test.apk demo.apk
# Replace existing applicationreinstall an existing app, keeping its data
adb install -r test.apk
# Allow test packages
adb install -t test.apk
# Allow version code downgradedebuggable packages only
adb install -d test.apk
# Grant all runtime permissionsGrant all permissions listed in the app manifest
adb install -g test.apk
# Cause the app to be installed as an ephemeral install app
adb install --instant test.apk
# Use fast deploy
adb install --fastdeploy test.apk
# Always push APK to device and invoke Package Manager as separate steps
adb install --no-streaming test.apk
adb uninstall
# Remove this app package from the device
adb uninstall test.apk
# Keep the data and cache directories around after package removal
adb uninstall -k test.apk
adb shell pm list packages
# Prints all packages
adb shell pm list packages
# See their associated APK file
adb shell pm list packages -f
# All known packagesbut excluding APEXes (Android Pony EXpress)
adb shell pm list packages -a
# Only show APEX packages
adb shell pm list packages --apex-only
# Filter to only show disabled packages
adb shell pm list packages -d
# Filter to only show enabled packages
adb shell pm list packages -e
# Filter to only show system packages
adb shell pm list packages -s
# Filter to only show third party packages
adb shell pm list packages -3
# See the installer for the packages
adb shell pm list packages -i
# Ignored (used for compatibility with older releases)
adb shell pm list packages -l
# Also show the package UID
adb shell pm list packages -U
# Also include uninstalled packages
adb shell pm list packages -u
# Also show the version codea
db shell pm list packages --show-versioncode
# Filter to only show packages with the given UID
adb shell pm list packages --uid UID
# Only list packages belonging to the given user
adb shell pm list packages --user USER_ID
adb shell pm path
# Print the path to the .apk of the given installed package name
adb shell pm path com.android.chrome
adb shell pm clear
# Deletes all data associated with a package.
adb shell pm clear <PACKAGE>
adb shell pm clear com.techno.herder
# Notes: clearing app data, cache
File Manager
adb pull
# Copy files/dirs from device
# To copy a file or directory and its sub-directories from the Android device
adb pull /mnt/sdcard/Download/test.apk pc.apk
# Preserve file timestamp and mode.
adb pull -a /mnt/sdcard/Download/test.apk pc.apk
adb push
# Copy local files/directories to Android device
adb push pc.apk /mnt/sdcard/Download/test.apk
# Only push files that are newer on the host than the Android device
adb push --sync pc.apk /mnt/sdcard/Download/test.apk
adb common linux commands
# List Files and Directories
adb shell ls /system/bin
# All files including .hidden
adb shell ls -a
# Directory, not contentsa
db shell ls -d
# Recursively list in subdirs
adb shell ls -R /mnt/sdcard/Download
# change directory
adb shell cd /mnt/sdcard/Download
# rm is a command-line utility for removing files, directories and symbolic links
adb shell rm /mnt/sdcard/Download/test.apk
# Force: remove without confirmation, no error if it doesn't exist
adb shell rm -f /mnt/sdcard/Download/test.apk
# Interactive: prompt for confirmation
adb shell rm -i /mnt/sdcard/Download/test.apk
# Recursive: remove directory contents
adb shell rm -rR /mnt/sdcard/Download
# Verbose
adb shell rm -v /mnt/sdcard/Download/test.apk
# Make directories
mkdir [options] <directory name>
mkdir /sdcard/tmp
# Set permission mode
mkdir -m 777 /sdcard/tmp
# Create parent directories as needed
mkdir -p /sdcard/tmp/sub1/sub2
# The touch command is a standard command used in UNIX/Linux operating system which is used to create, change and modify timestamps of a file
adb shell touch /mnt/sdcard/Download/test.txt
# Printing the current working directory
adb shell pwd
# Copy files and directories
cp [options] <source> <dest>
# STEP 1.
adb shell
# STEP 2.
cp /sdcard/test.txt /sdcard/demo.txt
# Moves files or directories from one place to another
adb shell mv /mnt/sdcard/Download/test.txt /mnt/sdcard/DCIM/test.txt
# Force copy by deleting destination file
adb shell mv -f /mnt/sdcard/Download/test.txt /mnt/sdcard/DCIM/test.txt
# Interactive, prompt before overwriting existing DEST
adb shell mv -i /mnt/sdcard/Download/test.txt /mnt/sdcard/DCIM/test.txt
# No clobber (don't overwrite DEST)
adb shell mv -n /mnt/sdcard/Download/test.txt /mnt/sdcard/DCIM/test.txt
## Display networking information.
# Default is netstat -tuwx
adb shell netstat
# Routing table
adb shell netstat -r
# All sockets (not just connected)
adb shell netstat -a
# Listening server sockets
adb shell netstat -l
# TCP sockets
adb shell netstat -t
# UDP sockets
adb shell netstat -u
# Raw sockets
adb shell netstat -w
# Unix sockets
adb shell netstat -x
# Extended info
adb shell netstat -e
# Don't resolve names
adb shell netstat -n
# Wide display
adb shell netstat -w
# Show PID/program name of sockets
adb shell netstat -p
# ping (Packet Internet Groper) is a network administration utility used to testing, and diagnosing network connectivity issues
adb shell ping
# Notes: press Ctrl-C to stop ping
# Specifies the number of echo Request messages sent
adb shell ping -c 4
# Specifies the amount of time, in milliseconds, to wait for the echo Reply message that corresponds to a given echo Request message to be received
# The default time-out is 4000 (4 seconds)
adb shell ping -W 200 127.0.0.1
# Interval in seconds
# By default, interval is 1 second
adb shell ping -i 2 127.0.0.1
# Network configuration.
adb shell netcfg
# Notes: /system/bin/sh: netcfg: not found in Android M or higher.
# Display or configure network interface.
adb shell ifconfig
# Get wlan0 (Wi-Fi) IP address
adb shell ip addr show wlan0
# Route table
adb shell ip route
# ARP table
adb shell ip neighbour
Logcat
adb logcat
# Prints log data to the screen.
adb logcat [option] [filter-specs]
adb logcat
# Notes: press Ctrl-C to stop monitor
# Lowest priority, filter to only show Verbose level
adb logcat *:V
# Filter to only show Debug level
adb logcat *:D
# Filter to only show Info level
adb logcat *:I
# Filter to only show Warning level
adb logcat *:W
# Filter to only show Error level
adb logcat *:E
# Filter to only show Fatal level
adb logcat *:F
# Silent, highest priority, on which nothing is ever printed
adb logcat *:S
# Buffer
adb logcat -b <Buffer>
# View the buffer that contains radio/telephony related messages.
adb logcat -b radio
# View the buffer containing events-related messages.
adb logcat -b event
# Default
adb logcat -b main
# Clears the entire log and exits.
adb logcat -c
# Dumps the log to the screen and exits.
adb logcat -d
# Writes log message output to test.logs
adb logcat -f test.logs
# Prints the size of the specified log buffer and exits.
adb logcat -g
# Sets the maximum number of rotated logs to <count>.
adb logcat -n <count>
# Notes: The default value is 4. Requires the -r option.
# Rotates the log file every <kbytes> of output.
adb logcat -r <kbytes>
# Notes: The default value is 16. Requires the -f option.
# Sets the default filter spec to silent.
adb logcat -s
# Format
adb logcat -v <format>
# Display priority/tag and PID of the process issuing the message (default format).
adb logcat -v brief
# Display PID only.
adb logcat -v process
# Display the priority/tag only.
adb logcat -v tag
# Display the raw log message, with no other metadata fields.
adb logcat -v raw
# Display the date, invocation time, priority/tag, and PID of the process issuing the message.
adb logcat -v time
# Display the date, invocation time, priority, tag, and the PID and TID of the thread issuing the message.
adb logcat -v threadtime
# Display all metadata fields and separate messages with blank lines.
adb logcat -v long
adb shell dumpsys
# To dump all services
adb shell dumpsys
# Only list services, do not dump them
adb shell dumpsys -l
# Get Android device battery info
adb shell dumpsys battery
adb shell dumpstate
# Dump Android device state.
adb shell dumpstate
# Dumpstate not working with Android 10.
# Dump the Android device dumpstate, dumpsys and logcat outs.
adb bugreport
Screenshot
adb shell screencap
# The screencap command is a shell utility for taking a screenshot of a device display
adb shell screencap /mnt/sdcard/Download/test.png
# Notes: If FILENAME is not given, the results will be printed to stdout.
# To copy screenshot from Android Device.
adb pull /mnt/sdcard/Download/test.png test.png
adb shell screenrecord [4.4+]
# Android screenrecord v1.2. Records the device's display to a .mp4 file
adb shell screenrecord /mnt/sdcard/Download/test.mp4
# Recording continues until Ctrl-C is hit or the time limit is reached
# Set the video size, e.g. "1280x720". Default is the device's main display resolution (if supported), 1280x720 if not. For best results, use a size supported by the AVC encoder.
adb shell screenrecord --size 1280x720 /mnt/sdcard/Download/test.mp4
# Set the video bit rate, in bits per second. Value may be specified as bits or megabits, e.g. '4000000' is equivalent to '4M'. Default 20Mbps.
adb shell screenrecord --bit-rate 4000000 /mnt/sdcard/Download/test.mp4
# Rotates the output 90 degrees. This feature is experimental.
adb shell screenrecord --rotate /mnt/sdcard/Download/test.mp4
# Add additional information, such as a timestamp overlay, that is helpful in videos captured to illustrate bugs.
adb shell screenrecord --bugreport /mnt/sdcard/Download/test.mp4
# Set the maximum recording time, in seconds. Default / maximum is 180
adb shell screenrecord --time-limit=120 /mnt/sdcard/Download/test.mp4
# Display interesting information on stdout
adb shell screenrecord --verbose /mnt/sdcard/Download/test.mp4
# Audio is not recorded with the video file. Rotation of the screen during recording is not supported. If the screen does rotate during recording, some of the screen is cut off in the recording.
System
adb root
# Restart adbd with root permissions
adb root
# Restart adbd without root permissions
adb unroot
adb sideload
# Sideload the given full OTA package
adb sideload /mnt/sdcard/Download/ota.zip
# No Root Required
adb shell ps
# List processes. Which processes to show (selections may be comma separated lists)
adb shell ps
# All processes
adb shell ps -A
# Filter PIDs (--pid)
adb shell ps -p 1256
# Show threads
adb shell ps -t
adb shell top
# Show process activity in real timea
db shell top
# Cursor LEFT/RIGHT to change sort, UP/DOWN move list, space to force update, R to reverse sort, Q to exit
# Show threads
adb shell top -H
# Show FIELDS (def PID,USER,PR,NI,VIRT,RES,SHR,S,%CPU,%MEM,TIME+,CMDLINE)
adb shell top -o %CPU,%MEM,TIME+
# Maximum number of tasks to show
adb shell top -m 50
adb shell getprop
# Gets an Android system property, or lists them all
adb shell getprop
# Show property types instead of values
adb shell getprop -T
# Get SIM Operator
adb shell getprop gsm.sim.operator.alpha
# Get Device IEMI
adb shell getprop ro.ril.oem.imei
adb shell setprop
# Set property service
setprop <key> <value>
# STEP 1.
adb shell
# STEP 2.
setprop service.adb.tcp.port 5555
# See Also adb shell getprop
Content Provider
Content Providers expose Application A through the Content Resolver of a different application, Application B. This is done through:
prefix://authority/data_type/id
# Examples:
content://com.technoherder.userprovider/users
# More detailed example:
authority === com.technoherder.userprovider
data_type === description of the data returned by the provider
id === specific id for a record
content://com.elearnsecurity.userprovider/users/1
# CRUD == > Content Resolver Methods
# Create === insert
# Retrieve === query
# Update === update
# Delete === delete
The Android manifest file helps to declare the permissions that an app must have to access data from other apps. Always check the AndroidManifest.xml file to find any dangerous permissions or Content Providers marked for export. Here is an example:
<provider android:name="com.technoherder.pwdmanager.contentprovider.MyContentProvider" android:enabled="true" android:exported="true" android:authorities="com.technoherder.pwdmanager.contentprovider" />
<provider android:name="com.technoherder.safenote.contentprovider.notecontentprovider" android:enabled="true" android:exported="true" android:authorities="com.technoherder.safenote" />
Wow that was unusual. I just wrote an very long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say wonderful blog!
thank you