Introduction
ADB is a command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device. It is a client-server program that includes three components:
- A client, which sends commands. The client runs on your development machine.
- A daemon (adbd), which runs commands on a device. The daemon runs as a background process on each device.
- A server, which manages communication between the client and the daemon. The server runs as a background process on your development machine.
Useful Command List
Managing Device
- List devices/emulators are attached
adb devices
adb devices -l - Reboot your device
adb reboot - In case of multiple device connected to the development machine, use below command. adb devices command shows the id of connected devices.
adb -s (redirect command to specific device) <id>
adb –d (directs command to only attached USB device) <id>
adb –e (directs command to only attached emulator) <id> - Wait for the device until it is connected back to development PC
adb wait-for-device - Connect to the device by its IP address.
adb connect device_ip_address - Start the bootloader
adb reboot-bootloader
Basic Commands
- Restarts adbd with root permissions
adb root - Manage ADB server
adb start-server
adb kill-server - Manage terminal on the device
adb shell (starts the backround terminal)
exit (exits the background terminal) - List all the commands
adb help
Device Security
- DM-verity is a security measure to check the integrity of your device. The disable-verity command will disable dm-verity protection which lives in the kernel. Disabling dm-verity will retain kernel modifications by bypassing this protection. So if a rooting software compromises the system before the kernel comes up, it will retain those modifications. The enable-verity will enable the protection if it is disabled in a user debug build.
adb disable-verity // Disable Verity
adb enable-verity // Enable Verity
Manage Package
- Install a apk
adb shell install (install app)
adb shell install (install app from phone path) - Uninstall an application
adb uninstall com.myapp.packagename
Example
adb install -d -g -r -t MediaPlayer.apk
Above command will install the application in test mode and grant all the permisison.
-g = Grant all permission
-d = Debug
-t = Test mode
File Operations
- Send a file to the device:
adb push /home/myhome/image.png /sdcard/Download/
adb push –sync Clips/ /sdcard/
First command will copy ‘image.png’ from the development machine to ‘Download’ folder on the device - Retrieve a file from the device
adb pull /sdcard/Download/pic.jpg /home/myhome/Desktop/
This command will copy ‘pic.jpg’ from the device to ‘Desktop’ folder on the development machine.
Phone Info
- Show device state
adb get-statе (print device state) - Get the device serial number
adb get-serialno - Get the device IMEI
adb shell dumpsys iphonesybinfo - List TCP connectivity
adb shell netstat - Show battery status
adb shell dumpsys battery - List phone features
adb shell pm list features - List all services
adb shell service list - Show activity info
adb shell dumpsys activity - Print process status
adb shell ps - Displays the current screen resolution
adb shell wm size - Retrieve just a single property
adb shell getprop ro.build.version.sdk
Above command retrieve Android api level the devices has.
Permissions
- Grant a permission
adb shell pm grant your.app.package android.permission.INTERNET - Revoke a permission
adb shell pm revoke your.app.package android.permission.INTERNET - List permission groups definitions
adb shell permissions groups - List permissions details
adb shell list permissions -g -r - Reset permission
adb shell pm reset-permissions -p your.app.package
Package Info
- List package names along with path to apk
adb shell list packages -r - List third party package names
adb shell list packages -3 - List only system packages
adb shell list packages -s - List info on one package
adb shell dump <package name> - List all the installed packages in the device
adb shell pm list packages
Configure Device
- Change the battery status
adb shell dumpsys battery set level
adb shell dumpsys battery reset
adb shell dumpsys battery set usb - Sets the resolution to W(width) x H(height)
adb shell wm size WxH - Get the list of available properties
adb shell getprop - Disable SELinux policy
adb shell setenforce 0 - Change screen density
adb shell wm density 100
Logging
- Collect log from the device
adb logcat - Clear the current logs on the device.
adb logcat -c - Save the logcat output to a file on the development machine
adb logcat -d > [path_to_file] - Will dump the whole device information like dumpstate, dumpsys and logcat output.
adb bugreport > [path_to_file] - Set log buffer size
adb logcat -G 128M
In the above command log buffer size is set to 128 mega bytes - Filter logs based on log type
- adb logcat *:<Log Type>
Supported log types are- V: Verbose (lowest priority)
- D: Debug
- I: Info
- W: Warning
- E: Error
- F: Fatal
- S: Silent (highest priority, on which nothing is ever printed)
The following filter expression displays all log messages with priority level “warning” and higher, on all tags:
adb logcat *:W
Process Details
- Get the name of current activity
adb shell dumpsys window windows | grep -E ‘mCurrentFocus|mFocusedApp’ - Stop an Application
adb shell am force-stop com.my.app.id - List all running processes on the device and their process ids
adb shell ps - Kill the Process
adb shell kill - Kill all processes associated with (the app’s package name).
adb shell am kill [options]
Emulate device
- Set specific screen resolution/density
adb shell wm size 2048×1536
adb shell wm density 288 - Reset resolution and/or density to default
adb shell wm size reset
adb shell wm density reset
Screen capture
- Take screenshoot
adb shell screencap -p /sdcard/screenshot.png - Record screen
adb shell screenrecord /sdcard/Login.mp4