ADB common commands

Source: Internet
Author: User
Tags root access

ADB (Android Debug Bridge)
Description: Some of the following commands require root permission to perform successfully
Quick Launch DOS window execution adb:
1. Add the Adb.exe path to the system environment variable
2. Configure shortcut keys to start DOS
Enter the C:\WINDOWS\system32 directory and locate the Cmd.exe.
Right-click the menu "Send To" desktop shortcut.
On the desktop, right-click Shortcut to Cmd.exe, properties, shortcut page
---cursor highlighting shortcut keys, pressing custom shortcut keys (e.g. Ctrl + Alt + Z)

In any case, press CTRL + ALT + Z to start the DOS window to execute the ADB command.


-----------View the Device Connection status series-----------
ADB Get-serialno gets the ID and serial number of the device serialnumber
ADB devices queries the current computer for connecting those devices (including simulators and phones), output format: [serialnumber] [state]
ADB get-state View the current status of the simulator/facility.

Description
Serial number [serialnumber]--a string created by ADB, this string through its own control port <type>-<consolePort>
Uniquely identifies an emulator/device instance. Example of a serial number: emulator-5554

-----------Send commands to the device family-----------
adb [-d|-e|-s <serialnumber>] <command>
-d Send command to USB connected device
-e Send command to emulator device
-S <serialNumber> send command to specified device

If you start your mobile device shell:adb-d shell

ADB forward <local> <remote> publish port, you can set any port number,
As a request port for the host to the emulator or device. such as: adb forward tcp:5555 tcp:8000

ADB reboot Restart your phone
ADB remount to re-mount the system partition as a read-write partition
ADB kill-server terminates ADB service process
ADB start-server restart ADB service process
ADB root has root access to restart ADB service
ADB wait-for-device commands are reproduced in the ADB command before the simulator/device is connected
ADB jdwp View the available jdwp information for the specified facility.
You can use the forward jdwp:<pid> port mapping information to connect to the specified JDWP process. For example:
ADB forward tcp:8000 jdwp:472
Jdb-attach localhost:8000

ADB shell am command to start the application

adb shell input text <string> input text to device (the text box where the cursor is located)
ADB shell input keyevent <event_code> send key event to device
Such as:
When you are editing a text message, enter it into the text box: adb shell input text "Hello"
Send key value back to phone home:adb shell input keyevent 3
Event_code keycode_* in reference View/keyevent.java
public static final int keycode_soft_left = 1;
public static final int keycode_soft_right = 2;
public static final int keycode_home = 3;
public static final int keycode_back = 4;
public static final int keycode_call = 5;
public static final int keycode_endcall = 6;

-----------Safety loading and unloading series-----------
ADB install [-l] [-r] <file>-push This package file to the device and install it
('-l ' means forward-lock the app)
('-R ' means reinstall the app, keeping its data)
adb uninstall [-K] <package>-remove this app from the device
('-K ' means keep the data and cache directories)
Such as:
ADB install d:\hello.apk
ADB Unstall Com.huawei.hello
NOTE: If you reinstall the APK with the-r option, install it in the/data/local/tmp/directory and use the original APK after the phone restarts.

-----------File Operation series-----------
ADB push <local> <remote>-copy File/dir to device
ADB pull <remote> <local>-copy file/dir from device

-----------Basic Linux shell command series-----------
ADB Shell [command]
LS lists the files and folders under the directory
CD Switch Directory
RM Delete directories and files
Cat View File Contents
PS can see that process and then run
Ps-x [PID] View the status of a single process
Top can see the highest occupancy rate for that process.
Su switches to the root user
Kill [PID] kills a process
chmod 777 <file> Modify this file as executable permission

Detailed usage you can log in to a Linux server under the shell to view the Help manual, man <command>

-----------View system Status and Information series-----------
ADB shell Procrank queries the memory usage of each process
ADB Shell Service List View services information
ADB shell Cat/proc/meminfo View current memory conditions
ADB shell Cat/proc/cpuinfo View CPU information (hardware)
adb shell cat/proc/iomem view IO memory partition

ADB shell Getprop Lists all system Properties
ADB Shell Getprop | Findstr "GSM" lists the properties that contain GSM
adb shell SetProp <key> <value> Modify System Properties

ADB shell sqlite3 can execute SQL statements to view database information, specific usage to be investigated

