SoFunction
Updated on 2025-04-09

The finale of ADB command usage in Android

Preface

When it comes to ADB, you should be familiar with it, that is, Android Debug Bridge, and as Android developer, we are proficient in using ADB commands will greatly improve our development efficiency.

View version

I won’t say much about the installation of ADB here. Entering the following command will prove that your environment is OK. Otherwise, search online and solve it.

$ adb version

Android Debug Bridge version 1.0.36
Revision 8f855a3d9b35-android

There are many ADB commands. Today I will summarize some of the ADB commands I often use in development.

ADB Commands

1. Check the top layer to form the activity name:

adb shell dumpsys activity | findstr "mFocusedActivity" 
or adb shell dumpsys window w | findstr \/ | findstr name=

2. Check the activity's task stack:

 adb shell dumpsys activity activities

3. Display all activities information, including task stack, etc.:

adb shell dumpsys activity

4. Check the Android application package name package and entry activity name:

aapt dump badging E:\apk\

5. Display accounts information:

adb shell dumpsys account

5. Display CPU information:

adb shell dumpsys cpuinfo

View CPU usage information

adb shell top -n 1 -d 0.5 | findstr proc_ id

6. Show the keyboard, window and their relationship

 adb shell dumpsys window

When we need to know the resolution of the device

 adb shell dumpsys window displays

View all levels of information drawn by UI

adb shell dumpsys SurfaceFlinger

7. Display wifi information

adb shell dumpsys wifi

8. Power information and CPU usage time

 adb shell dumpsys batteryinfo $package_name

9. Obtain installation package information

adb shell dumpsys package packagename

10. Number of starts and time of each application

adb shell dumpsys usagestats

11. Display information related to the status bar

adb shell dumpsys statusbar

