0% found this document useful (0 votes)
63 views60 pages

ADB Usage Complete

Uploaded by

Thuấn Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views60 pages

ADB Usage Complete

Uploaded by

Thuấn Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Learn Git and GitHub without any code!


Using the Hello World guide, you'll start a branch, write comments, and open a pull
request.

Read the guide

doanpt / awesome-adb
forked from lixiaogang03/awesome-adb

ADB Usage Complete / ADB ⽤法⼤全


mazhuang.org/awesome-adb/

MIT License

0 stars 1.7k forks

Star Watch

Code Pull requests Actions Projects Wiki Security Insights Settings

master

This branch is even with lixiaogang03:master.

Pull request Compare

andforce and mzlogin … on Aug 19, 2019

View code

README.md

Awesome Adb
https://github.com/doanpt/awesome-adb 1/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

ADB, or Android Debug Bridge , is an irreplaceable powerful tool for Android


developers/testers, and a good toy for Android device players.

Continuously updated, feel free to mention PR and Issue supplementary correction, you can
find useful this GitHub repository Star Collection spare.

Note: The support of some commands may be related to the Android system version and
the implementation of custom ROM.

Other languages: English

Table of Contents
Basic usage
Command syntax
Specify the target device for the command
turn stop
View adb version
Run adbd with root privileges
Specify the network port of the adb server
Device connection management
Query connected devices/emulators
USB connection
Wireless connection (requires USB cable)
Wireless connection (no need to use USB cable)
Application management
View application list
All apps
system applications
third-party usage
Applications whose package name contains a certain string
Install APK
Uninstall app
Clear app data and cache
View foreground activity
View running services
View application details
View application installation path
Interact with the application
Start the application / call up Activity
https://github.com/doanpt/awesome-adb 2/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Transfer Service
Stop Service
Send broadcast
Force application to stop
Tighten memory
File management
Copy the files in the device to the computer
Copy files from computer to device
Analog button/input
Power button
menu
HOME key
return key
volume control
Media control
Turn on/off the screen
Slide to unlock
Input text
View log
Android log
Filter logs by level
Filter logs by tag and level
Log format
Clear log
Kernel log
View device information
model
Battery condition
Screen Resolution
Screen density
Display parameters
android_id
IMEI
Android system version
IP address
Mac address
CPU information
Memory information
https://github.com/doanpt/awesome-adb 3/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

More hardware and system attributes


Modify settings
Resolution
Screen density
Display area
Turn off USB debugging mode
Allow/disable access to non-SDK API
Display and hide the status bar and navigation bar
Utility function
Screenshots
Record screen
Remount the system partition as writable
View connected WiFi password
Set the system date and time
restart cellphone
Check if the device is rooted
Use Monkey for stress testing
Turn on/off WiFi
Relevant commands for flashing
Restart to Recovery mode
Restart from Recovery to Android
Restart to Fastboot mode
Update the system via sideload
Security related commands
Enable/disable SELinux
Enable/disable dm_verity
More adb shell commands
View process
View real-time resource usage
View process UID
other
common problem
Failed to start adb server
com.android.ddmlib.AdbCommandRejectedException
Unofficial implementation of adb
Related commands
Thanks
Reference link

https://github.com/doanpt/awesome-adb 4/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Basic usage

Command syntax
The basic syntax of the adb command is as follows:

adb [-d | -e | -s < serialNumber > ] < command >

If only one device / emulator connection can be omitted [-d|-e|-s <serialNumber>] in


this portion, directly adb <command> .

Specify the target device for the command


If there are multiple devices/emulators connected, you need to specify the target device for
the command.

parameter meaning

Specify the only Android device currently connected via USB as


-d
the command target

-e Specify the only simulator currently running as the command target

-s Specify the device/emulator with the corresponding serialNumber


<serialNumber> as the command target

In the case where a plurality of device / emulator, is more commonly used -s


<serialNumber> parameters, serialNumber can adb devices get command. Such as:

$ adb devices

List of devices attached


cf264b8f device
emulator-5554 device
10.129.164.6:5555 device

In the output cf264b8f , emulator-5554 and 10.129.164.6:5555 that is serialNumber.

For example, at this time you want to specify cf264b8f the device to run adb command to
get the screen resolution:

adb -s cf264b8f shell wm size

https://github.com/doanpt/awesome-adb 5/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Another example would like to 10.129.164.6:5555 mount the device to the application (
this form of serialNumber format <IP>:<Port> , typically a wireless device or the like
connected to third Genymotion Android emulator ):

adb -s 10.129.164.6:5555 install test.apk

In the case of multiple devices/simulators, these parameters are used to specify the
target device for the command. The following is a simplified description and will not
be repeated.

turn stop
Start the adb server command:

adb start-server

(Generally, there is no need to manually execute this command. If you find that the adb
server is not started when running the adb command, it will be automatically activated.)

Stop the adb server command:

adb kill-server

View adb version


command:

adb version

Sample output:

Android Debug Bridge version 1.0.36


Revision 8f855a3d9b35-android

Run adbd with root privileges


The operating principle of adb is that the adb server on the PC side establishes a
connection with the daemon process adbd on the mobile phone side, and then the adb
client on the PC side forwards the command through the adb server, and adbd parses and
runs after receiving the command.

https://github.com/doanpt/awesome-adb 6/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

So if adbd ordinary permission to perform, some need root privileges to execute the
command can not be directly adb xxx executed. Then you can adb shell then
su commands have been executed, but also allows adbd executed with root privileges, this
will be able to execute arbitrary commands a higher authority.

command:

adb root

Normal output:

restarting adbd as root

Now run adb shell , take a look at the command line prompt is not into # it?

After some phone can not root through adb root let adbd executed with root privileges,
such as some models of Samsung, will command prompt adbd cannot run as root in
production builds , then you can install adbd Insecure, then adb root try.

Accordingly, if you want to restore adbd non-root privileges, you can use the adb
unroot command.

Specify the network port of the adb server


command:

adb -P < port > start-server

The default port is 5037.

Device connection management

Query connected devices/emulators


command:

adb devices

Sample output:

List of devices attached


cf264b8f device

https://github.com/doanpt/awesome-adb 7/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

emulator-5554 device
10.129.164.6:5555 device

The output format is [serialNumber] [state] serialNumber, which is what we often call
SN, and the state is as follows:

offline —— Indicates that the device is not successfully connected or has no


response.

device —— The device is connected. Note that this state does not indicate that the
Android system has been fully started and operable. The device instance can be
connected to adb during the device startup process, but the system will be in an
operable state after startup.

no device —— No device/emulator connection.

The output shows a three devices currently connected / simulator cf264b8f , emulator-
5554 and 10.129.164.6:5555 respectively their SN. From emulator-5554 this it can be
seen that the name is an Android emulator, and 10.129.164.6:5555 this form of <IP>:
<Port> the device or the like is generally serialNumber Genymotion wirelessly connected to
third Android emulator.

Common abnormal output:

1. No device/emulator is successfully connected.

List of devices attached

2. The device/emulator is not connected to adb or not responding.

List of devices attached


cf264b8f offline

USB connection
To use adb normally through USB connection, you need to ensure several points:

1. The hardware status is normal.

Including the Android device is in a normal boot state, the USB cable and various
interfaces are intact.

2. Developer options and USB debugging mode for Android devices are turned on.

You can go to "Settings"-"Developer Options"-"Android Debugging" to view.

https://github.com/doanpt/awesome-adb 8/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

If you can't find the developer option in the settings, you need to use an easter egg to
show it: click the "version number" 7 times in "Settings"-"About Phone".

3. The device drive status is normal.

It seems that you don’t need to worry about this under Linux and Mac OS X. Under
Windows, you may encounter a situation where you need to install a driver. To confirm
this, you can right-click "Computer"-"Properties" and go to the "Device Manager" to
view related devices Whether there is a yellow exclamation mark or question mark, if
not, it means the drive status is good. Otherwise, you can download a mobile assistant
program to install the driver first.

