Android adb details (called by adb when multiple devices exist)

Source: Internet
Author: User
Tags unix domain socket

(). I have read a total of 0 comments for 36 times.
 
10:29:15

When you want to use logcat to view the status of one of multiple devices (simulators), or directly install an application on the target device, you must specify the device number.
Adb devices
This command can obtain the serial number of the current device (serialNumber ).
For example, a simulator is usually emulator-5554
Add the parameter-s <serialNumber> such as-s emulator-5554 after the adb command.
You can specify the adb Command target.
It is useful when multiple simulators or devices exist.
Original article link
Http://www.iteye.com/topic/260042
Android debugging Bridge
Http://www.androidin.com/docs/reference/adb.html#sqlite
Android debugging bridge (adb) is a versatile tool that helps you manage the status of devices or simulators.
You can add adb using the following methods:
Run shell commands on the device
Manage simulators or devices through port forwarding
Copy files from simulators or devices
The following describes the common use of adb.
Contents
Summary
Issue adb command
Query Simulators/device instances
Send commands to specific Simulators/device instances
Install software
Forwarding Port
Import or copy files from Simulators/devices
Adb command list
Start shell commands
Connect to the database by running sqllite3 on a remote shell Client
UI/Software Test Procedure Monkey
Other shell commands
Enable logcat logs
Use the logcat command
Filter log output
Control log output format
View available log Buffers
View stdout and stderr
Logcat command list
Stop adb Service
Summary
The Android debugging system is a customer service system that consists of three components:
A client that runs on the computer you use to develop programs. You can use the adb command on the shell to start the client. Other Android tools such as ADT plug-in and DDMS can also generate adb clients.
The server that runs as the background process on the machine you use for sending. The server is responsible for managing the communication between the client and the adb daemon running on the simulator or device ..
A daemon that runs on a simulator or device in the form of a subsequent process )..
When you start an adb client, the client first checks whether an adb service process is running. If not, start the service process. When the server runs, the adb server binds the local TCP port 5037 and listens for commands sent from the adb client.-All the adb clients use port 5037 to communicate with the adb server.
Then the server establishes a connection to all running simulators or device instances. It locates all simulators or devices by scanning all the odd ports in the range of 5555 to 5585. Once the server finds the adb daemon, it establishes a connection to the port. Note that any simulator or device instance will obtain two consecutive ports-an even port is used to connect to the corresponding console, and an odd port is used to respond to the adb connection. For example:
Simulator 1. Console: port 5554
Simulator 1 and Adb port 5555
Console: port 5556
Adb port 5557...
As shown above, the simulator instance connects to adb through port 5555, just like connecting to the console using port 5554.
Once the server establishes a connection with all simulator instances, you can use the adb command to control and access the instance. Because the server manages connections to simulators/device instances, and controls the processing of commands from multiple adb clients, you can control any simulator or device instance through any client (or script.
The following sections describe how to use adb through commands and manage the status of simulators/devices. Note that if you use Eclipse with the ADT plug-in to develop Android programs, you do not need to use adb through the command line. The ADT plug-in has transparently integrated adb into Eclipse. Of course, if necessary, you can still directly use adb, such as debugging.
Issue adb command
Android command: You can publish the Android command on the command line or script on your development machine. The usage is as follows:
Adb [-d |-e |-s <serialNumber>] <command>
When you issue a command, the system enables the Android client. The client is not related to the simulator instance, so if the dual server/device is running, you need to use the-d option to determine the target instance for the command to be controlled. For more information about using this option, you can view the terms control commands of the simulator/device instance.
Query Simulators/device instances
Before releasing the adb command, it is necessary to know what kind of simulator/device instance is connected to the adb server. You can use the devices command to obtain a series of associated Simulators/devices:
Adb devices
• In response, adb provides the following status information for each instance:
• Serial number-a string created by adb that uniquely identifies a simulator/device instance through its own control port <type>-<consolePort>. The following is an example of serial number: emulator-5554
There are three instance connection statuses:
Offline-this instance is not connected to adb or cannot respond.
Device-this instance is connected to the adb server. Note that this status does not indicate that the system is running and operating the Android system. Therefore, this instance is connected to adb when the system is running. However, after the system is started, it is a normal running status of the simulator/device.
The output format of each instance is fixed as follows:
[SerialNumber] [state]
The following is an example of the devices command and output:
$ Adb devices
List of devices attached
Emulator-5554 device
Emulator-5556 device
Emulator-5558 device
If no simulator/device is running, adb returns no
Device.
Send commands to specific Simulators/device instances
If multiple Simulators/device instances are running, you must specify a target instance when releasing the adb command. To do this, use the-s option command. The-s option used is
Adb-s <serialNumber> <command>
As shown above, the target instance is specified for a command, which uses the serial number allocated by adb. You can use the devices command to obtain the serial number of the running simulator/device instance.
Example:
Adb-s emulator-5556 install helloWorld.apk
Note that if you run the-s command without specifying a Target Simulator/device instance, adb will generate an error.
Install software
You can use adb to copy an application from your development computer and install it on a simulator/device instance. Run the install command. This install Command requires you to specify the path of the. APK file you want to install:
Adb install <path_to_apk>
For more information about how to create a .apk file that can be installed on the simulator/device, see Android Asset Packaging Tool (aapt ).
Note that if you are using Eclipse IDE and have installed the ADT plug-in, you do not need to directly use adb (or aapt) to install the application on the simulator/device. Otherwise, the ADT plug-in handles application packaging and installation on your behalf.
Forwarding Port
You can use the forward Command to forward any port-a request from a specific host port of a simulator/device instance to another port. The following demonstrates how to establish forwarding from host port 6100 to simulator/device port 7100.
Adb forward tcp: 6100 tcp: 7100
Similarly, you can use adb to create an abstract UNIX domain interface. The process is as follows:
Adb forward tcp: 6100 local: logd
Import or copy files from Simulators/devices
You can use the adbpull and push commands to copy files to or from a data file of a simulator/device instance. The install command only copies a .apk file to a specific location. Different from the command, the pull and push commands allow you to copy arbitrary directories and files to any location of a simulator/device instance.
Copy a file or directory from a simulator or device and use the following command ):
Adb pull <remote> <local>
Copy the file or directory to the simulator or device and run the following command)
Adb push <local> <remote>
In these commands, <local> and <remote> indicate the path to the target file/directory on the development machine (local) and simulator/device instance (remote) respectively.
The following is an example ::
Adb push foo.txt/sdcard/foo.txt
Adb command list
The following table lists all commands supported by adb and describes their meanings and usage.
Category Command Description Comments
Options-d manage abd only through the USB interface. If it is not just managed using the USB interface, an error is returned.
-E only manages adb through the simulator instance. If it is not just through the simulator instance management, an error is returned.
-S <serialNumber> uses the allowed command numbers of the simulator/device to send commands to manage adb (for example, "emulator-5556"). If no number is specified, an error is returned.
General devices: view the list of all devices connected to simulators/devices. View Querying for Emulator/Device Instances for more information.
Help to view all commands supported by adb ..
View the version serial number of adb.
Debug logcat [<option>] [<filter-specs>] outputs log data to the screen.
Bugreport: view the bug reports, such as dumpsys, dumpstate, and logcat information.
Jdwp allows you to view available JDWP information of a specified facility. You can use forward jdwp: <pid> port ing information to connect to the specified JDWP process. For example:
Adb forward tcp: 8000 jdwp: 472
Jdb-attach
Localhost: 8000
Data install <path-to-apk> to install Android (the complete path can be specified for the Data file .apk of the simulator/simulator ).
Pull <remote> <local> copies the specified file from the simulator/facility to the computer.
Push <local> <remote> copies the specified file from the computer to the simulator/device.
Ports and Networking forward <local> <remote> use the locally specified port to remotely connect to the simulator/facility port through the socket method. The following information must be described:
Tcp: <portnum>
Local: <UNIX domain socket name>
Dev: <character device name>
Jdwp: <pid>
Ppp <tty> [parm]... run ppp through USB:
<Tty>-the tty for PPP stream. For example dev:/dev/omap_csmi_ttyl.
[Parm]... & mdash zero or more PPP/PPPD options, such as defaultroute, local, notty, etc.
You must be reminded that you cannot automatically start the PDP connection.
Scripting get-serialno: view the serial number of the adb instance. View Querying for Emulator/Device Instances for more information.
Get-state: view the current status of the simulator/facility.
Wait-for-device will not be executed if the device is offline, that is, when the instance status is device. you can reprint the commands in the adb CLI in advance. The commands in the CLI won't execute other commands before the simulator/device is connected. example:
Adb wait-for-device shell getprop
Note that these commands do not start adb before all systems start up. Therefore, you cannot execute other commands before all systems start up. for example, Android packages are required when install is used. These packages are only fully started by the system. For example:
Adb wait-for-device install <app>. apk
The preceding command is executed only when the simulator/device is connected to the adb service, and an error occurs before the Android system is fully started.
Server start-server: Select whether the service starts the adb service process.
Kill-server terminates the adb service process.
Shell shell uses remote shell commands to Control Simulators/device instances. view more information for more information.
Shell [<shellCommand>] connects to the simulator/facility to execute shell commands. After the command is executed, exit the remote shell terminal l.
Start shell commands
Adb provides the shell end, through which you can run various commands on the simulator or device. These commands are saved in binary format in the file system of the local simulator or device:
/System/bin /...
Whether or not you are fully connected to the adb remote shell of the simulator/device, you can run shell commands to execute commands.
When the remote shell is not fully accessed, run the following shell command:
Adb [-d |-e |-s {<serialNumber >}] shell <shellCommand>
If you do not need a remote shell in the simulator/device, use shell as follows:
Adb [-d |-e |-s {<serialNumber >}] shell
You can exit shell remote connection by pressing CTRL + D or exit.
The following sections will show you more about shell commands.
Connect to the database by running sqllite3 on a remote shell Client
Through the remote shell end of adb, you can use the Android soft sqlite3 command program to manage the database. The sqlite3 tool contains many commands, such as. dump, which displays the table content. schema can display the SQL CREATE result set of an existing tablespace. Sqlite3 also allows you to remotely execute SQL commands.
Use sqlite3 to log on to the remote shell of the simulator according to the methods in the previous sections, and then start the tool to use the sqlite3 command. After sqlite3 is started, you can specify the full path of the database you want to view. The simulator/device instance stores the SQLite3 database in the folder./data/<package_name>
/Databases
/.
Example:
$ Adb-s emulator-5554 shell
# Sqlite3/data/com. example. google. rss. rssexample/databases/rssitems. db
SQLite version 3.3.12
Enter ". help" for instructions
... Enter commands, then quit...
Sqlite>. exit
When you start sqlite3, you can use the shell terminal to send the sqlite3 command. Use exit or CTRL + D to exit the remote shell of adb.
UI/Software Test Procedure Monkey
When a Monkey program is running on a simulator or device, if the user starts a system-level event, such as a click, touch, gesture, or system-level event, it generates a random pulse, therefore, you can use Monkey to load and test your software with random repetition.
The simplest method is to use the following command to use Monkey. This command will start your software and trigger 500 events.
$ Adb shell monkey-v-p your. package. name 500
For more information about the Monkey command, see UI/Application Exerciser Monkey documentation page.
Document page
Other shell commands
The following table lists some adbshell commands. If you need all the commands and programs, you can start the simulator instance and use the adb-help command.
Adb shell ls/system/bin
For most departments, help is available.
Shell Command Description Comments
Dumpsys clears the system data in the screen. The n. Dalvik Debug Monitor Service (DDMS) tool provides complete debugging ,.
Dumpstate clears the state of a file.
Logcat [<option>]... [<filter-spec>]... start the information log and output it to the screen.
Dmesg outputs the main debugging information to the screen.
Start to start or restart a simulator/device instance.
Stop disables a simulator/device instance.
Enable logcat logs
The Android logging system allows you to record and view system debugging information. Logs are recorded in various software and system buffers. You can use the logcat command to view and use logs in the buffer zone.
Use the logcat command
You can use the logcat command to view the content of the System Log Buffer:
[Adb] logcat [<option>]... [<filter-spec>]...
Please refer to the Listing of logcat Command Options, which provides a detailed description of the logcat Command.
You can also use the logcat command on your computer or remote adb shell Running on the simulator/device, or view the log output on your computer.
$ Adb logcat
You can also use the following method:
# Logcat
Filter log output
Each Android log output has a tag and its priority.
The log tag is a brief identifier of the original information of the system component. (For example, "View" is to View the system tag ).
The priority has the following sets, 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)
When running logcat, you can see the logcat label list and priority in the first two columns. It is marked as <priority>/<tag>.
The following is an example of logcat output. Its priority is I, and the label is ActivityManage:
I/ActivityManager (585): Starting activity: Intent {action = android. intent. action ...}
To enable log output to reflect the management level, you can also use filters to control log output. Filters can help you describe the system's tag level.
The filter statement depicts the tag in the following format: priority ..., tag indicates a tag, and priority indicates the lowest level of a tag report. the log priority can be obtained from the above tag. you can write the tag: priority multiple times in the filter.
All of these instructions end with a blank space. The following example shows a column that supports all log information, except for those with "ActivityManager" and "Info" or above, and those with "MyApp" and "Debug" or higher priorities. Level. The priority report is tag.
Adb logcat ActivityManager: I MyApp: D *: S
The final element *: S of the above expression sets all labels as "silent". All logs only show "View" and "MyApp". Use *: another use of S is to ensure that the log output is restricted according to the description of the filter, and make the filter output to the log as an item.
The following filter statement shows the log information with a priority of warning or higher:
Adb logcat *: W
If you run logcat on your computer, you can also set the default filter for the environment variable ANDROID_LOG_TAGS:
Export ANDROID_LOG_TAGS = "ActivityManager: I MyApp: D *: S"
It should be noted that if the ANDROID_LOG_TAGS filter runs logcat through a remote shell or runs the simulator/device using adb shell logcat, logs cannot be output.
Control log output format
Log information includes many metadata fields, including tags and priorities. You can modify the log output format to display a specific metadata domain. You can use the-v option to obtain information about formatted output logs.
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 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 use the-v option to specify the output format:
[Adb] logcat [-v <format>]
The following is the log format generated by Using thread:
Adb logcat-v thread
Note that you can specify the output format option only with the-v option.
View available log Buffers
The Android log system has a circular buffer, and not all log systems have a default circular buffer. To obtain the log information, you must use the-B Option to start logcat. To use the cyclic buffer, you need to check the remaining cyclic buffer period:
Radio-view information about the buffer.
Events-view the Event-related buffer.
Main-view the main log Buffer
-How to Use Option B:
[Adb] logcat [-B <buffer>]
The following example shows how to view the log buffer that contains radio and telephony information:
Adb logcat-B radio
View stdout and stderr
By default, the Android System includes stdout and stderr (System. out and System. err) output to/dev/null. In the process of running Dalvik VM, a system can back up log files. In this case, the system uses stdout, stderr, and priority I. To record log information.
In this way, specify the output path, stop the running simulator/device, and then remotely enter the log by using the setprop command.
$ Adb shell stop
$ Adb shell setprop log. redirect-stdio true
$ Adb shell start
The system will keep the settings until you disable the simulator/device. You can add/data/local. prop to use the default settings on the simulator/device.
Logcat command list
Option Description
-B <buffer> loads an available log buffer for viewing, such as event and radio. The default value is main. For details, see Viewing Alternative Log Buffers.
-C: Clear the logs on the screen.
-D. output the log to the screen.
-F <filename> specifies the <filename> of the output log information. The default value is stdout.
-G outputs the specified log buffer and exits after the output.
-N <count> set the maximum number of logs <count>. The default value is 4, which must be used with the-r option.
-R <kbytes> outputs logs per <kbytes>. The default value is 16 and must be used with the-f option.
-S sets the default filtering level to silent.
-V <format> sets the Log input Format. The default format is brief. For more supported formats, see Controlling Log Output Format.
Stopping the adb Server
In some cases, you may need to terminate the Android debugging system and restart it. For example, if the Android debugging system does not respond to a command, you can terminate the server and restart it. This may solve this problem.
You can use kill-server to terminate the adb server. You can use any commands issued by adb to restart the server.

Related Article

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.