Learning objectives: learn the basic grammar of ADB
1.adb version
adb version is used to view the adb version
C:\Users\le>adb version Android Debug Bridge version 1.0.39 Version 0.0.1-4500957 Installed as C:\Users\le\Desktop\Maohuan\platform-tools-latest-windows\platform-tools\adb.exe``
2.adb devices
adb devices is used to view the code of the device to which adb is connected
C:\Users\le>adb devices List of devices attached emulator-5554 device
The simulator is used here, so the equipment code is emulator-5554. Normally, the unchanged equipment number is a string of unordered letters and numbers
3. Get mobile phone serial number
adb get-serialno
C:\Users\le>adb get-serialno emulator-5554
Get serial no provides a simple way to extract the device serial number in devices without writing some code to select the mobile phone serial number
4. Check the mobile device model
adb shell getprop ro.product.model
C:\Users\le>adb shell getprop ro.product.model LIO-AN00
The simulator used here will display the device model of LIO-AN00 simulator. If it is a mobile phone, the manufacturer's content should be displayed
5. Check the phone resolution
adb shell wm size
C:\Users\le>adb shell wm size Physical size: 1080x1920
Display phone resolution (simulator set to 1080x1920)
6. Get the mac address of the mobile phone
adb shell cat /sys/class/net/wlan0/address
C:\Users\le>adb shell cat /sys/class/net/wlan0/address /system/bin/sh: cat: /sys/class/net/wlan0/address: No such file or directory
The simulator does not have a corresponding address file cat address, so No such file or directory is displayed.
If it is a real phone, it should be a string of hexadecimal addresses separated by ':'
PS: cat command is very useful when viewing some file information
7. View logs
adb shell logcat
C:\Users\le>adb shell logcat >log.txt
The output speed of adb shell logcat is too fast and too much. It is usually written in this way to record the log, and the log will be written to the txt file.
Or write it directly as adb shell logcat |grep 'XXXX' to search for some keywords from the log
8. View battery information
adb shell dumpsys battery
C:\Users\le\Desktop>adb shell dumpsys battery Current Battery Service state: AC powered: true USB powered: false Wireless powered: false Max charging current: 0 Max charging voltage: 0 Charge counter: 0 status: 1 health: 1 present: true level: 100 scale: 100 voltage: 3905 temperature: 299 technology: Unknown
It will output some system information about battery, such as charging state, battery state, etc
9. View process
adb shell ps
C:\Users\le\Desktop>adb shell ps USER PID PPID VSIZE RSS WCHAN PC NAME root 1 0 7172 1780 0 c7fffc10 S /init root 2 0 0 0 0 00000000 S kthreadd root 3 2 0 0 0 00000000 S ksoftirqd/0 root 4 2 0 0 0 00000000 S kworker/0:0 root 5 2 0 0 0 00000000 S kworker/0:0H root 7 2 0 0 0 00000000 S rcu_sched root 8 2 0 0 0 00000000 S rcu_bh root 9 2 0 0 0 00000000 S migration/0 root 10 2 0 0 0 00000000 S migration/1 root 11 2 0 0 0 00000000 S ksoftirqd/1 root 13 2 0 0 0 00000000 S kworker/1:0H root 14 2 0 0 0 00000000 S khelper ...
ps is used to view the system process. It is generally used to search the process PID, PPID and NAME, and then extract them
10. Check CPU usage
adb shell top
C:\Users\le\Desktop>adb shell top [?25l[0m[H[J[s[999C[999B[6n[uTasks: 108 total, 1 running, 105 sleeping, 0 stopped, 1 zombie Mem: 3564392k total, 1894312k used, 1670080k free, 3960k buffers Swap: 0k total, 0k used, 0k free, 189976k cached 200%cpu 32%user 0%nice 16%sys 152%idle 0%iow 0%irq 0%sirq 0%host [7m PID USER PR NI VIRT RES SHR S[%CPU] %MEM TIME+ ARGS [0m 2055 u0_a34 10 -10 2.7G 1.3G 69M S 44.0 38.5 32:52.34 com.bilibili.fatego 1075 root -2 -8 48M 2.2M 1.0M S 8.0 0.0 1:46.49 surfaceflinger 4258 root 20 0 6.0M 2.8M 2.4M R 4.0 0.0 0:00.00 top 3814 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [kworker/1:0] 3533 u0_a7 20 0 1.0G 48M 32M S 0.0 1.3 0:00.03 com.android.mtp 3514 u0_a9 20 0 1.0G 46M 30M S 0.0 1.3 0:00.02 com.android.external 3497 u0_a6 20 0 1.0G 46M 30M S 0.0 1.3 0:00.05 com.android.document 3481 u0_a5 20 0 1.0G 45M 29M S 0.0 1.2 0:00.09 com.android.defconta 3249 root 20 0 0 0 0 S 0.0 0.0 0:00.02 [kworker/u4:0] 2839 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [kworker/1:2]
Check the process that is occupying the CPU. You can open a process, and then find out how much the process occupies, and the process name of the process
11. Install mobile phone APK
adb install [APK path]
C:\Users\le\Desktop>adb install C:\Users\le\Desktop\XXXX\XXXXX\XXXX.APK
At present, there is no one on hand that can install apk file. The path can be directly dragged to the cmd window
Multiple device installation apk
adb -s [device number] install [path to APK file]
C:\Users\le\Desktop>adb -s emulator-5554 isntall C:\Users\le\Desktop\XXXX\XXXXX\XXXX.APK
The device number (emulator-5554) can be obtained through adb devices and ADB get serialno
If apk already exists, you need to overwrite the installation
adb install -r C:\Users\le\Desktop\XXXX\XXXXX\XXXX.APK
12. Uninstall APK
adb uninstall file path
Note: I don't know how to get the file path. Generally speaking, it is easier to find APK by using the package name. Generally, it can be found quickly by using the third-party package
adb uninstall package name
C:\Users\le\Desktop>adb uninstall com.qihoo.browser Success
Delete com qihoo. The APK represented by the browser package name is 360 browser
Uninstall but retain data
adb uninstall -k package name
13. View all package names installed on the mobile phone
adb shell pm list packages
Find, delete and finish at one go are heroes in adb
C:\Users\le\Desktop>adb shell pm list packages package:com.android.cts.priv.ctsshim package:com.android.providers.telephony package:com.android.providers.calendar package:com.android.providers.media package:com.android.documentsui package:com.android.externalstorage package:com.android.htmlviewer package:com.android.mms.service package:com.android.providers.downloads package:com.android.browser package:com.android.inputmethod.pinyin package:com.android.defcontainer package:com.android.providers.downloads.ui package:com.android.pacprocessor package:com.android.certinstaller package:com.android.carrierconfig package:android package:com.android.contacts package:com.android.mtp package:com.android.launcher3 package:com.android.statementservice package:com.android.providers.settings package:com.android.sharedstoragebackup package:com.android.printspooler package:com.android.webview package:com.bilibili.fatego package:android.ext.shared package:com.android.server.telecom package:com.android.keychain package:com.android.gallery3d package:com.android.flysilkworm package:android.ext.services package:com.android.packageinstaller package:com.android.basicsmsreceiver package:com.android.proxyhandler package:com.cyanogenmod.filemanager package:com.android.managedprovisioning package:com.android.googleinstaller package:com.android.storagemanager package:com.android.bookmarkprovider package:com.android.settings package:com.android.cts.ctsshim package:com.android.vpndialogs package:com.android.phone package:com.android.shell package:com.android.wallpaperbackup package:com.android.providers.blockednumber package:com.android.providers.userdictionary package:com.android.location.fused package:com.android.systemui package:com.android.providers.contacts package:tv.danmaku.bili package:com.android.captiveportallogin package:com.android.coreservice
Constraint lookup direction
Find third party package name
adb shell pm list packages -3
C:\Users\le\Desktop>adb shell pm list packages -3 package:com.bilibili.fatego package:tv.danmaku.bili
Find system package name
C:\Users\le\Desktop>adb shell pm list packages -s package:com.android.cts.priv.ctsshim package:com.android.providers.telephony package:com.android.providers.calendar package:com.android.providers.media package:com.android.documentsui package:com.android.externalstorage package:com.android.htmlviewer package:com.android.mms.service package:com.android.providers.downloads package:com.android.browser package:com.android.inputmethod.pinyin package:com.android.defcontainer package:com.android.providers.downloads.ui package:com.android.pacprocessor package:com.android.certinstaller package:com.android.carrierconfig package:android package:com.android.contacts package:com.android.mtp package:com.android.launcher3 package:com.android.statementservice package:com.android.providers.settings package:com.android.sharedstoragebackup package:com.android.printspooler package:com.android.webview package:android.ext.shared package:com.android.server.telecom package:com.android.keychain package:com.android.gallery3d package:com.android.flysilkworm package:android.ext.services package:com.android.packageinstaller package:com.android.basicsmsreceiver package:com.android.proxyhandler package:com.cyanogenmod.filemanager package:com.android.managedprovisioning package:com.android.googleinstaller package:com.android.storagemanager package:com.android.bookmarkprovider package:com.android.settings package:com.android.cts.ctsshim package:com.android.vpndialogs package:com.android.phone package:com.android.shell package:com.android.wallpaperbackup package:com.android.providers.blockednumber package:com.android.providers.userdictionary package:com.android.location.fused package:com.android.systemui package:com.android.providers.contacts package:com.android.captiveportallogin package:com.android.coreservice
reference material: https://blog.csdn.net/weixin_41635750/article/details/108297319?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164156636516780271529033%2522%252C%2522scm%2522%253A%252220140713.130102334 …%2522%257D&request_ id=164156636516780271529033&biz_ id=0&utm_ medium=distribute. pc_ search_ result. none-task-blog-2alltop_ positive~default-1-108297319. first_ rank_ v2_ pc_ rank_ v29&utm_ term=adb%E5%91%BD%E4%BB%A4&spm=1018.2226.3001.4187