12. Memory information (meminfo package_name or pid Use the program's package name or process id to display memory information)

 adb shell dumpsys meminfo

Get information about the memory used by the process    adb shell dumpsys meminfo

13. Disk-related information

adb shell dumpsys diskstats

14. Battery-related information

adb shell dumpsys battery

15. Display Alarm information

adb shell dumpsys alarm

Statistics of system power consumption

adb shell dumpsys batterystats

Set the priority of threads

adb shell dumpsys activity|grep oom_adj 

16. Force close an application;

 adb shell am force-stop <PACKAGE>

17. Check memory information

adb shell cat proc/meminfo

Specify process memory address mapping

adb shell cat proc/pid/maps

Specify process memory usage information

adb shell cat proc/pid/smaps

VSS. RSS. PSS. USS Information

adb shell procrank

Specify process VSS. RSS. PSS. USS details

adb shell procmem pid

18. View input devices

 adb shell getevent -p

19. Obtain input information for specific devices

adb shell getevent /dev/input/event0

20. Click

 adb shell input tap x y

21. Send button

adb shell input keyevent 82(keycode)

22. Enter text

adb shell input text XXXX

23. Check the process containing mobileqq in the registration

 adb shell ps | findstr mobileqq

24. Remote process ID

adb jdwp

25. Obtain the serial number

adb get-serialno

26. Restart to bootloader, that is, flash mode

adb reboot bootloader

27. Restart to recovery, that is, recovery mode

adb reboot recovery

28. Obtain the machine MAC address:

 adb shell cat /sys/class/net/wlan0/address

29. Obtain the CPU serial number

adb shell cat /proc/cpuinfo

30. Overwrite the installation (retain data and cache files, reinstall apk)

adb install -r <apkfile>

31. Install apk to SD card

 adb install -s <apkfile>

32. Uninstall the app but retain data and cache files

adb uninstall -k <package>

33. Check the CPU and memory usage of the device

 adb shell top

34. Check the apps that occupy the top 6 memory

adb shell top -m 6

35. Refresh the memory information once and then return

adb shell top -n 1

36. Query the memory usage of each process

adb shell procrank

37. Check the specified process status

adb shell ps -x [PID] 

38. Check backend services information

 adb shell service list 

39. Check the current memory usage (this method can only obtain the approximate usage of the entire system memory)
If you want to view memory usage of all processes

 adb shell procrank

40. Check the IO memory partition

adb shell cat /proc/iomem

41. Check the wifi password

adb shell cat /data/misc/wifi/*.conf

42. Clear the log cache

 adb logcat -c

43. Check device information

adb shell cat /system/

44. Run the monkey

adb shell monkey -v -p  500

45. List the package names of all apps installed on the target device

adb shell pm list packages

46. ​​Screenshot command:

adb shell screencap -p /sdcard/

adb pull /sdcard/

adb shell rm /sdcard/

Record the mobile phone screen, the video format is mp4, and it is stored in the mobile phone SD card. The default recording time is 180s:

 adb shell screenrecord

The video recording time is limited to 10s. If not, the default is 180s:

adb shell screenrecord --time-limit 10 /sdcard/demo.mp4

Specify the video resolution size:

adb shell screenrecord --size 1280*720 /sdcard/demo.mp4

Specify the bit rate of the video:

 adb shell screenrecord --bit-rate 6000000 /sdcard/demo.mp4

Display log on the command line:

adb shell screenrecord --time-limit 10 --verbose /sdcard/demo.mp4

47. Set and obtain attribute information

adb shell getprop [key]

adb shell setprop [key] [value]

Listen to changes in system properties. If the system properties change during the period, display the changed value.

adb shell watchprops

48. adb logcat Each log message has a tag and priority associated with it.

(1) The tag is a short string that identifies the source of the original message (for example, "View" comes from the display system). The priority is the following characters, in the order from low to high:

V — Details (Lower Priority)
D — Debugging
I — Information
W — Warning
E — Error
F — Critical Error
S — Undocumented (highest priority, nothing will be recorded)

(2) View filter log

 adb logcat ActivityManager:I *:S

*:S is used to set the log priority of all tags to S, which ensures that the output complies with the specified filter settings.
In this way, the filter becomes a "whitelist" of log output

Show all logs with priority greater than or equal to "warning"

adb logcat *:W

(3) Log messages have many metadata fields in addition to marking and priority. These fields can control the output results by modifying the output format. The -v option plus the content listed below can control the output fields:

brief — Display priority/tag and original process PID (default format)
process — only display process PID
tag — Show priority/tag only
thread — Show only processes: threads and priority/tags
raw — displays the original log information without any other metadata fields
time — display date, call time, priority/tag, PID
long —Show all metadata fields and separate message content with blank lines

Use thread output format

adb logcat -v thread

(4) The Android log system maintains multiple circular buffers for log messages, and not all messages are sent to the default buffer. To view these additional buffers, you can use the -b option. The following are the buffers that can be specified:

radio — view buffer messages contained in wireless/phone related
events — view events related messages
main — View the main buffer (default buffer)

View radio buffer

adb logcat -b radio

48. Print the application log

adb logcat -b main -v time>

49. Printing RF-related logs, SIM STK will also be included, modem-related ATcommand, etc., of course, it is far from QXDM.

adb logcat -b radio -v time> 

50. Print the log of system events, such as touch screen events

adb logcat -b events -v time

51. tcpdump is very useful. You can use this to capture it for TCP/IP protocol related to it.

adb shell tcpdump -s 10000 -w /sdcard/

52. Status information, including dmesg, dumpstate and dumpsys

adb bugreport>

53. The kernel log is related to kernel, such as driver problems (camera, Bluetooth, USB, startup, etc.)

adb shell dmesg > ldmesg_kernel.log

54. dumpstate is the system status information, which is relatively complete, including the current memory information of the mobile phone, CPU information, logcat cache, kernel cache, etc.

adb shell dumpstate

55. All the content about the system service is in this

adb shell dumpsys

56. Display memory information

adb shell dumpsys meminfo system

Summarize

The above is the entire content of this article. I hope that the content of this article has a certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.