Most complete ADB command manual
Tags: android, adb
Published: 2021-01-12 09:58:19

- [What is ADB](#what-is-adb)
- [ADB Architecture](#adb-architecture)
- [ADB port is occupied](#adb-port-is-occupied)
- [Basic usage](#basic-usage)
  * [Command syntax](#command-syntax)
  * [Specify the target device for the command](#specify-the-target-device-for-the-command)
  * [start stop](#start-stop)
  * [View adb version](#view-adb-version)
  * [Run adbd as root](#run-adbd-as-root)
  * [Specify the network port of adb server](#specify-the-network-port-of-adb-server)
- [Device connection management](#device-connection-management)
  * [Query connected devices/emulators](#query-connected-devices-emulators)
  * [USB connection](#usb-connection)
  * [Wireless connection (USB cable required)](#wireless-connection--usb-cable-required-)
  * [Wireless connection (no need to use USB cable)](#wireless-connection--no-need-to-use-usb-cable-)
- [Application Management](#application-management)
  * [View application list](#view-application-list)
  * [All applications](#all-applications)
  * [system applications](#system-applications)
  * [third-party usage](#third-party-usage)
  * [Install APK](#install-apk)
  * [Adb install internal principle introduction](#adb-install-internal-principle-introduction)
  * [Uninstall the app](#uninstall-the-app)
  * [Clear application data and cache](#clear-application-data-and-cache)
  * [View foreground activity](#view-foreground-activity)
  * [View running Services](#view-running-services)
  * [View application details](#view-application-details)
- [Interact with the application](#interact-with-the-application)
  * [Activating Activity](#activating-activity)
  * [Transfer Service](#transfer-service)
  * [Send broadcast](#send-broadcast)
  * [Forcibly stop the application](#forcibly-stop-the-application)
  * [Disable apps and start](#disable-apps-and-start)
  * [Revoke the permissions of the application](#revoke-the-permissions-of-the-application)
- [File Management](#file-management)
  * [Copy the files in the device to the computer](#copy-the-files-in-the-device-to-the-computer)
  * [Copy files from computer to device](#copy-files-from-computer-to-device)
- [Simulation key/input](#simulation-key-input)
  * [Power button](#power-button)
  * [menu](#menu)
  * [HOME key](#home-key)
  * [return key](#return-key)
  * [volume control](#volume-control)
  * [Media Control](#media-control)
  * [Turn on/off the screen](#turn-on-off-the-screen)
  * [Slide to unlock](#slide-to-unlock)
  * [Enter text](#enter-text)
- [View log](#view-log)
  * [Android log](#android-log)
  * [Kernel log](#kernel-log)
- [View device information](#view-device-information)
  * [Model](#model)
  * [Battery status](#battery-status)
  * [Screen Resolution](#screen-resolution)
  * [Screen density](#screen-density)
  * [Display parameters](#display-parameters)
  * [android_id](#android-id)
  * [IMEI](#imei)
  * [Android system version](#android-system-version)
  * [IP address](#ip-address)
  * [Mac address](#mac-address)
  * [CPU information](#cpu-information)
  * [Memory information](#memory-information)
  * [More hardware and system properties](#more-hardware-and-system-properties)
- [Modify settings](#modify-settings)
  * [Resolution](#resolution)
  * [Screen density](#screen-density-1)
  * [Display area](#display-area)
  * [Turn off USB debugging mode](#turn-off-usb-debugging-mode)
  * [Display and hide status bar and navigation bar](#display-and-hide-status-bar-and-navigation-bar)
  * [Return to normal mode](#return-to-normal-mode)
- [Useful functions](#useful-functions)
  * [Screenshots](#screenshots)
  * [Record screen](#record-screen)
  * [Remount.](#remount)
  * [View connected WiFi passwords](#view-connected-wifi-passwords)
  * [Set the system date and time](#set-the-system-date-and-time)
  * [restart cellphone](#restart-cellphone)
  * [Check if the device is rooted](#check-if-the-device-is-rooted)
  * [Use Monkey for stress testing](#use-monkey-for-stress-testing)
  * [Turn on/off WiFi](#turn-on-off-wifi)
  * [Turn on/off data traffic](#turn-on-off-data-traffic)
- [Flashing related commands](#flashing-related-commands)
  * [Restart to Recovery mode](#restart-to-recovery-mode)
  * [Restart from Recovery to Android](#restart-from-recovery-to-android)
  * [Restart to Fastboot mode](#restart-to-fastboot-mode)
  * [Update the system via sideload](#update-the-system-via-sideload)
  * [More adb shell commands](#more-adb-shell-commands)
  * [View process](#view-process)
  * [View real-time resource usage](#view-real-time-resource-usage)
  * [View process UID](#view-process-uid)
  * [Other](#other)
- [Security related](#security-related)
  * [Enable SELinux](#enable-selinux)
  * [Disable SELinux](#disable-selinux)
  * [Enable dm_verity](#enable-dm-verity)
  * [Disable dm_verity](#disable-dm-verity)
- [common problem](#common-problem)
  * [Failed to start adb server](#failed-to-start-adb-server)



**The content of this article is integrated from the Internet, welcome to reprint. **

I believe that friends who do Android development have used ADB commands, but they are only limited to installing application push files and device restarting. I don’t know the deeper ones. In fact, we can understand a little more. There are some uncommon scenarios we should at least Knowing that it can be done, for example, we know adb install but not adb shell am start. The former is used to install software, and the latter is used to open the software. A usage scenario of the latter makes me pay attention to him: the company customizes the Android system. When debugging the screen, it depends on whether the screen is full to verify that the driver is normal. This is a troublesome approach. It is to be installed and opened in the hands of Android developers with eclipse or other ide. Obviously, it is much more complicated than the driver who connects the data line and uses the adb command. Therefore, it is necessary to know more.

The following may be more cumbersome, I will try to be simple, please be patient and finish reading.



## What is ADB


----------


The full name of Adb is Android Debug Bridge: Android Debug Bridge. The picture below shows the official introduction of Adb by Android:

![在这里插入图片描述](https://img-blog.csdnimg.cn/20190620094906531.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3pob25nbHVuc2h1bg==,size_16,color_FFFFFF,t_70)

It can be seen that the original intention of Android is to use a tool such as adb to assist developers in debugging apk faster and better in the process of developing android applications, so adb has the ability to install and uninstall apk, copy and push files, view device hardware information, and view Functions such as applications occupying resources and executing shell commands on the device;

We can find the adb tool in the platform-tools directory of the android sdk installation directory;

The permission mechanism of the existing Android system is becoming more and more perfect. Many operations that hope to bypass the permission management mechanism are no longer available, but Adb can achieve it. In fact, Adb has a lot of authority to some extent, even on the latest version of the Android system. Because Adb is designed to facilitate debugging by developers, it is necessary to expose some interfaces outside of permissions. So many companies can use this feature to **bypass the permission mechanism** to do some operations on non-Root non-customized machines (the specific usage is mentioned below), of course, there are also various ways, such as connecting via mobile phone OTG, which will not be repeated here.

## ADB Architecture

In order to facilitate understanding, we start with three instructions, we often use adb start-server, adb devices, adb kill-server.
Then we often see this output interface:

```
C:\Users\dell>adb devices
List of devices attached
* daemon not running. starting it now at tcp:5037 *
* daemon started successfully *
```

So there are three questions here, why is the server, the server corresponds to the server or the server? If the mobile phone is the client, does the server refer to the service opened on the computer. And what is this daemon?

ADB is a C/S architecture application, composed of three parts:

  1. Adb client running on the PC side:
     The command line program "adb" is used to run adb commands from a shell or script. First, the "adb" program tries to locate the ADB server on the host. If the ADB server cannot be found, the "adb" program automatically starts an ADB server. Next, when the adbd of the device and the adb server on the pc side establish a connection, the adb client can send a service request to the ADB servcer;
  2. Adb server running on the PC side:
     ADB Server is a background process running on the host. Its function is to detect the connection and removal of the USB port sensing device, and the start or stop of the emulator instance. ADB Server also needs to send the request of the adb client to the corresponding adbd via usb or tcp;
  3. The resident process adb demon (adbd) running on the device side:
     The program "adbd" runs as a background process in the Android device or emulator system. Its function is to connect to the ADB server and provide some services for the client running on the host;

![在这里插入图片描述](https://img-blog.csdnimg.cn/20190620094923717.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3pob25nbHVuc2h1bg==,size_16,color_FFFFFF,t_70)
----------

![在这里插入图片描述](https://img-blog.csdnimg.cn/20190620094933317.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3pob25nbHVuc2h1bg==,size_16,color_FFFFFF,t_70)

## ADB port is occupied

A small partner said that he hoped that I would put the Adb startup problem at the top, because he often encountered the problem of adb unable to find the device, then I will put it in front, I think it is definitely not only she will encounter this situation .

5037 is the default port of adb. If port 5037 is occupied, we will be troubled by not finding the device when using the Adb command. This problem is often encountered for those who are not very familiar with Adb, so I will This usage is placed at the beginning of the article so that friends can find it easily;
The idea of ​​solving this kind of port occupation problem is the same, three steps:

1. Find the Pid of the process using the port;

```bash
C:\Windows\system32>netstat -aon|findstr 5037
TCP 127.0.0.1:5037 0.0.0.0:0 LISTENING 3172
```

2. Find the corresponding process name through PID (easy to locate, you can skip);

```bash
C:\Windows\system32>tasklist /fi "PID eq 3172"

Image name PID session name session# memory usage
========================= ======== ================ = ========== ============
360MobileLink.exe 3172 Console 4 40,208 K
```

3. Use the command to terminate the operation of the command;

```bash
C:\Users\wwx229495>taskkill /pid 3172 /f
Success: The process with PID 3172 has been terminated.
```



> Sometimes, some rogue programs will copy a copy of Adb.exe to the windows environment variable, such as C://Windows/system32, at this time we can use Where
> The Adb command finds out the path where adb is located and deletes it.


## Basic usage


----------


What can adb do? The answer is that all operations that can be performed on mobile phones can be implemented with adb. That is to say, if you play 6, your touch screen is completely broken, and the display is completely broken, just give you a motherboard, and you can still complete the actions you want to do. Of course, this is not recommended in general scenarios, efficiency is the priority.

The following content is transferred from the [blog](https://github.com/mzlogin/awesome-adb) of a big cow on github. If there is any infringement, please inform and delete it immediately;
Late

### Command syntax


The basic syntax of the adb command is as follows:

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

If there is only one device/emulator connected, you can omit the part [-d|-e|-s <serialNumber>] and use adb <command> directly.

### Specify the target device for the command

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

<table>
<thead>
<tr>
<th>Parameters</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>-d</td>
<td>Specify the only Android device currently connected via USB as the command target</td>
</tr>
<tr>
<td>-e</td>
<td>Specify the only simulator currently running as the command target</td>
</tr>
<tr>
<td><code>-s &lt;serialNumber&gt;</code></td>
<td>Specify the device/emulator with the corresponding serialNumber number as the command target</td>
</tr></tbody></table>


When multiple devices/emulators are connected, the -s <serialNumber> parameter is commonly used. The serialNumber can be obtained through the adb devices command. Such as:

```
$ adb devices

List of devices attached
cf264b8f device
emulator-5554 device
10.129.164.6:5555 device
```

Cf264b8f, emulator-5554 and 10.129.164.6:5555 in the output are serialNumber.

For example, you want to specify the device cf264b8f to run the adb command to obtain the screen resolution:

```
adb -s cf264b8f shell wm size
```

Another example is to install an application on the device 10.129.164.6:5555 (the format of serialNumber in this form is <IP>:<Port>, which is generally a wirelessly connected device or a third-party Android emulator such as Genymotion):

```
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. *

###  start 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


```
adb version
```

Sample output

```
Android Debug Bridge version 1.0.36
Revision 8f855a3d9b35-android
```

### Run adbd as root


The operating principle of adb is that the adb server on the PC side establishes a connection with the daemon 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.

So if adbd is executed with normal permissions, some commands that require root permissions to execute cannot be directly executed with adb xxx. At this time, you can execute commands after adb shell and then su, or you can let adbd execute with root privileges, which can execute high-privileged commands at will.

command:

```
adb root
```

Normal output:

```
restarting adbd as root
```

Now run adb shell again and see if the command line prompt becomes #?

Some mobile phones cannot be executed with root privileges through the adb root command after rooting. For example, some Samsung models will prompt adbd cannot run as root in production builds. You can install **adbd Insecure** first, and then adb root Try it.

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

### Specify the network port of adb server


```
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
emulator-5554 device
10.129.164.6:5555 device
```

The output format is [serialNumber] [state], serialNumber 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 above output shows that three devices/emulators are currently connected, and cf264b8f, emulator-5554 and 10.129.164.6:5555 are their SNs respectively. It can be seen from the name emulator-5554 that it is an Android emulator, and 10.129.164.6:5555, which is the serialNumber of the form <IP>:<Port>, is generally a wirelessly connected device or a third-party Android emulator such as Genymotion.

Common abnormal output:

No device/emulator is successfully connected.

List of devices attached
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:

The hardware status is normal.

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

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

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

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".

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.

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 (USB cable required)

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:
Connect the Android device and the computer to run adb to the same local area network, for example to the same WiFi.
Connect the device to the computer via a USB cable.
Make sure that the connection is successful (you can run adb devices to see if the device can be listed).
Let the device monitor TCP/IP connections on port 5555:

```
adb tcpip 5555
```

Disconnect the USB connection.
Find the IP address of the device.
Generally, it can be found in "Settings"-"About Phone"-"Status Information"-"IP Address", or you can use the adb command to view it using the method in the section View Device Information-IP Address below.

Connect the device by IP address.

```
adb connect <device-ip-address>
```

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

Confirm the connection status.

```
adb devices
```

If you can see

```
<device-ip-address>:5555 device
```

The connection is successful.
If you can't connect, please confirm that the Android device and the computer are connected to the same WiFi, and then execute the step of `adb connect <device-ip-address>` again;
If it still does not work, restart adb via adb kill-server and try again from the beginning.

Disconnect wireless connection
command:

```
adb disconnect <device-ip-address>
```

### Wireless connection (no need to use USB cable)


Note: root permission is required.

The previous section "Wireless connection (requires USB cable)" is the method introduced in the official document, which requires the help of USB data cable to achieve wireless connection.
Since we want to achieve wireless connection, can all steps be wireless? The answer is yes.
Install a terminal emulator on the Android device.
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
Connect the Android device and the computer to run adb to the same local area network, for example to the same WiFi.
Open the terminal emulator on the Android device and run the commands in sequence:

```
su
setprop service.adb.tcp.port 5555
```

Find the IP address of the Android device.

Generally, it can be found in "Settings"-"About Phone"-"Status Information"-"IP Address", or you can use the adb command to view it using the method in the section View Device Information-IP Address below.

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

```
adb connect <device-ip-address>
```

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

If you can see the output connected to <device-ip-address>:5555, it means the connection is successful.

**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

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

That is, on the basis of adb shell pm list packages, you can add some parameters to filter and view different lists. The supported filter parameters are as follows:

<table>
<thead>
<tr>
<th>Parameters</th>
<th>Display list</th>
</tr>
</thead>
<tbody>
<tr>
<td>None</td>
<td>All applications</td>
</tr>
<tr>
<td>-f</td>
<td>Display the apk file associated with the application</td>
</tr>
<tr>
<td>-d</td>
<td>Only display disabled apps</td>
</tr>
<tr>
<td>-e</td>
<td>Only show enabled apps</td>
</tr>
<tr>
<td>-s</td>
<td>Only show system apps</td>
</tr>
<tr>
<td>-3</td>
<td>Only display third-party applications</td>
</tr>
<tr>
<td>-i</td>
<td>Display the installer of the application</td>
</tr>
<tr>
<td>-u</td>
<td>Include uninstalled apps</td>
</tr>
<tr>
<td><code>&lt;FILTER&gt;</code></td>
<td>Package name contains <code>&lt;FILTER&gt;</code> string</td>
</tr></tbody></table>


### All applications

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
...
```

###  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 list of applications whose package name contains the string mazhuang, 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 can be followed by some optional parameters to control the behavior of installing APK. The available parameters and their meanings are as follows:

<table>
<thead>
<tr>
<th>Parameters</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>-l</td>
<td>Install the application to the protected directory /mnt/asec</td>
</tr>
<tr>
<td>-r</td>
<td>Allow overwrite installation</td>
</tr>
<tr>
<td>-t</td>
<td>Allow to install the application specified by application <code>android:testOnly="true"</code> in AndroidManifest.xml</td>
</tr>
<tr>
<td>-s</td>
<td>Install the application to the sdcard</td>
</tr>
<tr>
<td>-d</td>
<td>Allow downgrade to overwrite installation</td>
</tr>
<tr>
<td>-g</td>
<td>Grant all runtime permissions</td>
</tr></tbody></table>


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 latest version of adb of v1.0.36, which will show the progress percentage of pushing the 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 status is Failure, the installation failed, for example:

```
[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:

<table>
<thead>
<tr>
<th>Output</th>
<th>Meaning</th>
<th>Solution</th>
</tr>
</thead>
<tbody>
<tr>
<td>INSTALL_FAILED_ALREADY_EXISTS</td>
<td>The application already exists, or uninstalled but not uninstalled cleanly</td>
<td><code>adb install</code>, use the <code>-r</code> parameter, or first <code>adb uninstall &lt;packagename&gt;</code> and then install</td>
</tr>
<tr>
<td>INSTALL_FAILED_INVALID_APK</td>
<td>Invalid APK file</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_INVALID_URI</td>
<td>Invalid APK file name</td>
<td>Make sure there is no Chinese in the APK file name</td>
</tr>
<tr>
<td>INSTALL_FAILED_INSUFFICIENT_STORAGE</td>
<td>Not enough space</td>
<td>Clean up space</td>
</tr>
<tr>
<td>INSTALL_FAILED_DUPLICATE_PACKAGE</td>
<td>A program with the same name already exists</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_NO_SHARED_USER</td>
<td>The requested shared user does not exist</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_UPDATE_INCOMPATIBLE</td>
<td>The application with the same name has been installed before, but the data is not removed when uninstalling; or the application has been installed, but the signature is inconsistent</td>
<td>First <code>adb uninstall &lt;packagename&gt;</code> then install</td>
</tr>
<tr>
<td>INSTALL_FAILED_SHARED_USER_INCOMPATIBLE</td>
<td>The requested shared user exists but the signature is inconsistent</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_MISSING_SHARED_LIBRARY</td>
<td>The installation package uses a shared library that is not available on the device</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_REPLACE_COULDNT_DELETE</td>
<td>Cannot be deleted when replacing</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_DEXOPT</td>
<td>dex optimization verification failed or insufficient space</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_OLDER_SDK</td>
<td>The device system version is lower than the application requirements</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_CONFLICTING_PROVIDER</td>
<td>A content provider with the same name as the app already exists in the device</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_NEWER_SDK</td>
<td>The device system version is higher than the application requirements</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_TEST_ONLY</td>
<td>The application is test-only, but the <code>-t</code> parameter is not specified during installation</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_CPU_ABI_INCOMPATIBLE</td>
<td>Contains native code of incompatible device CPU application binary interface</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_MISSING_FEATURE</td>
<td>The application uses a feature that is not available on the device</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_CONTAINER_ERROR</td>
<td>1. sdcard access failed; <br>2. The application signature is consistent with the ROM signature and is regarded as a built-in application. </td>
<td>1. Confirm that the sdcard is available, or install it to the built-in storage; <br>2. Do not use the same signature as the ROM when packaging. </td>
</tr>
<tr>
<td>INSTALL_FAILED_INVALID_INSTALL_LOCATION</td>
<td>1. Cannot be installed to the specified location; <br>2. The application signature is consistent with the ROM signature and is regarded as a built-in application. </td>
<td>1. Switch the installation location, add or delete the <code>-s</code> parameter;<br>2. Do not use the same signature as the ROM when packaging. </td>
</tr>
<tr>
<td>INSTALL_FAILED_MEDIA_UNAVAILABLE</td>
<td>The installation location is not available</td>
<td>Usually sdcard, confirm that the sdcard is available or install to the built-in storage</td>
</tr>
<tr>
<td>INSTALL_FAILED_VERIFICATION_TIMEOUT</td>
<td>Verify installation package timeout</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_VERIFICATION_FAILURE</td>
<td>Failed to verify the installation package</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_PACKAGE_CHANGED</td>
<td>The application does not match the expectations of the calling program</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_UID_CHANGED</td>
<td>The application has been installed before, and it is not consistent with the UID assigned this time</td>
<td>Clean up residual files from previous installations</td>
</tr>
<tr>
<td>INSTALL_FAILED_VERSION_DOWNGRADE</td>
<td>A newer version of this app has been installed</td>
<td>Use the <code>-d</code> parameter</td>
</tr>
<tr>
<td>INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE</td>
<td>The installed target SDK supports the application of the same name with runtime permissions, and the version to be installed does not support runtime permissions</td>
<td></td>
</tr>
<tr>
<td>INSTALL_PARSE_FAILED_NOT_APK</td>
<td>The specified path is not a file or does not end with <code>.apk</code></td>
<td></td>
</tr>
<tr>
<td>INSTALL_PARSE_FAILED_BAD_MANIFEST</td>
<td>Unable to parse AndroidManifest.xml file</td>
<td></td>
</tr>
<tr>
<td>INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION</td>
<td>The parser encountered an exception</td>
<td></td>
</tr>
<tr>
<td>INSTALL_PARSE_FAILED_NO_CERTIFICATES</td>
<td>The installation package is not signed</td>
<td></td>
</tr>
<tr>
<td>INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES</td>
<td>The app has been installed, and the signature is inconsistent with the APK file</td>
<td>Uninstall the app on the device first, then install it</td>
</tr>
<tr>
<td>INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING</td>
<td><code>CertificateEncodingException</code></td> when parsing APK file
<td></td>
</tr>
<tr>
<td>INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME</td>
<td>There is no or invalid package name in the manifest file</td>
<td></td>
</tr>
<tr>
<td>INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID</td>
<td>An invalid shared user ID is specified in the manifest file</td>
<td></td>
</tr>
<tr>
<td>INSTALL_PARSE_FAILED_MANIFEST_MALFORMED</td>
<td>A structural error was encountered while parsing the manifest file</td>
<td></td>
</tr>
<tr>
<td>INSTALL_PARSE_FAILED_MANIFEST_EMPTY</td>
<td>The operable tag (instrumentation or application) could not be found in the manifest file</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_INTERNAL_ERROR</td>
<td>Installation failed due to system problems</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_USER_RESTRICTED</td>
<td>Users are restricted from installing apps</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_DUPLICATE_PERMISSION</td>
<td>The application tries to define an existing permission name</td>
<td></td>
</tr>
<tr>
<td>INSTALL_FAILED_NO_MATCHING_ABIS</td>
<td>The application contains native code not supported by the application binary interface of the device</td>
<td></td>
</tr>
<tr>
<td>INSTALL_CANCELED_BY_USER</td>
<td>App installation needs to be confirmed on the device, but the device is not operated or canceled</td>
<td>Agree to install on the device</td>
</tr>
<tr>
<td>INSTALL_FAILED_ACWF_INCOMPATIBLE</td>
<td>The application is not compatible with the device</td>
<td></td>
</tr>
<tr>
<td>does not contain AndroidManifest.xml</td>
<td>Invalid APK file</td>
<td></td>
</tr>
<tr>
<td>is not a valid zip file</td>
<td>Invalid APK file</td>
<td></td>
</tr>
<tr>
<td>Offline</td>
<td>The device is not connected successfully</td>
<td>First connect the device to adb successfully</td>
</tr>
<tr>
<td>unauthorized</td>
<td>The device is not authorized to allow debugging</td>
<td></td>
</tr>
<tr>
<td>error: device not found</td>
<td>There is no successfully connected device</td>
<td>First connect the device to adb successfully</td>
</tr>
<tr>
<td>protocol failure</td>
<td>The device has been disconnected</td>
<td>First connect the device to adb successfully</td>
</tr>
<tr>
<td>Unknown option: -s</td>
<td>Installation to sdcard is not supported under Android 2.2</td>
<td>Do not use the <code>-s</code> parameter</td>
</tr>
<tr>
<td>No space left on device</td>
<td>Not enough space</td>
<td>Clean up space</td>
</tr>
<tr>
<td>Permission denied ... sdcard ...</td>
<td>sdcard is not available</td>
<td></td>
</tr>
<tr>
<td>signatures do not match the previously installed version; ignoring!</td>
<td>The app has been installed and the signatures are inconsistent</td>
<td>Uninstall the app on the device first, then install it</td>
</tr></tbody></table>


Reference: [\[PackageManager.java\]](https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/content/pm/PackageManager.java)

### Adb install internal principle introduction

adb install is actually completed 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 the app


command:

```
adb uninstall [-k] <packagename>
```

`<packagename>` represents the package name of the application, and the -k parameter is optional, meaning that the application is uninstalled but the data and cache directory are retained.
Command example:

```
adb uninstall com.qihoo360.mobilesafe
```

Means to uninstall 360 Mobile Guard.

### Clear application 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
```

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

### View foreground activity


command:

```
adb shell dumpsys activity activities | grep mFocusedActivity
```

Sample output:

```
mFocusedActivity: ActivityRecord{8079d7e u0 com.cyanogenmod.trebuchet/com.android.launcher3.Launcher t42}
```

Among them, `com.cyanogenmod.trebuchet/com.android.launcher3.Launcher` is the Activity currently in the foreground.

### View running Services


command:

```
adb shell dumpsys activity services [<packagename>]
```

The `<packagename>` parameter is not necessary. Specifying `<packagename>` means viewing the Services related to a certain package name, and not specifying it means viewing all Services.

`<packagename>` does not have to give a complete package name. For example, if you run adb shell dumpsys activity services org.mazhuang, then the package name org.mazhuang.demo1, org.mazhuang.demo2, org.mazhuang123 and other related Services will be listed come out.

### 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.BuglyFileProvider}

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

Key Set Manager:
  [org.mazhuang.guanggoo]
      Signing KeySets: 501

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 stopped=true notLaunched=false enabled=0
      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 stopped=true notLaunched=true enabled=0
      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 [compilation_filter=speed-profile, status=kOatUpToDa
      te]
```

## Interact with the application


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

<table>
<thead>
<tr>
<th>command</th>
<th>Use</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>start [options] &lt;INTENT&gt;</code></td>
<td>Start the activity specified by <code>&lt;INTENT&gt;</code></td>
</tr>
<tr>
<td><code>startservice [options] &lt;INTENT&gt;</code></td>
<td>Start the service specified by <code>&lt;INTENT&gt;</code></td>
</tr>
<tr>
<td><code>broadcast [options] &lt;INTENT&gt;</code></td>
<td>Send the broadcast specified by <code>&lt;INTENT&gt;</code></td>
</tr>
<tr>
<td><code>force-stop &lt;packagename&gt;</code></td>
<td>Stop <code>&lt;packagename&gt;</code> related processes</td>
</tr></tbody></table>
<p><code>&lt;INTENT&gt;</code> The parameters are very flexible, and correspond to the Intent in the code when writing Android programs. </p>
<p>The options used to determine the intent object are as follows:</p>
<table>
<thead>
<tr>
<th>Parameters</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-a &lt;ACTION&gt;</code></td>
<td>Specify the action, such as <code>android.intent.action.VIEW</code></td>
</tr>
<tr>
<td><code>-c &lt;CATEGORY&gt;</code></td>
<td>Specify category, such as <code>android.intent.category.APP_CONTACTS</code></td>
</tr>
<tr>
<td><code>-n &lt;COMPONENT&gt;</code></td>
<td>Specify the complete component name, which is used to clearly specify which Activity to start, such as <code>com.example.app/.ExampleActivity</code></td>
</tr></tbody></table>
<p><code>&lt;INTENT&gt;</code> can also carry data, just like Bundle when writing code:</p>
<table>
<thead>
<tr>
<th>Parameters</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--esn &lt;EXTRA_KEY&gt;</code></td>
<td>null value (only key name)</td>
</tr>
<tr>
<td>`-e</td>
<td>--es &lt;EXTRA_KEY&gt; &lt;EXTRA_STRING_VALUE&gt;`</td>
</tr>
<tr>
<td><code>--ez &lt;EXTRA_KEY&gt; &lt;EXTRA_BOOLEAN_VALUE&gt;</code></td>
<td>boolean value</td>
</tr>
<tr>
<td><code>--ei &lt;EXTRA_KEY&gt; &lt;EXTRA_INT_VALUE&gt;</code></td>
<td>integer value</td>
</tr>
<tr>
<td><code>--el &lt;EXTRA_KEY&gt; &lt;EXTRA_LONG_VALUE&gt;</code></td>
<td>long value</td>
</tr>
<tr>
<td><code>--ef &lt;EXTRA_KEY&gt; &lt;EXTRA_FLOAT_VALUE&gt;</code></td>
<td>float 值</td>
</tr>
<tr>
<td><code>--eu &lt;EXTRA_KEY&gt; &lt;EXTRA_URI_VALUE&gt;</code></td>
<td>URI</td>
</tr>
<tr>
<td><code>--ecn &lt;EXTRA_KEY&gt; &lt;EXTRA_COMPONENT_NAME_VALUE&gt;</code></td>
<td>component name</td>
</tr>
<tr>
<td><code>--eia &lt;EXTRA_KEY&gt; &lt;EXTRA_INT_VALUE&gt;[,&lt;EXTRA_INT_VALUE...]</code></td>
<td>integer 数组</td>
</tr>
<tr>
<td><code>--ela &lt;EXTRA_KEY&gt; &lt;EXTRA_LONG_VALUE&gt;[,&lt;EXTRA_LONG_VALUE...]</code></td>
<td>long 数组</td>
</tr></tbody></table>



### Activating Activity


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" "hello, world"
```

It means to call up org.mazhuang.boottimemeasure/.MainActivity and pass it the string data key-value pair toast-hello, world.

### Transfer Service


Command format:

```
adb shell am startservice [options] <INTENT>
```

E.g:

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

Indicates that a certain service of WeChat has been activated.

### Send broadcast


Command format:

```
adb shell am broadcast [options] <INTENT>
```

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

For example, to broadcast BOOT_COMPLETED to all components:

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

For another example, only broadcast BOOT_COMPLETED to org.mazhuang.boottimemeasure/.BootCompletedReceiver:

```
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n org.mazhuang.boottimemeasure/.BootCompletedReceiver
```

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:

<table>
<thead>
<tr>
<th>action</th>
<th>Trigger timing</th>
</tr>
</thead>
<tbody>
<tr>
<td>android.net.conn.CONNECTIVITY_CHANGE</td>
<td>Network connection has changed</td>
</tr>
<tr>
<td>android.intent.action.SCREEN_ON</td>
<td>The screen lights up</td>
</tr>
<tr>
<td>android.intent.action.SCREEN_OFF</td>
<td>The screen goes off</td>
</tr>
<tr>
<td>android.intent.action.BATTERY_LOW</td>
<td>If the battery is low, a low battery prompt box will pop up</td>
</tr>
<tr>
<td>android.intent.action.BATTERY_OKAY</td>
<td>The battery is restored</td>
</tr>
<tr>
<td>android.intent.action.BOOT_COMPLETED</td>
<td>The device has started up</td>
</tr>
<tr>
<td>android.intent.action.DEVICE_STORAGE_LOW</td>
<td>Storage space is too low</td>
</tr>
<tr>
<td>android.intent.action.DEVICE_STORAGE_OK</td>
<td>Storage space recovery</td>
</tr>
<tr>
<td>android.intent.action.PACKAGE_ADDED</td>
<td>A new application is installed</td>
</tr>
<tr>
<td>android.net.wifi.STATE_CHANGE</td>
<td>The WiFi connection status has changed</td>
</tr>
<tr>
<td>android.net.wifi.WIFI_STATE_CHANGED</td>
<td>WiFi status changes to enable/disable/starting/disabling/unknown</td>
</tr>
<tr>
<td>android.intent.action.BATTERY_CHANGED</td>
<td>The battery level has changed</td>
</tr>
<tr>
<td>android.intent.action.INPUT_METHOD_CHANGED</td>
<td>The system input method has changed</td>
</tr>
<tr>
<td>android.intent.action.ACTION_POWER_CONNECTED</td>
<td>External power connection</td>
</tr>
<tr>
<td>android.intent.action.ACTION_POWER_DISCONNECTED</td>
<td>External power supply disconnected</td>
</tr>
<tr>
<td>android.intent.action.DREAMING_STARTED</td>
<td>The system started to sleep</td>
</tr>
<tr>
<td>android.intent.action.DREAMING_STOPPED</td>
<td>The system stops sleeping</td>
</tr>
<tr>
<td>android.intent.action.WALLPAPER_CHANGED</td>
<td>The wallpaper has changed</td>
</tr>
<tr>
<td>android.intent.action.HEADSET_PLUG</td>
<td>Plug in headphones</td>
</tr>
<tr>
<td>android.intent.action.MEDIA_UNMOUNTED</td>
<td>Unload external media</td>
</tr>
<tr>
<td>android.intent.action.MEDIA_MOUNTED</td>
<td>Mount external media</td>
</tr>
<tr>
<td>android.os.action.POWER_SAVE_MODE_CHANGED</td>
<td>Enable power saving mode</td>
</tr></tbody></table>


*(The above broadcasts can all be triggered by adb)*

### Forcibly stop the application

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.

### Disable apps and start

Command example:

```java
adb shell pm disable-user <packagename>
adb shell pm disable <packagename>
```


```java
adb shell pm disable-user [options] <packagename>
```

Command example:

```java
adb shell pm enable <packagename>
```

### Revoke the permissions of the application

1. Grant permissions to the app. Only optional permissions declared by the application can be granted

```java
adb shell pm grant <packagename> <PACKAGE_PERMISSION>
```

For example: `adb -d shell pm grant packageName android.permission.BATTERY_STATS`

2. Cancel app authorization

```java
adb shell pm revoke <packagename> <PACKAGE_PERMISSION>
```

Option `--user user_id: the user to be disabled` For example, grant permissions to the application. On devices running Android 6.0 (API level 23) and higher, the permission can be any permission declared in the application manifest. On devices running Android 5.1 (API level 22) and lower, it must be an optional permission defined by the application.

> Disclaimer: The above order is an unconventional order. I am not responsible for any damage to your equipment, forcible stop, etc. You are performing this operation on your device, and you are responsible for it.

## File Management


### Copy the files in the device to the computer


command:

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

Among them, the directory parameter on the computer can be omitted, and the default is copied to the current directory.

example:

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

*Tips: *The file path on the device may require root privileges to access. If your device has been rooted, you can use the adb shell and su commands to obtain root privileges in the adb shell, then cp /path/on/device /sdcard/filename Copy the file 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/
```

*Tips: *The file path on the device may not be directly written by ordinary permissions. If your device has been rooted, you can first adb push /path/on/pc /sdcard/filename, and then adb shell and su in adb shell After obtaining root permissions, cp /sdcard/filename /path/on/device.

## Simulation key/input


There is a very useful command called input in adb shell, through which you can do some interesting things.
The complete help information of the input 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: keyboard)
      tap <x> <y> (Default: touchscreen)
      swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
      press (Default: trackball)
      roll <dx> <dy> (Default: trackball)
```

For example, to simulate a click: //Click the position of the coordinate point x=50 y=250 on the screen.

> adb shell input tap 50 250

For example, using the adb shell input keyevent <keycode> command, different keycodes can achieve different functions. For the complete keycode list, see KeyEvent. The excerpts are as follows:

<table>
<thead>
<tr>
<th>keycode</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>HOME key</td>
</tr>
<tr>
<td>4</td>
<td>Back key</td>
</tr>
<tr>
<td>5</td>
<td>Open the dial-up application</td>
</tr>
<tr>
<td>6</td>
<td>Hang up the call</td>
</tr>
<tr>
<td>24</td>
<td>Increase volume</td>
</tr>
<tr>
<td>25</td>
<td>Reduce the volume</td>
</tr>
<tr>
<td>26</td>
<td>Power button</td>
</tr>
<tr>
<td>27</td>
<td>Taking photos (need to be in the camera application)</td>
</tr>
<tr>
<td>64</td>
<td>Open the browser</td>
</tr>
<tr>
<td>82</td>
<td>Menu key</td>
</tr>
<tr>
<td>85</td>
<td>Play/Pause</td>
</tr>
<tr>
<td>86</td>
<td>Stop playing</td>
</tr>
<tr>
<td>87</td>
<td>Play the next song</td>
</tr>
<tr>
<td>88</td>
<td>Play the previous song</td>
</tr>
<tr>
<td>122</td>
<td>Move the cursor to the beginning of the line or the top of the list</td>
</tr>
<tr>
<td>123</td>
<td>Move the cursor to the end of the line or the bottom of the list</td>
</tr>
<tr>
<td>126</td>
<td>Resume playback</td>
</tr>
<tr>
<td>127</td>
<td>Pause playback</td>
</tr>
<tr>
<td>164</td>
<td>Mute</td>
</tr>
<tr>
<td>176</td>
<td>Open system settings</td>
</tr>
<tr>
<td>187</td>
<td>Switch application</td>
</tr>
<tr>
<td>207</td>
<td>Open contacts</td>
</tr>
<tr>
<td>208</td>
<td>Open the calendar</td>
</tr>
<tr>
<td>209</td>
<td>Open music</td>
</tr>
<tr>
<td>210</td>
<td>Open the calculator</td>
</tr>
<tr>
<td>220</td>
<td>Reduce screen brightness</td>
</tr>
<tr>
<td>221</td>
<td>Increase screen brightness</td>
</tr>
<tr>
<td>223</td>
<td>System hibernation</td>
</tr>
<tr>
<td>224</td>
<td>Light up the screen</td>
</tr>
<tr>
<td>231</td>
<td>Open the voice assistant</td>
</tr>
<tr>
<td>276</td>
<td>If there is no wakelock, let the system hibernate</td>
</tr></tbody></table>


The following are some usage examples of input command.

###  Power button


```
db 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:**

```
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:**

```
adb shell input keyevent 224
```

**Turn off the screen:**

```
adb shell input keyevent 223
```

### Slide to unlock


If the lock screen does not have a password and is unlocked by swiping gestures, you can unlock it by input swipe.

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

```
adb shell input swipe 300 1000 300 500
```

The parameters 300 1000 300 500 respectively represent the start point x coordinate, the start point y coordinate, the end point x coordinate, and the end point y coordinate.

### Enter text


When the focus is on a text box, you can use the input command to enter text.

command:

```
adb shell input text hello
```

Now hello appears in the text box.

## 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

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: Under macOS, you need to add double quotation marks to *:W so that * as the tag parameter, such as adb logcat "*:W", otherwise an error will be reported no matches found: *:W.)

**Filter logs by tag and level**

`<filter-spec>` can be composed of multiple `<tag>[:priority]`.

For example, the command:

```
adb logcat ActivityManager:I MyApp:D *:S
```

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

**Log Format**

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

The log supports the following types of `<format>`:

 -brief

The default format. The format is:

<priority>/<tag>(<pid>): <message>
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
To
 -raw

The format is:

<message>
Example:

Disconnected process message: 10, size: 0

 -time

The format is:

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

08-28 22:39:39.974 D/HeadsetStateMachine( 1785): Disconnected process message: 10, size: 0

 -threadtime

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

 -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:

```
<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.
```

The [14201.684016] in the brackets represents the time since the kernel started, in seconds.

Through the kernel log we can do some things, such as measuring the kernel startup time, find the time before the Freeing init memory line in the kernel log after the system is started.

## View device information


### Model


command:

```
adb shell getprop ro.product.model
```

Sample output:

Nexus 5

### Battery status


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
  temperature: 280
  technology: Li-poly
```

Among them, scale represents the maximum power, and level represents the current power. 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
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
```

Among them, mDisplayId is the display number, init is the initial resolution and screen density. The height of the app is smaller than that in init, which means that there are virtual buttons at the bottom of the screen. The height is 1920-1794 = 126px and 42dp.

### android_id


command:

```
adb shell settings get secure android_id
```

Sample output:

```
51b6be48bac8c569
```

### IMEI


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

```
adb shell dumpsys iphonesubinfo
```

Sample output:

```
Phone Subscriber Info:
  Phone Type = GSM
  Device ID = 860955027785041
The Device ID is IMEI.
```

In Android 5.0 and above, the output of this command is empty, and it must 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 the 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", which is annoying, right? It can be easily viewed through adb.

command:

```
adb shell ifconfig "| grep Mask"
```

Sample output:

```
inet addr:10.130.245.230 Mask:255.255.255.252
inet addr: 127.0.0.1 Mask: 255.0.0.0
```

Then 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 local area network adb shell ifconfig wlan0 Example:

```
wlan0: ip 10.129.160.99 mask 255.255.240.0 flags [up broadcast running multicast]
```

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
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 the 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 is the local area network Mac address, mobile network or other connection information can be viewed through the adb shell netcfg command mentioned in the previous section "IP address".

### 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

Features: swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
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, and 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
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, and MemFree is the current free memory.

### More hardware and system properties


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.

The output also includes some other useful information, which can also be viewed separately through the adb shell getprop <property name> command. Some properties are listed as follows:

<table>
<thead>
<tr>
<th>Attribute name</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>ro.build.version.sdk</td>
<td>SDK version</td>
</tr>
<tr>
<td>ro.build.version.release</td>
<td>Android system version</td>
</tr>
<tr>
<td>ro.build.version.security_patch</td>
<td>Android security patch level</td>
</tr>
<tr>
<td>ro.product.model</td>
<td>Model</td>
</tr>
<tr>
<td>ro.product.brand</td>
<td>Brand</td>
</tr>
<tr>
<td>ro.product.name</td>
<td>Device name</td>
</tr>
<tr>
<td>ro.product.board</td>
<td>Processor model</td>
</tr>
<tr>
<td>ro.product.cpu.abilist</td>
<td>Abi list supported by CPU [<em>Section 1</em>]</td>
</tr>
<tr>
<td>persist.sys.isUsbOtgEnabled</td>
<td>Whether to support OTG</td>
</tr>
<tr>
<td>dalvik.vm.heapsize</td>
<td>Maximum memory limit for each application</td>
</tr>
<tr>
<td>ro.sf.lcd_density</td>
<td>Screen density</td>
</tr></tbody></table>


**Section Note 1:**

Some ROMs customized by small factories may have modified the attribute name of the abi list supported by the CPU. If you can’t find it with the ro.product.cpu.abilist attribute name, you can try:

```
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, running the recovery command may still display abnormalities. You can run adb reboot to restart the device, or manually 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:

```
adb shell wm density 160
```

Means 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 with commands, after all, if USB debugging is turned off, adb cannot connect to the Android device.

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

### Display and hide 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>` can be composed of the following keys and their corresponding values, in the format of `<key1>=<value1>:<key2>=<value2>`.

<table>
<thead>
<tr>
<th>key</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>immersive.full</td>
<td>Hide at the same time</td>
</tr>
<tr>
<td>immersive.status</td>
<td>Hide the status bar</td>
</tr>
<tr>
<td>immersive.navigation</td>
<td>Hide the navigation bar</td>
</tr>
<tr>
<td>immersive.preconfirms</td>
<td>?</td>
</tr></tbody></table>



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

<table>
<thead>
<tr>
<th>value</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>apps</code></td>
<td>All applications</td>
</tr>
<tr>
<td><code>*</code></td>
<td>All interfaces</td>
</tr>
<tr>
<td><code>packagename</code></td>
<td>Specify application</td>
</tr>
<tr>
<td><code>-packagename</code></td>
<td>Exclude specific applications</td>
</tr></tbody></table>


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.package2:immersive.navigation=apps,-com.package3
```

It means setting to hide the status bar in applications with package names com.package1 and com.package2, and hide the navigation bar in all applications except package names com.package3.

### Return to normal mode

What if I don't want to be full screen?

```
adb shell settings put global policy_control null
```


## Useful functions


### Screenshots


**Save screenshot to computer:**

```
adb exec-out screencap -p> sc.png
```

If the adb version is older and the exec-out command cannot be used, it is recommended to update the adb version at this time. 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:

```
adb pull /sdcard/sc.png
```

You can use adb shell screencap -h to view the help information of the screencap command. The following are two meaningful parameters and their meanings:

<table>
<thead>
<tr>
<th>Parameters</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>-p</td>
<td>Specify the save file as png format</td>
</tr>
<tr>
<td>-d display-id</td>
<td>Specify the screen number of the screenshot (if there are multiple screens)</td>
</tr></tbody></table>


Actually, if the specified file name ends with .png, you can omit the -p parameter; otherwise, you need to use the -p parameter. If you do not specify the file name, the content of the screenshot file will be directly output 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 needs to use the gnu sed command, which is available directly under Linux, and 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


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

```
adb shell screenrecord /sdcard/filename.mp4
```

Press Ctrl-C when you need to stop, 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 adb shell screenrecord --help to view the help information of the screenrecord command. The following are common parameters and their meanings:

<table>
<thead>
<tr>
<th>Parameters</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>--size WIDTHxHEIGHT</td>
<td>The size of the video, such as <code>1280x720</code>, the default is the screen resolution. </td>
</tr>
<tr>
<td>--bit-rate RATE</td>
<td> The bit rate of the video, the default is 4Mbps. </td>
</tr>
<tr>
<td>--time-limit TIME</td>
<td> Recording duration, in seconds. </td>
</tr>
<tr>
<td>--verbose</td>
<td> Output more information. </td>
</tr></tbody></table>


**Remount the system partition as writable**

*Note: root permission is required. *

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

step:

Enter the shell and switch to root user authority.

command:

```
adb shell
su
```

View the current partition mounting status.

command:

```
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,relatime,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/userdata /data ext4 rw,seclabel,nosuid,nodev,relatime,noauto_da_alloc,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/cache /cache ext4 rw,seclabel,nosuid,nodev,relatime,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/persist /persist ext4 rw,seclabel,nosuid,nodev,relatime,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/modem /firmware vfat ro,context=u:object_r:firmware_file:s0,relatime,uid=1000,gid=1000,fmask=0337,dmask=0227,codepage =cp437,iocharset=iso8859-1,shortname=lower,errors=remount-ro 0 0
/dev/fuse /mnt/shell/emulated fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
/dev/fuse /mnt/shell/emulated/0 fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
```

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

```
/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,seclabel,relatime,data=ordered 0 0
```

### Remount.


command:

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

Here /dev/block/platform/msm_sdcc.1/by-name/system is the file path we got from the output of 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.

### View connected WiFi passwords


*Note: root permission is 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 is the name we see in the WLAN settings, psk is the password, and key_mgmt is the security encryption method.

### Set the system date and time


*Note: root permission is required. *

command:

```
adb shell
su
date -s 20160823.131500
```

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

### restart cellphone


command:

```
adb reboot
```

### Check if the device is rooted


command:

```
adb shell
su
```

At this time, the command line prompt is $, which means that there is no root authority, and # means that it is rooted.

### 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
```

It means to send 500 pseudo-random events to the application specified by `<packagename>`.

For detailed usage of Monkey, refer to the official documentation.

### Turn on/off WiFi


Note: root permission is required.

Sometimes you need to control the WiFi status of the device, you can use the following commands to complete.

Turn on WiFi:

```
adb root
adb shell svc wifi enable
```

Turn off WiFi:

```
adb root
adb shell svc wifi disable
```

Set wifi priority, use wifi first when there is network and wifi

```java
adb shell svc wifi prefer
```


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

### Turn on/off data traffic

```java
svc data disable
```

This command can close the data connection, that is, the Internet traffic. Everyone knows that there are many switches to control the Internet, but most of them are realized by adding a suffix to the access point on the apn, but this command will not change any settings of the apn. The bottom layer closes the data connection. It should be the most thorough, and does not affect the apn settings. What is the difference between this and apndroid? When apndroid closes the Internet data, the downloading connection may not be forcibly closed (this is also mentioned in apndroid's own instructions). For example, if you are downloading a 10M movie, if you download 1M, the download will not sound. Use apndroid to close the connection, maybe the download will continue, not immediately. But with this command, it clicked away without mercy.

```java
adb shell svc data enable
```

This is to open the Internet data connection, which is the opposite of the previous command.

```java
adb shell svc data prefer
```

 This command is to control the data connection prior to wifi. We all know that under normal circumstances, when there is wifi, the data network connection will not be used. But this command is the opposite. If there is a data network, use data network traffic first, and use wifi when there is no data network.


## Flashing related commands


### 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:

Restart to Recovery mode.

command:

```
adb reboot recovery
```

Operate on the Recovery interface of the device to enter Apply update-Apply from ADB.

*Note: Different Recovery menus may be different from this. Some first-level menus have Apply update from ADB. *

**Upload and update the system via adb. **

command:

```
adb sideload <path-to-update.zip>
```

### More adb shell commands


The Android system is based on the Linux kernel, so many commands in Linux have the same or similar implementations in Android and can be called in adb shell. The adb shell command has been used in the previous part of this document.

### View process


```
adb shell ps
```

example:

```
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:classic
u0_a58 7963 5926 1561916 59568 ffffffff 00000000 S org.mazhuang.boottimemeasure
...
shell 8750 217 10640 740 00000000 b6f28340 R ps
```

Meaning of each column:

<table>
<thead>
<tr>
<th>Column name</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>USER</td>
<td>Owned user</td>
</tr>
<tr>
<td>PID</td>
<td>Process ID</td>
</tr>
<tr>
<td>PPID</td>
<td>Parent process ID</td>
</tr>
<tr>
<td>NAME</td>
<td>Process name</td>
</tr></tbody></table>


### View real-time resource usage


```
adb shell top
```

example:

```
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
 ...
```

Meaning of each column:

<table>
<thead>
<tr>
<th>Column name</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>PID</td>
<td>Process ID</td>
</tr>
<tr>
<td>PR</td>
<td>Priority</td>
</tr>
<tr>
<td>CPU%</td>
<td>The percentage of CPU occupied at the current instant</td>
</tr>
<tr>
<td>S</td>
<td>Process status (R=run, S=sleep, T=track/stop, Z=zombie process)</td>
</tr>
<tr>
<td>#THR</td>
<td>Number of threads</td>
</tr>
<tr>
<td>VSS</td>
<td>Virtual Set Size virtual memory consumption (including memory occupied by shared libraries)</td>
</tr>
<tr>
<td>RSS</td>
<td>Resident Set Size actually uses physical memory (including memory occupied by shared libraries)</td>
</tr>
<tr>
<td>PCY</td>
<td>Scheduling strategy priority, SP_BACKGROUND/SPFOREGROUND</td>
</tr>
<tr>
<td>UID</td>
<td>User ID of the process owner</td>
</tr>
<tr>
<td>NAME</td>
<td>Process name</td>
</tr></tbody></table>


The top 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] [-h]
    -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:

```
adb shell dumpsys package <packagename> | grep userId=
```

Such as:

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

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.guanggoo
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:

<table>
<thead>
<tr>
<th>Command</th>
<th>Features</th>
</tr>
</thead>
<tbody>
<tr>
<td>cat</td>
<td>Display file content</td>
</tr>
<tr>
<td>cd</td>
<td>Change directory</td>
</tr>
<tr>
<td>chmod</td>
<td>Change file access mode/access permissions</td>
</tr>
<tr>
<td>df</td>
<td>Check disk space usage</td>
</tr>
<tr>
<td>grep</td>
<td>Filter output</td>
</tr>
<tr>
<td>kill</td>
<td>Kill the process of the specified PID</td>
</tr>
<tr>
<td>ls</td>
<td>List the contents of the directory</td>
</tr>
<tr>
<td>mount</td>
<td>View and manage mount directories</td>
</tr>
<tr>
<td>mv</td>
<td>Move or rename files</td>
</tr>
<tr>
<td>ps</td>
<td>View the running process</td>
</tr>
<tr>
<td>rm</td>
<td>Delete files</td>
</tr>
<tr>
<td>top</td>
<td>Check the resource usage of the process</td>
</tr></tbody></table>


## Security related

### Enable SELinux

Enable SELinux

```java
adb root
adb shell setenforce 1
```

### Disable SELinux

```java
adb root
adb shell setenforce 0
```

### Enable dm_verity

```java
adb root
adb enable-verity
```

### Disable dm_verity

```java
adb root
adb disable-verity
```

## common problem


### Failed to start adb server


Error message

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

possible reason

The 5037 port 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.