4. Confirm the status after connecting the computer and the device via the USB cable.

adb devices

If you can see

xxxxxx device

The connection is successful.

Wireless connection (requires USB cable)


In addition to connecting the device and the computer via USB to use adb, you can also use
a wireless connection-although there are steps to use USB during the connection process,
your device can get rid of the limitation of the USB cable within a certain range after the
connection is successful. !

Steps:

1. Connect the Android device and the computer to run adb to the same local area
network, for example to the same WiFi.

2. Connect the device to the computer via a USB cable.

Make sure the connection is successful (can be run adb devices to see if the device is
listed).

3. Let the device monitor TCP/IP connections on port 5555:

adb tcpip 5555

4. Disconnect the USB connection.

https://github.com/doanpt/awesome-adb 9/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

5. Find the IP address of the device.

Generally "Settings" in - "About phone" - "state information" - "IP address" found below
where you can use to view the device information - IP address of a way to see inside
with adb command.

6. Connect the device by IP address.

adb connect < device-ip-address >

Here <device-ip-address> is the IP address of the device found in the previous step.

7. Confirm the connection status.

adb devices

If you can see

< device-ip-address > :5555 device

The connection is successful.

If you can not connect, verify that Android devices and computers are connected to the
same WiFi, then execute again adb connect <device-ip-address> that step;

If that does not work, by adb kill-server then all over again to try to restart the adb.

Disconnect wireless connection

command:

adb disconnect < device-ip-address >

Wireless connection (no need to use USB cable)


Note: Root permissions are required.

The previous section "Wireless connection (requires USB cable)" is the method introduced
in the official document, which requires the help of a USB data cable to achieve wireless
connection.

Since we want to achieve wireless connection, can all steps be wireless? The answer is
yes.

1. Install a terminal emulator on the Android device.


https://github.com/doanpt/awesome-adb 10/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Devices that have already been installed can skip this step. The download address of
the terminal emulator I use is: Terminal Emulator for Android Downloads

2. Connect the Android device and the computer to run adb to the same local area
network, for example to the same WiFi.

3. Open the terminal emulator on the Android device and run the commands in sequence:

su
setprop service.adb.tcp.port 5555

4. Find the IP address of the Android device.

Generally "Settings" in - "About phone" - "state information" - "IP address" found below
where you can use to view the device information - IP address of a way to see inside
with adb command.

5. Connect the Android device via adb and IP address on the computer.

adb connect < device-ip-address >

Here <device-ip-address> is the IP address of the device found in the previous step.

If you can see connected to <device-ip-address>:5555 this output indicates a


successful connection.

Section Note 1:

Some devices, such as Xiaomi 5S + MIUI 8.0 + Android 6.0.1 MXB48T, may need to restart
the adbd service before step 5, and run on the device's terminal emulator:

restart adbd

If restart does not work, try the following command:

stop adbd
start adbd

Application management

View application list


The basic command format for viewing the application list is

https://github.com/doanpt/awesome-adb 11/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

adb shell pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [--user USER_ID]

That adb shell pm list packages can be added on the basis of a number of different
parameters to filter to view a list of supported filter parameters are as follows:

parameter Show list

no All apps

-f Display the apk file associated with the application

-d Only show disabled apps

-e Only show enabled apps

-s Only show system apps

-3 Only show third-party apps

-i Display the installer of the application

-u Contains uninstalled apps

<FILTER> Package name contains the <FILTER> string

All apps

command:

adb shell pm list packages

Sample output:

package:com.android.smoketest
package:com.example.android.livecubes
package:com.android.providers.telephony
package:com.google.android.googlequicksearchbox
package:com.android.providers.calendar
package:com.android.providers.media
package:com.android.protips
package:com.android.documentsui
package:com.android.gallery
package:com.android.externalstorage
...
// other packages here
...

https://github.com/doanpt/awesome-adb 12/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

system applications

command:

adb shell pm list packages -s

third-party usage

command:

adb shell pm list packages -3

Applications whose package name contains a certain string

For example, to view the package name that contains the string mazhuang application list,
the command:

adb shell pm list packages mazhuang

Of course, you can also use grep to filter:

adb shell pm list packages | grep mazhuang

Install APK
Command format:

adb install [-lrtsdg] < path_to_apk >

parameter:

adb install Some optional parameters can be followed to control the behavior of
installing APK. The available parameters and their meanings are as follows:

parameter meaning

-l Install the application to the protected directory /mnt/asec

-r Allow overwrite installation

AndroidManifest.xml allowed to install application specified in


-t
android:testOnly="true" the application

https://github.com/doanpt/awesome-adb 13/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

parameter meaning

-s Install the application to the sdcard

-d Allow downgrade to overwrite installation

-g Grant all runtime permissions

After running the command, if you see output similar to the following (the status is
Success ), the installation is successful:

[100%] /data/local/tmp/1.apk
pkg: /data/local/tmp/1.apk
Success

The above is the output of the current latest version v1.0.36 of adb, which will display the
progress percentage of the push apk file to the phone.

Using the old version of adb, the output is like this:

12040 KB/s (22205609 bytes in 1.801s)


pkg: /data/local/tmp/SogouInput_android_v8.3_sweb.apk
Success

And if the state is Failure said installation failure, such as:

[100%] /data/local/tmp/map-20160831.apk
pkg: /data/local/tmp/map-20160831.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]

Common installation failure output codes, meanings and possible solutions are as follows:

Output meaning

The application already


INSTALL_FAILED_ALREADY_EXISTS uninstalled but not unins
cleanly

INSTALL_FAILED_INVALID_APK Invalid APK file

INSTALL_FAILED_INVALID_URI Invalid APK file name

https://github.com/doanpt/awesome-adb 14/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Output meaning

INSTALL_FAILED_INSUFFICIENT_STORAGE not enough space

A program with the sam


INSTALL_FAILED_DUPLICATE_PACKAGE
already exists

The requested shared u


INSTALL_FAILED_NO_SHARED_USER
not exist

The application of the sa


name has been installed
but the data is not remov
INSTALL_FAILED_UPDATE_INCOMPATIBLE
uninstalling; or the applic
has been installed but th
signature is inconsistent

The requested shared u


INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
but the signature is inco

The installation package


INSTALL_FAILED_MISSING_SHARED_LIBRARY shared library that is not
on the device

Cannot be deleted when


INSTALL_FAILED_REPLACE_COULDNT_DELETE
replacing

dex optimization verifica


INSTALL_FAILED_DEXOPT
or insufficient space

The device system vers


INSTALL_FAILED_OLDER_SDK lower than the applicatio
requirements

A content provider with t


INSTALL_FAILED_CONFLICTING_PROVIDER name as the app already
the device

The device system vers


INSTALL_FAILED_NEWER_SDK higher than the applicati
requirements

It is a test-only applicatio
INSTALL_FAILED_TEST_ONLY did not specify the instal
t parameters

https://github.com/doanpt/awesome-adb 15/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Output meaning

Contains native code of


INSTALL_FAILED_CPU_ABI_INCOMPATIBLE incompatible device CPU
application binary interfa

The app uses a feature


INSTALL_FAILED_MISSING_FEATURE
available on the device

1. The sdcard access fa


2. The application signa
INSTALL_FAILED_CONTAINER_ERROR consistent with the ROM
signature and is regarde
built-in application.

1. It cannot be installed
specified location;
2. The application signa
INSTALL_FAILED_INVALID_INSTALL_LOCATION
consistent with the ROM
signature and is regarde
built-in application.

Installation location is no
INSTALL_FAILED_MEDIA_UNAVAILABLE
available

Verify installation packag


INSTALL_FAILED_VERIFICATION_TIMEOUT
timeout

Failed to verify installatio


INSTALL_FAILED_VERIFICATION_FAILURE
package

Inconsistent expectation
INSTALL_FAILED_PACKAGE_CHANGED
between application and