-----------Log Series-----------
ADB logcat [<filter-spec>]-View device log

1~~~~~~~~~~~ View the available log buffers:
ADB logcat-b radio-To view information about the buffer.
ADB logcat-b events-View the buffer associated with the event.
ADB logcat-b main-View the primary log buffer

2~~~~~~~~~~~ Filter Log output:
The filter statement is described in the following format tag:priority ..., tag is the label, priority is the lowest level of the report that represents the label
ADB logcat *:w display log information with priority warning or higher
ADB logcat activitymanager:i Myapp:d *:s

The label of the log is a brief indication of the original information of the system part. (For example, "View" is to view the system's label).
Priority has the following concentrations, which are arranged smoothly from low to High:
V-verbose (Lowest priority)
D-debug
I-info
W-warning
E-error
F-fatal
S-silent (highest priority, on which nothing is ever printed)

If you run Logcat on your computer, you can also android_log_tags for environment variables: Enter a parameter to set the default filter, compared to the remote Adbshell side.
Export android_log_tags= "activitymanager:i Myapp:d *:s "
It is important to note that the Android_log_tags filter cannot output the log if it runs logcat through the remote shell or runs the emulator/device with the ADB shell logcat.

3~~~~~~~~~~~ control Log Output format:
The log information includes many metadata fields including labels and precedence. You can modify the output format of the log so that a specific metadata field can be displayed. Information about the formatted output log can be obtained through the-v option.

Brief-display Priority/tag and PID of originating process (the default format).
Process-display PID only.
Tag-display the Priority/tag only.
Thread-display Process:thread and Priority/tag only.
Raw-display the raw log message with and no other metadata fields.
Time-display the date, invocation time, Priority/tag, and PID of the originating process.
Long-display all metadata fields and separate messages with a blank lines.
When Logcat is started, you can specify the output format with the-V option:

[ADB] logcat [-v <format>]
Here is the log format generated with thread:

ADB logcat-v Thread
Note that you only have the-V option to specify the output format options.

4~~~~~~~~~~~logcat Command List
-B <buffer> Loads a log buffer that can be used for viewing, such as event and radio. The default value is main. See Viewing alternative Log buffers specifically.
-C Clear the Log on the screen.
-D output logs to the screen.
-F <filename> Specifies the <filename> of the output log information, which is stdout by default.
-g outputs the specified log buffer and exits after output.
-N <count> sets the maximum number of logs <count>., the default value is 4 and needs to be used with the-r option.
-R <kbytes> output log per <kbytes>, default value is 16 and needs to be used with the-f option.
-S sets the default filter level to silent.
-V <format> Set the log input format, default is brief format, to know more supported formats, see Controlling log Output format


ADB Bugreport-return all information from the device
That should is included in a bug report.

ADB shell DMESG query kernel buffer information
ADB shell dumpstate Various kinds of information, such as process information, memory information, process is abnormal, kernnel log, etc.
ADB Shell Dumpcrash
ADB shell Dumpsys Querying the status of all service


-----------Other-----------

Emulator using Mirrored SDcard
Use the Mksdcard tool in the SDK to create a FAT32 disk image and load it when the emulator starts. This creates the image:? Mksdcard <size> <file>
For example I want to create a 64M SD card simulation file, the file path is in D:\workspace\sdcard.img
Mksdcard 64000000 D:\workspace\sdcard.img

Emulator–sdcard D:\workspace\sdcard.img
or configure the startup parameters in the Open Run Dialog dialog box in the Run menu of Eclipse.

#top
Usage:top [-M Max_procs] [-N iterations] [-D delay] [-s sort_column] [-t] [-h]
-M num Maximum number of processes to display.
-N num Updates to show before exiting.
-D num Seconds to wait between updates.
-S Col Column to sort by (CPU,VSS,RSS,THR).
-T Show threads instead of processes.
-H Display this help screen.

Simple selection ********* ********* selection by list *********
-A All processes-c by command name
-N negate selection-g by real Group ID (supports names)
-a all w/tty except session leaders-u by real user ID (supports names)
-D all except session leaders-g by session OR by effective group name
-e all processes-p by Process ID
T All processes-terminal-s processes in the sessions given
A all w/tty, including and users-t by TTY
G OBSOLETE--do not use-u by effective user ID (supports names)
R only running processes U processes for specified users
X processes w/o controlling TTYs t by TTY
Output format ********** *********** long Options ***********
-o,o user-defined-f full--group--user--pid--cols--ppid
-j,j job Control s signal--group--user--sid--rows--info
-o,o preloaded-o v virtual memory--cumulative--format--deselect
-l,l long u user-oriented--sort--tty--forest--version
-F Extra Full X registers--heading--no-heading--context
Misc Options *********
-v,v Show version L list format codes F ASCII Art Forest
-m,m,-l,-t,h threads S Children in sum-y change-l format
-m,z Security Data C True command Name-c scheduling class
-w,w wide output n numeric wchan,uid-h process hierarchy


Netstat-ano Viewing network connection Status
Displays protocol statistics and current TCP/IP network connections.

NETSTAT [-A] [-b] [-e] [-n] [-O] [-P proto] [-r] [-S] [-v] [interval]

-a displays all connections and listening ports.
The-b display is included in creating each connection or listening port
The executable component. In some cases, the executable component is known
has multiple independent components, and in these cases
A sequence of components that are included in creating a connection or listening port
are displayed. In this case, the name of the executable component
At the bottom of [], the top is the component that it calls,
Wait until the TCP/IP section. Note this option
May take a long time if you don't have sufficient permissions
May fail.
-e Displays Ethernet statistics. This option can be used with the-s
Combination of options.
-N Displays the address and port number in digital form.
-O Displays the owning process ID associated with each connection.
-p proto shows the connection proto the specified protocol; proto can be
One of the following protocols: TCP, UDP, TCPv6, or UDPV6.
If used with the-s option to display per-protocol statistics, Proto can be one of the following protocols:
IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPV6.
-r Displays the routing table.
-S displays statistical information by protocol. By default, the display IP,
IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPV6 statistics;
The-p option specifies a subset of the default conditions.
-V is used with the-B option to display the containing
To create a connection or listen port for all executable components
Component.
Interval Displays the selected statistics, between each display
Pause interval (in seconds). Press CTRL + C to stop re-
Displays statistics. If omitted, Netstat displays the current
Configuration information (show only once)


Pm
USAGE:PM [List|path|install|uninstall]
PM list packages [-f]
PM List permission-groups
PM List permissions [-G] [-f] [-d] [-u] [GROUP]
PM list instrumentation [-f] [Target-package]
PM List Features
PM Path Package
PM install [-l] [-r] [-T] [-I installer_package_name] PATH
PM Uninstall [-K] Package
PM Enable Package_or_component
PM Disable Package_or_component

The list Packages command prints all packages. Options:
-f:see their associated file.

The list permission-groups command prints all known
Permission groups.

The list Permissions command prints all known
permissions, optionally only those in GROUP. Options:
-g:organize by group.
-f:print all information.
-s:short Summary.
-d:only List dangerous permissions.
-u:list only the permissions users would see.

The list Instrumentation command prints all instrumentations,
Or only those this target a specified package. Options:
-f:see their associated file.

The list features command prints all features of the system.

The path command prints the path to the. apk in a package.

The install command installs a package to the system. Options:
-l:install the package with Forward_lock.
-r:reinstall an exisiting app, keeping it data.
-t:allow test. APKs to be installed.
-i:specify the installer package name.

The uninstall command removes a package from the system. Options:
-k:keep the data and cache directories around.
After the package removal.

The Enable and disable commands change the enabled state of
A given package or component (written as "Package/class").


View stdout and stderr
By default, the Android system has stdout and stderr (System.out and System.err) output to/dev/null,
In the process of running the Dalvik VM, there is one system that can back up the log files. In this case, the system uses stdout and stderr and the priority I to record the log information.

This method specifies the path to the output, stops the emulator/device running, and then remotely enters the log by using the SetProp command

$ adb shell stop
$ adb shell SetProp Log.redirect-stdio true
$ adb shell start system until you close the simulator/device before the settings are retained, you can use the default settings on the emulator/device by adding/data/local.prop

ui/Software test program Monkey
When the monkey program is running in a simulator or device, if the user departs for example, click, Touch, gesture or some system-level event,
It generates random pulses, so you can use monkey to load test your software with a random, repetitive approach.
The simplest way is to use monkey with the following command, which will launch your software and trigger 500 events.

$ adb shell monkey-v-P Your.package.name 500
For more information about command Monkey commands, you can view ui/application exerciser Monkey documentation page.

ADB common commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.