The application has bee


installed before, which is
INSTALL_FAILED_UID_CHANGED
inconsistent with the UID
assigned this time

https://github.com/doanpt/awesome-adb 16/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Output meaning

A higher version of the a


INSTALL_FAILED_VERSION_DOWNGRADE
already installed

The target SDK has bee


installed to support runti
permissions of the same
INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE
application, the version t
installed does not suppo
runtime permissions

Specified path is not a fi


INSTALL_PARSE_FAILED_NOT_APK
in .apk the end

Unresolved AndroidMan
INSTALL_PARSE_FAILED_BAD_MANIFEST
file

The parser encountered


INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION
exception

The installation package


INSTALL_PARSE_FAILED_NO_CERTIFICATES
signed

The app is installed and


INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES signature is inconsistent
APK file

Encountered when pars


INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING files
CertificateEncodingEx

No or invalid package na
INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME
the manifest file

Invalid shared user ID s


INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID
in the manifest file

A structural error was


INSTALL_PARSE_FAILED_MANIFEST_MALFORMED encountered while parsi
manifest file

Cannot find an operable


INSTALL_PARSE_FAILED_MANIFEST_EMPTY (instrumentation or appl
the manifest file

https://github.com/doanpt/awesome-adb 17/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Output meaning

Installation failed due to


INSTALL_FAILED_INTERNAL_ERROR
problems

Users are restricted from


INSTALL_FAILED_USER_RESTRICTED
installing apps

The application tries to d


INSTALL_FAILED_DUPLICATE_PERMISSION
existing permission nam

The application contains


code that is not supporte
INSTALL_FAILED_NO_MATCHING_ABIS
application binary interfa
device

App installation needs to


confirmed on the device
INSTALL_CANCELED_BY_USER
device is not operated o
canceled

The application is not co


INSTALL_FAILED_ACWF_INCOMPATIBLE
with the device

The APK file is a file com


INSTALL_FAILED_TEST_ONLY using Android Studio dir
RUN

does not contain AndroidManifest.xml Invalid APK file

is not a valid zip file Invalid APK file

The device is not conne


Offline
successfully

The device is not author


unauthorized
allow debugging

https://github.com/doanpt/awesome-adb 18/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Output meaning

No device successfully
error: device not found
connected

protocol failure Device disconnected

Installation to sdcard is n
Unknown option: -s
supported under Android

No space left on device not enough space

Permission denied ... sdcard ... sdcard is not available

signatures do not match the previously installed version; The app is already insta
ignoring! the signature is inconsis

Reference: PackageManager.java

adb install Introduction to internal principles

adb install It is actually done in three steps:

1. Push the apk file to /data/local/tmp.

2. Call pm install to install.

3. Delete the corresponding apk file under /data/local/tmp.

Therefore, when necessary, you can also follow this step to manually perform the
installation process step by step.

Uninstall app
command:

adb uninstall [-k] < packagename >

<packagename> Indicates the package name of the application. The -k parameter is


optional. It means that the application is uninstalled but the data and cache directory are
retained.

https://github.com/doanpt/awesome-adb 19/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Command example:

adb uninstall com.qihoo360.mobilesafe

Means to uninstall 360 Mobile Guard.

Clear app data and cache


command:

adb shell pm clear < packagename >

<packagename> Represents the application name package. The effect of this command is
equivalent to clicking "Clear Cache" and "Clear Data" on the application information
interface in the settings.

Command example:

adb shell pm clear com.qihoo360.mobilesafe

Indicates to clear the data and cache of 360 Mobile Guard.

View foreground activity


command:

adb shell dumpsys activity activities | grep mResumedActivity

Sample output:

mResumedActivity: ActivityRecord{8079d7e u0 com.cyanogenmod.trebuchet/com.andr

Which com.cyanogenmod.trebuchet/com.android.launcher3.Launcher it is currently in the


foreground Activity.

In the Windows command above may not be available, you can try adb shell dumpsys
activity activities | findstr mResumedActivity or adb shell "dumpsys activity
activities | grep mResumedActivity" .

View running services


command:
https://github.com/doanpt/awesome-adb 20/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

adb shell dumpsys activity services [ < packagename > ]

<packagename> Parameter is not necessary to specify <packagename> represents the view


associated with a package name of Services, does not specify the representation View all
Services.

<packagename> Do not have to give the complete package name, such as running adb
shell dumpsys activity services org.mazhuang , then the package name
org.mazhuang.demo1 , org.mazhuang.demo2 and org.mazhuang123 other related Services
will be listed.

View application details


command:

adb shell dumpsys package < packagename >

The output contains a lot of information, including Activity Resolver Table, Registered
ContentProviders, package name, userId, path to file resource code after installation,
version information, permission information and grant status, signature version information,
etc.

<packagename> Represents the application package name.

Sample output:

Activity Resolver Table:


Non-Data Actions:
android.intent.action.MAIN:
5b4cba8 org.mazhuang.guanggoo/.SplashActivity filter 5ec9dcc
Action: " android.intent.action.MAIN "
Category: " android.intent.category.LAUNCHER "
AutoVerify=false

Registered ContentProviders:
org.mazhuang.guanggoo/com.tencent.bugly.beta.utils.BuglyFileProvider:
Provider{7a3c394 org.mazhuang.guanggoo/com.tencent.bugly.beta.utils.BuglyF

ContentProvider Authorities:
[org.mazhuang.guanggoo.fileProvider]:
Provider{7a3c394 org.mazhuang.guanggoo/com.tencent.bugly.beta.utils.BuglyF
applicationInfo=ApplicationInfo{7754242 org.mazhuang.guanggoo}

Key Set Manager:


[org.mazhuang.guanggoo]
Signing KeySets: 501

https://github.com/doanpt/awesome-adb 21/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Packages:
Package [org.mazhuang.guanggoo] (c1d7f):
userId=10394
pkg=Package{55f714c org.mazhuang.guanggoo}
codePath=/data/app/org.mazhuang.guanggoo-2
resourcePath=/data/app/org.mazhuang.guanggoo-2
legacyNativeLibraryDir=/data/app/org.mazhuang.guanggoo-2/lib
primaryCpuAbi=null
secondaryCpuAbi=null
versionCode=74 minSdk=15 targetSdk=25
versionName=1.1.74
splits=[base]
apkSigningVersion=2
applicationInfo=ApplicationInfo{7754242 org.mazhuang.guanggoo}
flags=[ HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP]
privateFlags=[ RESIZEABLE_ACTIVITIES]
dataDir=/data/user/0/org.mazhuang.guanggoo
supportsScreens=[small, medium, large, xlarge, resizeable, anyDensity]
timeStamp=2017-10-22 23:50:53
firstInstallTime=2017-10-22 23:50:25
lastUpdateTime=2017-10-22 23:50:55
installerPackageName=com.miui.packageinstaller
signatures=PackageSignatures{af09595 [53c7caa2]}
installPermissionsFixed=true installStatus=1
pkgFlags=[ HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP]
requested permissions:
android.permission.READ_PHONE_STATE
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.READ_LOGS
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_EXTERNAL_STORAGE
install permissions:
android.permission.INTERNET: granted=true
android.permission.ACCESS_NETWORK_STATE: granted=true
android.permission.ACCESS_WIFI_STATE: granted=true
User 0: ceDataInode=1155675 installed=true hidden=false suspended=false st
gids=[3003]
runtime permissions:
android.permission.READ_EXTERNAL_STORAGE: granted=true
android.permission.READ_PHONE_STATE: granted=true
android.permission.WRITE_EXTERNAL_STORAGE: granted=true
User 999: ceDataInode=0 installed=false hidden=false suspended=false stopp
gids=[3003]
runtime permissions:

Dexopt state:
[org.mazhuang.guanggoo]
Instruction Set: arm64
path: /data/app/org.mazhuang.guanggoo-2/base.apk
status: /data/app/org.mazhuang.guanggoo-2/oat/arm64/base.odex [compilati
te]

https://github.com/doanpt/awesome-adb 22/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

View application installation path


command:

adb shell pm path <PACKAGE>

Output application installation path

Sample output:

adb shell pm path ecarx.weather

package:/data/app/ecarx.weather-1.apk

Interact with the application

Mainly the use of am <command> the command, commonly used <command> as follows:

command use

start [options] <INTENT> Start <INTENT> the specified Activity

startservice [options] <INTENT> Start <INTENT> the specified Service

broadcast [options] <INTENT> Send <INTENT> a designated broadcast

force-stop <packagename> Stop <packagename> related processes

<INTENT> The parameters are very flexible and correspond to the Intent in the code when
writing the Android program.

The options used to determine the intent object are as follows:

parameter meaning

-a
Specify action, such as android.intent.action.VIEW
<ACTION>

-c
Specify category, such as android.intent.category.APP_CONTACTS
<CATEGORY>

-n Specify the full component name, which is used to specify which


<COMPONENT> Activity to start, such as com.example.app/.ExampleActivity

https://github.com/doanpt/awesome-adb 23/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

<INTENT> It can also carry data, just like Bundle when writing code:

parameter meaning

--esn <EXTRA_KEY> null value (only key name)

--es <EXTRA_KEY>
`-e
<EXTRA_STRING_VALUE>`

--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> boolean value

--ei <EXTRA_KEY> <EXTRA_INT_VALUE> integer value

--el <EXTRA_KEY> <EXTRA_LONG_VALUE> long value

--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> float value

--eu <EXTRA_KEY> <EXTRA_URI_VALUE> URI

--ecn <EXTRA_KEY>
component name
<EXTRA_COMPONENT_NAME_VALUE>

--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,


integer array
<EXTRA_INT_VALUE...]

--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,


long array
<EXTRA_LONG_VALUE...]

Start the application / call up Activity


Specify Activity name to start

Command format:

adb shell am start [options] < INTENT >

E.g:

adb shell am start -n com.tencent.mm/.ui.LauncherUI

Indicates that the main interface of WeChat is activated.

adb shell am start -n org.mazhuang.boottimemeasure/.MainActivity --es " toast

https://github.com/doanpt/awesome-adb 24/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

He represents invoking org.mazhuang.boottimemeasure/.MainActivity and pass it the


string data key-value pairs toast - hello, world .

Start without specifying the Activity name (start the main Activity)

Command format:

adb shell monkey -p < packagename > -c android.intent.category.LAUNCHER 1

E.g:

adb shell monkey -p com.tencent.mm -c android.intent.category.LAUNCHER 1

Indicates that the main interface of WeChat is activated.

Transfer Service
Command format:

adb shell am startservice [options] < INTENT >

E.g:

adb shell am startservice -n com.tencent.mm/.plugin.accountsync.model.AccountA

Indicates that a certain service of WeChat is called up.

Another typical use case is if the virtual button should be displayed on the device but not
displayed, you can try this:

adb shell am startservice -n com.android.systemui/.SystemUIService

Stop Service
Command format:

adb shell am stopservice [options] < INTENT >

Send broadcast
Command format:

https://github.com/doanpt/awesome-adb 25/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

adb shell am broadcast [options] < INTENT >

It can be broadcast to all components or only to specified components.

For example, to broadcast to all components BOOT_COMPLETED :

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

As another example, only the


org.mazhuang.boottimemeasure/.BootCompletedReceiver broadcast BOOT_COMPLETED :

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n org.mazhuang

This type of usage is very practical when testing. For example, a broadcast scene is difficult
to create. You can consider sending broadcasts in this way.

It can send the pre-defined broadcast of the system and also send the self-defined
broadcast. The following is part of the system predefined broadcast and normal trigger
timing:

action Trigger timin

android.net.conn.CONNECTIVITY_CHANGE Network connection change

android.intent.action.SCREEN_ON The screen lights up

android.intent.action.SCREEN_OFF The screen goes off

Low battery, a low battery p


android.intent.action.BATTERY_LOW
pop up

android.intent.action.BATTERY_OKAY The battery is restored

android.intent.action.BOOT_COMPLETED The device is started

android.intent.action.DEVICE_STORAGE_LOW Storage space is too low

android.intent.action.DEVICE_STORAGE_OK Storage space recovery

android.intent.action.PACKAGE_ADDED New app installed

android.net.wifi.STATE_CHANGE The WiFi connection status

WiFi status becomes


android.net.wifi.WIFI_STATE_CHANGED
enabled/disabled/starting/di

https://github.com/doanpt/awesome-adb 26/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

action Trigger timin

android.intent.action.BATTERY_CHANGED Battery level has changed

android.intent.action.INPUT_METHOD_CHANGED System input method chang

android.intent.action.ACTION_POWER_CONNECTED External power connection

android.intent.action.ACTION_POWER_DISCONNECTED External power supply disco

android.intent.action.DREAMING_STARTED System starts to sleep

android.intent.action.DREAMING_STOPPED System stopped sleeping

android.intent.action.WALLPAPER_CHANGED Wallpaper changes

android.intent.action.HEADSET_PLUG Plug in headphones

android.intent.action.MEDIA_UNMOUNTED Unload external media

android.intent.action.MEDIA_MOUNTED Mount external media

android.os.action.POWER_SAVE_MODE_CHANGED Power saving mode is on

(The above broadcasts can all be triggered by adb)

Force application to stop


command:

adb shell am force-stop < packagename >

Command example:

adb shell am force-stop com.qihoo360.mobilesafe

Means to stop all the processes and services of 360 Security Guard.

Tighten memory
command:

adb shell am send-trim-memory < pid > < level >

https://github.com/doanpt/awesome-adb 27/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

pid: Process ID level: HIDDEN, RUNNING_MODERATE, BACKGROUND,


RUNNING_LOW, MODERATE, RUNNING_CRITICAL, COMPLETE

Command example:

adb shell am send-trim-memory 12345 RUNNING_LOW

Indicates that the memory tightening command of level=RUNNING_LOW is issued to the


process with pid=12345.

File management

Copy the files in the device to the computer


command:

adb pull < file path in device > [directory on computer]

Which 电脑上的⽬录 parameters can be omitted, copy the default to the current directory.
example:

adb pull /sdcard/sr.mp4 ~ /tmp/

* Tips: * file path on the device may need root privileges to access, if your equipment has
been root, you can use adb shell and su the command to obtain root privileges in adb
shell, the first cp /path/on/device /sdcard/filename copy files to sdcard, then adb pull
/sdcard/filename /path/on/pc .

Copy files from computer to device


command:

adb push < file path on computer > < directory in device >

example:

adb push ~ /sr.mp4 /sdcard/

https://github.com/doanpt/awesome-adb 28/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

* Tips: * file path common permissions on the device may not be directly written to, if your
device has root before, you can first adb push /path/on/pc /sdcard/filename , then adb
shell and su after obtaining root privileges in adb shell where cp /sdcard/filename
/path/on/device .

Analog button/input
In the adb shell inside there is a very useful command is called input , through which
you can do some interesting things.

input The complete help information of the command is as follows:

Usage: input [ < source > ] < command > [ < arg > ...]

The sources are:


mouse
keyboard
joystick
touchnavigation
touchpad
trackball
stylus
dpad
gesture
touchscreen
gamepad

The commands and default sources are:


text < string > (Default: touchscreen)
keyevent [--longpress] < key code number or name > ... (Default: keyboar
tap < x > < y > (Default: touchscreen)
swipe < x 1> < y 1> < x 2> < y 2> [duration(ms)] (Default: touchscree
press (Default: trackball)
roll < dx > < dy > (Default: trackball)

For example, use adb shell input keyevent <keycode> the command, different keycode
can perform different functions, a complete list of keycode see KeyEvent , I think the
interesting part of the quote is as follows:

keycode meaning

3 HOME key

4 return key

5 Open the dialer app

6 hang up the phone

https://github.com/doanpt/awesome-adb 29/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

keycode meaning

twenty four Increase volume

25 lower the volume

26 Power button

27 Take a picture (need in the camera application)

64 Open browser

82 menu

85 play / Pause

86 Stop play

87 Play next song

88 Play the previous song

122 Move the cursor to the beginning of the line or the top of the list

123 Move the cursor to the end of the line or the bottom of the list

126 Resume playback

127 Pause playback

164 Mute

176 Open system settings

187 Switch app

207 Open contact

208 Open calendar

209 Open music

210 Open the calculator

220 Decrease screen brightness

221 Increase screen brightness

223 System hibernation

224 Light up the screen

https://github.com/doanpt/awesome-adb 30/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

keycode meaning

231 Turn on the voice assistant

276 If there is no wakelock, let the system hibernate

The following are input some of the command usage examples.

Power button
command:

adb shell input keyevent 26

The effect is equivalent to pressing the power button.

menu
command:

adb shell input keyevent 82

HOME key
command:

adb shell input keyevent 3

return key
command:

adb shell input keyevent 4

volume control
Increase volume:

adb shell input keyevent 24

lower the volume:

https://github.com/doanpt/awesome-adb 31/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

adb shell input keyevent 25

Mute:

adb shell input keyevent 164

Media control
play / Pause:

adb shell input keyevent 85

Stop play:

adb shell input keyevent 86

Play the next song:

adb shell input keyevent 87

Play the previous song:

adb shell input keyevent 88

Resume playback:

adb shell input keyevent 126

Pause playback:

adb shell input keyevent 127

Turn on/off the screen


The analog power button described above can be used to switch the screen on and off, but
if you clearly want to turn on or off the screen, you can use the following method.

Light up the screen:

https://github.com/doanpt/awesome-adb 32/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

adb shell input keyevent 224

Turn off the screen:

adb shell input keyevent 223

Slide to unlock
If no password lock screen is unlocked by sliding gestures, you can input swipe unlock.

Command (parameters are based on model Nexus 5, slide up gesture to unlock example):

adb shell input swipe 300 1000 300 500

Parameters 300 1000 300 500 , respectively 起始点x坐标 起始点y坐标 结束点x坐标 结束点y坐
标 .

Input text
When the focus is in a text box, you can input enter text commands.

command:

adb shell input text hello

Now hello in the text box appeared.

View log

The Android system log is divided into two parts. The underlying Linux kernel log is output
to /proc/kmsg, and the Android log is output to /dev/log.

Android log
Command format:

[adb] logcat [ < option > ] ... [ < filter-spec > ] ...

Common usages are listed as follows:

Filter logs by level

https://github.com/doanpt/awesome-adb 33/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Android logs are divided into the following priority (priority):

V —— Verbose (lowest, most output)


D —— Debug
I —— Info
W —— Warning
E —— Error
F —— Fatal
S —— Silent (the highest, nothing is output)

Filtering logs by a certain level will output logs of that level and above.

For example, the command:

adb logcat * :W

Warning, Error, Fatal and Silent logs will be output.

( Note: In macOS need to give *:W this order * as the tag parameter double quotation
marks, such as adb logcat "*:W" , or will be error no matches found: *:W .)

Filter logs by tag and level

<filter-spec> It may be composed of a plurality of <tag>[:priority] components.

For example, the command:

adb logcat ActivityManager:I MyApp:D * :S

It means to output the ActivityManager log of the Info level above the tag, output the log
MyApp of the Debug level above the tag, and the Silent level log of other tags (that is, shield
other tag logs).

Log format

You can use adb logcat -v <format> the output format option to specify a log.

The log support is as follows <format> :

brief

The default format. The format is:

< priority > / < tag >( < pid > ) : < message >

https://github.com/doanpt/awesome-adb 34/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Example:

D/HeadsetStateMachine( 1785): Disconnected process message: 10, size: 0

process

The format is:

< priority >( < pid > ) < message >

Example:

D( 1785) Disconnected process message: 10, size: 0 (HeadsetStateMachine)

tag

The format is:

< priority > / < tag > : < message >

Example:

D/HeadsetStateMachine: Disconnected process message: 10, size: 0

raw

The format is:

< message >

Example:

Disconnected process message: 10, size: 0

time

The format is:

< datetime > < priority > / < tag >( < pid > ) : < message >

Example:
https://github.com/doanpt/awesome-adb 35/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

08-28 22:39:39.974 D/HeadsetStateMachine( 1785): Disconnected process mess

threadtime

The format is:

< datetime > < pid > < tid > < priority > < tag > : < message >

Example:

08-28 22:39:39.974 1785 1832 D HeadsetStateMachine: Disconnected process m

long

The format is:

[ < datetime > < pid > : < tid > < priority > / < tag > ]
< message >

Example:

[08-28 22:39:39.974 1785: 1832 D/HeadsetStateMachine]


Disconnected process message: 10, size: 0

The specified format can be used simultaneously with the above filtering. such as:

adb logcat -v long ActivityManager:I * :S

Clear log

adb logcat -c

Kernel log
command:

adb shell dmesg

Sample output:
https://github.com/doanpt/awesome-adb 36/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

< 6 > [14201.684016] PM: noirq resume of devices complete after 0.982 msecs
< 6 > [14201.685525] PM: early resume of devices complete after 0.838 msecs
< 6 > [14201.753642] PM: resume of devices complete after 68.106 msecs
< 4 > [14201.755954] Restarting tasks ... done.
< 6 > [14201.771229] PM: suspend exit 2016-08-28 13:31:32.679217193 UTC
< 6 > [14201.872373] PM: suspend entry 2016-08-28 13:31: 32.780363596 UTC
< 6 > [14201.872498] PM: Syncing filesystems ... done.

In parentheses [14201.684016] after the kernel started representing time in seconds.

By kernel log we can do something, such as a measure of the kernel boot time, found in the
kernel log after the system is ready in Freeing init memory front of the line that time is.

View device information

model
command:

adb shell getprop ro.product.model

Sample output:

Nexus 5

Battery condition
command:

adb shell dumpsys battery

Input example:

Current Battery Service state:


AC powered: false
USB powered: true
Wireless powered: false
status: 2
health: 2
present: true
level: 44
scale: 100
voltage: 3872

https://github.com/doanpt/awesome-adb 37/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

temperature: 280
technology: Li-poly

Which scale represents the maximum power, level represents the current charge. The
output above indicates that 44% of the battery is left.

Screen Resolution
command:

adb shell wm size

Sample output:

Physical size: 1080x1920

The device screen resolution is 1080px * 1920px.

If it is modified using the command, the output may be:

Physical size: 1080x1920


Override size: 480x1024

Indicates that the screen resolution of the device was originally 1080px * 1920px, but is
currently modified to 480px * 1024px.

Screen density
command:

adb shell wm density

Sample output:

Physical density: 420

The device screen density is 420dpi.

If it is modified using the command, the output may be:

Physical density: 480


Override density: 160

https://github.com/doanpt/awesome-adb 38/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Indicates that the screen density of the device was originally 480dpi, but is currently
modified to 160dpi.

Display parameters
command:

adb shell dumpsys window displays

Sample output:

WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)


Display: mDisplayId=0
init=1080x1920 420dpi cur=1080x1920 app=1080x1794 rng=1080x1017-1810x1731
deferred=false layoutNeeded=false

Which mDisplayId is the display number init is the initial resolution and screen density
and app height than init in the smaller, expressed the virtual keys at the bottom of the
screen, height is 1920 - 1794 = 126px co 42dp.

android_id
command:

adb shell settings get secure android_id

Sample output:

51b6be48bac8c569

IMEI
In Android 4.4 and below, IMEI can be obtained by the following command:

adb shell dumpsys iphonesubinfo

Sample output:

Phone Subscriber Info:


Phone Type = GSM
Device ID = 860955027785041

https://github.com/doanpt/awesome-adb 39/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Which Device ID is the IMEI.

In Android 5.0 and above, the output of this command is empty, and it has to be obtained by
other means (root permission is required):

adb shell
su
service call iphonesubinfo 1

Sample output:

Result: Parcel(
0x00000000: 00000000 0000000f 00360038 00390030 ' ........8.6.0.9. '
0x00000010: 00350035 00320030 00370037 00350038 ' 5.5.0.2.7.7.8.5. '
0x00000020: 00340030 00000031 ' 0.4.1... ' )

Extracting the effective content inside is IMEI, for example, here is 860955027785041 .

Reference: adb shell dumpsys iphonesubinfo not working since Android 5.0 Lollipop

Android system version


command:

adb shell getprop ro.build.version.release

Sample output:

5.0.2

IP address
Every time you want to know the IP address of the device, you have to "Settings"-"About
Phone"-"Status Information"-"IP Address" is annoying, right? It can be easily viewed
through adb.

command:

adb shell ifconfig | grep Mask

Sample output:

https://github.com/doanpt/awesome-adb 40/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

inet addr:10.130.245.230 Mask:255.255.255.252


inet addr: 127.0.0.1 Mask: 255.0.0.0

So 10.130.245.230 is the device IP address.

This command has no output on some devices. If the device is connected to WiFi, you can
use the following command to view the LAN IP:

adb shell ifconfig wlan0

Sample output:

wlan0: ip 10.129.160.99 mask 255.255.240.0 flags [up broadcast running multica

or

wlan0 Link encap:UNSPEC


inet addr:10.129.168.57 Bcast:10.129.175.255 Mask:255.255.240.0
inet6 addr: fe80::66cc:2eff:fe68:b6b6/64 Scope: Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:496520 errors:0 dropped:0 overruns:0 frame:0
TX packets: 68215 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3000
RX bytes: 116266821 TX bytes: 8311736

If the above command still does not get the expected information, you can try the following
command (available in some system versions):

adb shell netcfg

Sample output:

wlan0 UP 10.129.160.99/20 0x00001043 f8:a9:d0:17:42:4d


lo UP 127.0.0.1/8 0x00000049 00:00:00:00:00:00
p2p0 UP 0.0.0.0/0 0x00001003 fa:a9:d0:17:42:4d
sit0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00
rmnet0 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet1 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet3 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet2 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet4 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet6 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet5 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00
rmnet7 DOWN 0.0.0.0/0 0x00000000 00:00:00:00:00:00

https://github.com/doanpt/awesome-adb 41/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

rev_rmnet3 DOWN 0.0.0.0/0 0x00001002 4e:b7:e4:2e:17:58


rev_rmnet2 DOWN 0.0.0.0/0 0x00001002 4e:f0:c8:bf:7a:cf
rev_rmnet4 DOWN 0.0.0.0/0 0x00001002 a6:c0:3b:6b:c4:1f
rev_rmnet6 DOWN 0.0.0.0/0 0x00001002 66:bb:5d:64:2e:e9
rev_rmnet5 DOWN 0.0.0.0/0 0x00001002 0e:1b:eb:b9:23:a0
rev_rmnet7 DOWN 0.0.0.0/0 0x00001002 7a:d9:f6:81:40:5a
rev_rmnet8 DOWN 0.0.0.0/0 0x00001002 4e:e2:a9:bb:d0:1b
rev_rmnet0 DOWN 0.0.0.0/0 0x00001002 fe:65:d0:ca:82:a9
rev_rmnet1 DOWN 0.0.0.0/0 0x00001002 da:d8:e8:4f:2e:fe

You can see information such as network connection name, activation status, IP address,
and Mac address.

Mac address
command:

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

Sample output:

f8:a9:d0:17:42:4d

This view is the LAN Mac address, mobile network connection, or other information that
may be mentioned by an earlier section "IP address" in adb shell netcfg order to see.

CPU information
command:

adb shell cat /proc/cpuinfo

Sample output:

Processor : ARMv7 Processor rev 0 (v7l)


processor : 0
BogoMIPS : 38.40

processor : 1
BogoMIPS : 38.40

processor : 2
BogoMIPS : 38.40

processor : 3
BogoMIPS : 38.40

https://github.com/doanpt/awesome-adb 42/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Features : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva
CPU implementer : 0x51
CPU architecture: 7
CPU variant : 0x2
CPU part : 0x06f
CPU revision : 0

Hardware : Qualcomm MSM 8974 HAMMERHEAD (Flattened Device Tree)


Revision : 000b
Serial : 0000000000000000

This is the CPU information of Nexus 5. We can see from the output that the hardware used
is Qualcomm MSM 8974 , the processor number is 0 to 3, so it is quad-core, and the
architecture used is ARMv7 Processor rev 0 (v71) .

Memory information
command:

adb shell cat /proc/meminfo

Sample output:

MemTotal: 1027424 kB
MemFree: 486564 kB
Buffers: 15224 kB
Cached: 72464 kB
SwapCached: 24152 kB
Active: 110572 kB
Inactive: 259060 kB
Active(anon): 79176 kB
Inactive(anon): 207736 kB
Active(file): 31396 kB
Inactive(file): 51324 kB
Unevictable: 3948 kB
Mlocked: 0 kB
HighTotal: 409600 kB
HighFree: 132612 kB
LowTotal: 617824 kB
LowFree: 353952 kB
SwapTotal: 262140 kB
SwapFree: 207572 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 265324 kB
Mapped: 47072 kB
Shmem: 1020 kB
Slab: 57372 kB

https://github.com/doanpt/awesome-adb 43/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

SReclaimable: 7692 kB
SUnreclaim: 49680 kB
KernelStack: 4512 kB
PageTables: 5912 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 775852 kB
Committed_AS: 13520632 kB
VmallocTotal: 385024 kB
VmallocUsed: 61004 kB
VmallocChunk: 209668 kB

Among them, MemTotal is the total memory of the device, which MemFree is the current
free memory.

More hardware and system attributes


More hardware and system properties of the device can be viewed through the following
commands:

adb shell cat /system/build.prop

This will output a lot of information, including the "model" and "Android system version"
mentioned in the previous sections.

Further comprising output in some other useful information, they can adb shell getprop <
属性名> view the command alone, include a portion of the following properties:
Attribute name meaning

ro.build.version.sdk SDK version

ro.build.version.release Android system version

ro.build.version.security_patch Android security patch level

ro.product.model model

ro.product.brand Brand

ro.product.name Equipment name

ro.product.board Processor model

ro.product.cpu.abilist List of abi supported by CPU [ Section 1 ]

persist.sys.isUsbOtgEnabled Whether to support OTG

https://github.com/doanpt/awesome-adb 44/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Attribute name meaning

dalvik.vm.heapsize Maximum memory per application

ro.sf.lcd_density Screen density

Section Note 1:

Some small factories custom ROM may be modified CPU support list of property names
abi, if the ro.product.cpu.abilist find can not attribute name, you can try this:

adb shell cat /system/build.prop | grep ro.product.cpu.abi

Sample output:

ro.product.cpu.abi=armeabi-v7a
ro.product.cpu.abi2=armeabi

Modify settings

Note: After modifying the settings, it is possible to run the restore command displays still
not normal, you can run adb reboot restart the device, or manual restart.

The principle of modifying settings is mainly to modify the setting values stored in
/data/data/com.android.providers.settings/databases/settings.db through the settings
command.

Resolution
command:

adb shell wm size 480x1024

Means to modify the resolution to 480px * 1024px.

Restore the original resolution command:

adb shell wm size reset

Screen density
command:

https://github.com/doanpt/awesome-adb 45/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

adb shell wm density 160

Indicates to modify the screen density to 160dpi.

Restore the original screen density command:

adb shell wm density reset

Display area
command:

adb shell wm overscan 0,0,0,200

The four numbers respectively indicate the margin pixels from the left, top, right, and bottom
edges. The above command means to leave the bottom of the screen 200px blank.

Restore the original display area command:

adb shell wm overscan reset

Turn off USB debugging mode


command:

adb shell settings put global adb_enabled 0

restore:

It can't be restored by command, after all, if you turn off the USB debugging adb, you can't
connect to the Android device.

Go to the device to manually restore it: "Settings"-"Developer Options"-"Android


Debugging".

Allow/disable access to non-SDK API


Allow access to non-SDK API:

adb shell settings put global hidden_api_policy_pre_p_apps 1


adb shell settings put global hidden_api_policy_p_apps 1

https://github.com/doanpt/awesome-adb 46/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Prohibit access to non-SDK APIs:

adb shell settings delete global hidden_api_policy_pre_p_apps


adb shell settings delete global hidden_api_policy_p_apps

There is no need for the device to obtain root permissions.

The meaning of the number at the end of the command:

value meaning

It is forbidden to detect calls to non-SDK interfaces. In this case, the logging


0 function is disabled and the strict mode API, namely detectNonSdkApiUsage()
is invalid. Not recommended.

Warning only-Allow access to all non-SDK interfaces, but keep the warning
1
information in the log, you can continue to use the strick mode API.

2 It is forbidden to call the interfaces in the dark gray list and black list.

It is forbidden to call the interfaces in the blacklist, but it is allowed to call the
3
interfaces in the dark gray list.

Display and hide the status bar and navigation bar


The related settings mentioned in this section correspond to "Extended Desktop" in
Cyanogenmod.

command:

adb shell settings put global policy_control < key-values >

<key-values> It can be composed of the following keys and their corresponding values in
the format <key1>=<value1>:<key2>=<value2> .

key meaning

immersive.full Hide at the same time

immersive.status Hide status bar

immersive.navigation Hide navigation bar

immersive.preconfirms ?

https://github.com/doanpt/awesome-adb 47/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

The values corresponding to these keys can be combined with commas as the following
values:

value meaning

apps All apps

* All interfaces

packagename Designated application

-packagename Exclude specific apps

E.g:

adb shell settings put global policy_control immersive.full = *

Indicates that the status bar and navigation bar are hidden at the same time in all
interfaces.

adb shell settings put global policy_control immersive.status=com.package1,com

Representation provided in the package name com.package1 and com.package2 hide the
status bar in the application, in addition to a package named com.package3 all applications
hidden in the navigation bar.

Utility function

Screenshots
Save the screenshot to the computer:

adb exec-out screencap -p > sc.png

If an older version of adb can not use exec-out command, this time recommended updates
adb version. If you cannot update, you can use the following troublesome methods:

First save the screenshot to the device:

adb shell screencap -p /sdcard/sc.png

Then export the png file to the computer:

https://github.com/doanpt/awesome-adb 48/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

adb pull /sdcard/sc.png

You can use the adb shell screencap -h View screencap command help information,
here are two significant parameters and their meanings:

parameter meaning

-p Specify the save file as png format

-d display- Specify the screen number of the screenshot (when there are multiple
id screens)

If you specify the actual file name .png can be omitted -p parameter at the end; otherwise,
need to use the -p parameter. If you do not specify a file name, the content of the
screenshot file will be output directly to stdout.

Another way to take a screenshot of a one-line command and save it to the computer:

Linux and Windows

adb shell screencap -p | sed " s/\r$// " > sc.png

Mac OS X

adb shell screencap -p | gsed " s/\r$// " > sc.png

This method requires the gnu sed command, which is available directly under Linux, and
also available under the bin folder of the Git installation directory under Windows. If you
really cannot find the command, you can download sed for Windows and add the folder
where sed.exe is located to the PATH environment variable.

However, using the sed command that comes with the system under Mac will report an
error:

sed: RE error: illegal byte sequence

Need to install gnu-sed, and then use the gsed command:

brew install gnu-sed

Record screen

https://github.com/doanpt/awesome-adb 49/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

The recorded screen is saved to /sdcard in mp4 format:

adb shell screenrecord /sdcard/filename.mp4

Press when you need to stop Ctrl-C , the default recording time and maximum recording
time are both 180 seconds.

If you need to export to a computer:

adb pull /sdcard/filename.mp4

You can use the adb shell screenrecord --help View screenrecord command help
information, the following are common parameters and their meanings:

parameter meaning

--size The size of the video, for example 1280x720 , the default is the
WIDTHxHEIGHT screen resolution.

--bit-rate RATE The bit rate of the video, the default is 4Mbps.

--time-limit TIME Recording duration, in seconds.

--verbose Output more information.

Remount the system partition as writable


Note: Root permissions are required.

The /system partition is mounted as read-only by default, but some operations such as
adding commands to the Android system and deleting its own applications require writing to
/system, so you need to remount it as read-write.

step:

1. Enter the shell and switch to root user authority.

command:

adb shell
su

2. View the current partition mounting status.

command:

https://github.com/doanpt/awesome-adb 50/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

mount

Sample output:

rootfs / rootfs ro, relatime 0 0


tmpfs /dev tmpfs rw,seclabel,nosuid,relatime,mode=755 0 0
devpts /dev/pts devpts rw,seclabel,relatime,mode=600 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,seclabel,relatime 0 0
selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
none /var tmpfs rw,seclabel,relatime,mode=770,gid=1000 0 0
none /acct cgroup rw,relatime,cpuacct 0 0
none /sys/fs/cgroup tmpfs rw,seclabel,relatime,mode=750,gid=1000 0 0
none /sys/fs/cgroup/memory cgroup rw,relatime,memory 0 0
tmpfs /mnt/asec tmpfs rw,seclabel,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,seclabel,relatime,mode=755,gid=1000 0 0
none /dev/memcg cgroup rw,relatime,memory 0 0
none /dev/cpuctl cgroup rw,relatime,cpu 0 0
none /sys/fs/cgroup tmpfs rw,seclabel,relatime,mode=750,gid=1000 0 0
none /sys/fs/cgroup/memory cgroup rw,relatime,memory 0 0
none /sys/fs/cgroup/freezer cgroup rw,relatime,freezer 0 0
/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,seclabel,rel
/dev/block/platform/msm_sdcc.1/by-name/userdata /data ext4 rw,seclabel,nos
/dev/block/platform/msm_sdcc.1/by-name/cache /cache ext4 rw,seclabel,nosui
/dev/block/platform/msm_sdcc.1/by-name/persist /persist ext4 rw,seclabel,n
/dev/block/platform/msm_sdcc.1/by-name/modem /firmware vfat ro,context=u:o
/dev/fuse /mnt/shell/emulated fuse rw,nosuid,nodev,relatime,user_id=1023,g
/dev/fuse /mnt/shell/emulated/0 fuse rw,nosuid,nodev,relatime,user_id=1023

Find the line with /system that we are concerned about:

/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,seclabel,rel

3. Remount.

command:

mount -o remount,rw -t yaffs2 /dev/block/platform/msm_sdcc.1/by-name/syste

Here /dev/block/platform/msm_sdcc.1/by-name/system is the file path we get from


output in the previous step.

If the output does not prompt an error, the operation is successful, and you can do whatever
you want with the files under /system.
https://github.com/doanpt/awesome-adb 51/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

View connected WiFi password


Note: Root permissions are required.

command:

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

Sample output:

network={
ssid= " TP-LINK_9DFC "
scan_ssid=1
psk= " 123456789 "
key_mgmt=WPA-PSK
group=CCMP TKIP
auth_alg=OPEN
sim_num=1
priority=13893
}

network={
ssid= " TP-LINK_F11E "
psk= " 987654321 "
key_mgmt=WPA-PSK
sim_num=1
priority=17293
}

ssid That is the name we see in the WLAN settings, psk the password, and key_mgmt the
security encryption method.

Set the system date and time


Note: Root permissions are required.

command:

adb shell
su
date -s 20160823.131500

Indicates to change the system date and time to 13:15:00 on August 23, 2016.

restart cellphone

https://github.com/doanpt/awesome-adb 52/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

command:

adb reboot

Check if the device is rooted


command:

adb shell
su

At this point the command line prompt is $ said that no root privileges, is # it indicates root.

Use Monkey for stress testing


Monkey can generate pseudo-random user events to simulate clicks, touches, gestures and
other operations, and can perform random stress tests on programs under development.

Simple usage:

adb shell monkey -p < packagename > -v 500

Told <packagename> to send 500 pseudo-random event specified application.

Detailed usage Monkey references official documents .

Turn on/off WiFi


Note: Root permissions are required.

Sometimes it is necessary to control the WiFi status of the device, which can be done with
the following commands.

Turn on WiFi:

adb root
adb shell svc wifi enable

Turn off WiFi:

adb root
adb shell svc wifi disable

https://github.com/doanpt/awesome-adb 53/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

If the execution is successful, the output will be empty; if the command is executed without
root privileges, the execution will fail and the output will be output Killed .

Relevant commands for flashing

Restart to Recovery mode


command:

adb reboot recovery

Restart from Recovery to Android


command:

adb reboot

Restart to Fastboot mode


command:

adb reboot bootloader

Update the system via sideload


If we download the system update package corresponding to the Android device to the
computer, we can also complete the update through adb.

Take the update in Recovery mode as an example:

1. Restart to Recovery mode.

command:

adb reboot recovery

2. Enter Apply update - on the Recovery interface of the device Apply from ADB .

Note: Different Recovery menus may be different from this, and some have first-level
menus Apply update from ADB .

3. Upload and update the system via adb.

https://github.com/doanpt/awesome-adb 54/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

command:

adb sideload < path-to-update.zip >

Security related commands

Enable/disable SELinux
Enable SELinux

adb root
adb shell setenforce 1

Disable SELinux

adb root
adb shell setenforce 0

Enable/disable dm_verity
Enable dm_verity

adb root
adb enable-verity

Disable dm_verity

adb root
adb disable-verity

More adb shell commands

Android system is based on the Linux kernel, so Linux in many commands in Android also
has the same or similar implement, in adb shell can be called in. Part earlier in this
document have been used in the adb shell command.

View process
command:

adb shell ps
https://github.com/doanpt/awesome-adb 55/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Sample output:

USER PID PPID VSIZE RSS WCHAN PC NAME


root 1 0 8904 788 ffffffff 00000000 S /init
root 2 0 0 0 ffffffff 00000000 S kthreadd
...
u0_a71 7779 5926 1538748 48896 ffffffff 00000000 S com.sohu.inputmethod.sogou:
u0_a58 7963 5926 1561916 59568 ffffffff 00000000 S org.mazhuang.boottimemeasur
...
shell 8750 217 10640 740 00000000 b6f28340 R ps

Meaning of each column:

Column name meaning

USER Owned user

PID Process id

PPID Parent process ID

NAME Process name

View real-time resource usage


command:

adb shell top

Sample output:

User 0%, System 6%, IOW 0%, IRQ 0%


User 3 + Nice 0 + Sys 21 + Idle 280 + IOW 0 + IRQ 0 + SIRQ 3 = 307

PID PR CPU% S # THR VSS RSS PCY UID Name


8763 0 3% R 1 10640K 1064K fg shell top
131 0 3% S 1 0K 0K fg root dhd_dpc
6144 0 0% S 115 1682004K 115916K fg system system_server
132 0 0% S 1 0K 0K fg root dhd_rxf
1731 0 0% S 6 20288K 788K fg root /system/bin/mpdecision
217 0 0% S 6 18008K 356K fg shell /sbin/adbd
...
7779 2 0% S 19 1538748K 48896K bg u0_a71 com.sohu.inputmethod.sogou:classic
7963 0 0% S 18 1561916K 59568K fg u0_a58 org.mazhuang.boottimemeasure
...

https://github.com/doanpt/awesome-adb 56/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Meaning of each column:

Column
meaning
name

PID Process id

PR priority

CPU% Percentage of CPU occupied instantly

Process status (R=running, S=sleeping, T=tracking/stopping, Z=zombie


S
process)

#THR Threads

Virtual Set Size virtual memory consumption (including memory occupied


VSS
by shared libraries)

Resident Set Size actual use of physical memory (including memory


RSS
occupied by shared libraries)

PCY Priority of scheduling strategy, SP_BACKGROUND/SPFOREGROUND

UID User ID of the process owner

NAME Process name

top The command also supports some command line parameters, the detailed usage is
as follows:

Usage: top [-m max_procs] [ -n iterations] [ -d delay] [ -s sort_column] [ -t


-m num shows how many processes at most
-n num exit after refreshing how many times
-d num refresh interval (unit: second, default value 5)
-s col Sort by a column (available col values: cpu, vss, rss, thr)
-t display thread information
-h show help document

View process UID


There are two options:

1. adb shell dumpsys package <packagename> | grep userId=

Such as:

https://github.com/doanpt/awesome-adb 57/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

$ adb shell dumpsys package org.mazhuang.guanggoo | grep userId=


userId=10394

2. After finding the pid of the corresponding process through the ps command adb shell
cat /proc/<pid>/status | grep Uid

Such as:

$ adb shell
gemini:/ $ ps | grep org.mazhuang.guanggoo
u0_a394 28635 770 1795812 78736 SyS_epoll_ 0000000000 S org.mazhuang.guang
gemini:/$ cat /proc/28635/status | grep Uid
Uid: 10394 10394 10394 10394
gemini:/$

other
The following is a brief description of other commonly used commands. The commands that
have been specifically mentioned above will not be explained separately:

command Features

cat Show file content

cd Switch directory

chmod Change file access mode/access permissions

df View disk space usage

grep Filter output

kill Kill the process with the specified PID

ls List directory contents

mount View and manage mount directories

mv Move or rename files

ps View the running process

rm Delete Files

top View the resource usage of the process

common problem
https://github.com/doanpt/awesome-adb 58/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Failed to start adb server


Error message

error: protocol fault (couldn ' t read status): No error

Possible Causes

Port 5037 that the adb server process wants to use is occupied.

solution

Find the process occupying port 5037, and then terminate it. Take Windows as an example:

netstat -ano | findstr LISTENING

...
TCP 0.0.0.0:5037 0.0.0.0:0 LISTENING 1548
...

Here 1548 is the process ID, end the process with the command:

taskkill /PID 1548

Then start adb and there is no problem.

com.android.ddmlib.AdbCommandRejectedException
Create a new emulator in Android Studio, but cannot connect with adb, prompt:

com.android.ddmlib.AdbCommandRejectedException: device unauthorized.


This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.

Install a terminal on the phone and execute su and prompt that there is no such command.
This is abnormal.

So after deleting the emulator, download and install it again, this time it is normal.

Unofficial implementation of adb

fb-adb -A better shell for Android devices (for Mac).

https://github.com/doanpt/awesome-adb 59/60
2/25/2021 doanpt/awesome-adb: ADB Usage Complete / ADB Usage Complete

Related commands
aapt
am
dumsys
pm
uiautomator

Thanks

Thank you friends for your selfless sharing and supplements (in no particular order).

zxning , linhua55 , codeskyblue , seasonyuu , fan123199 , zhEdward , 0x8BADFOOD ,


keith666666 , shawnlinboy , s-xq , lucky9322 .

Reference link

Android Debug Bridge


ADB Shell Commands
logcat Command-line Tool
Android ADB command list
Adb command line usage record
Android ADB command list (view wifi password, MAC address, device information,
operation file, view file, log information, uninstall, start and install APK through ADB
command)
Those ADB commands that Android development must know
adb shell top
Use ADB command line like a master (2)

Releases

No releases published
Create a new release

Packages

No packages published
Publish your first package

https://github.com/doanpt/awesome-adb 60/60

You might also like