basis

Adb version Indicates the ADB versionhelpHelp ADB start-server start ADB ADBkill-server Stops the ADB serverCopy the code

I. Equipment control

-dSpecify the only Android device currently connected through USB as the target of the command-eSpecifies the only currently running emulator as the command target-s<serialNumber> specifies the device/emulator corresponding to serialNumber as the command target ADB Devices display device ADB reboot Restarts ADB-sSelect the device for example: ADB-sEmulator-5556 reboot Restarts emulator-5556Copy the code

Two. Installation and uninstallation

adb install  path_to_apk
adb uninstall packageName
Copy the code

Copy files to devices

adb pull remote local
adb push local remote

Copy the code

In the above commands, local and remote refer to the path to the target file/directory on the development machine (local) and the emulator/device instance (remote). Such as:

adb push foo.txt /sdcard/foo.txt
Copy the code

Shell Launches the remote Shell in the target emulator/device instance

Issue device commands without entering adb remote shell on emulator/device instance:

adb [-d|-e|-s serial_number] shell shell_command
Copy the code

Enter the remote shell on the emulator/device instance:

adb [-d|-e|-s serial_number] shell
Copy the code

When you are ready to exit the remote shell, press Control + D or type Exit.

The shell command binaries are stored in the emulator or device file system in the path of /system/bin/

4.1 Obtaining Device Information

adb shell getprop
Copy the code

4.2 the Window manager

adb shell wm
Copy the code

help


Window manager (window) commands:
  help
      Print this help text.
  size [reset|WxH|WdpxHdp]
    Return or override display size.
    width and height in pixels unless suffixed with 'dp'.
  density [reset|DENSITY]
    Return or override display density.
  overscan [reset|LEFT,TOP,RIGHT,BOTTOM]
    Set overscan area for display.
  scaling [off|auto]
    Set display scaling mode.
  dismiss-keyguard


Copy the code

case

Adb shell wm size Physical size: 1080x2160Copy the code

4.3 am the Activity Manager

In the ADB shell, you can use the Activity Manager (AM) tool to issue commands to perform various system operations, such as starting an Activity, forcibly stopping a process, broadcasting intents, modifying device screen properties, and more

4.3.1 Common Commands:
Start ADB shell am start -n Package name/Activity name (full path) Close ADB shell am force-stop package name Example: Open the browser. Adb Shell first and then am start-a android.intent.action.VIEW -d  http://www.google.cn/

Copy the code
4.3.2 start Starts the Activity specified in the intent
Start [options] Intent Starts the Activity specified in the intent. See the specification for intent parameters. The options are as follows: -d: enables debugging. -w: Waits until the startup is complete. --start-profiler file: Starts the profiler and sends the results to the file. -p file: Similar to --start-profiler, but analysis stops when the application enters idle state. -r count: indicates the count times for restarting the Activity. The top Activity completes before each repeat. -s: forcibly stops the target application before starting the Activity. --opengl-trace: enables tracing of opengL functions. - user user_id | current: specify to which the user to run as a; If not specified, it is run as the current user.Copy the code
4.3.3 startService Starts the Service specified by the intent
startservice [options] intent
Copy the code
4.3.4 other
Broadcast [options] Intent Intent force-stop Package Forcibly stops all applications associated with the packagekill[options] package Terminates all processes associated with package (the application's package name). This command terminates only processes that can be safely terminated without affecting user experiencekill-all Disables the use of all background processes clear-debug-appset-debug-app Clears software packages previously configured for debugging... .Copy the code
4.3.5 Specification of Intent parameters
For an Activity Manager command that takes an intent parameter, you can specify the intent with the following options:-aAction specified intent action, such as "android. Intent. Action. VIEW". This specification can only be declared once.-dData_uri specify intent data URI, such as "content: / / contacts/people / 1". This specification can only be declared once. -t mime_type Specifies the intent MIME type, such as image/ PNG. This specification can only be declared once. - c category specified intent category, such as "android. Intent. Category. APP_CONTACTS". - n component with a specified package name prefix component name to create explicit intent, such as "com. Example. The app /. ExampleActivity".-fFlags Adds flags tosetFlags() Supports the intent.Copy the code

4.4 PM Invoking the package manager

See the help

shell@JDtab:/ $ pm
usage: pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [--user USER_ID] [FILTER]
       pm list permission-groups
       pm list permissions [-g] [-f] [-d] [-u] [GROUP]
       pm list instrumentation [-f] [TARGET-PACKAGE] pm list features pm list libraries pm list users pm path PACKAGE pm dump PACKAGE pm install [-lrtsfd]  [-i PACKAGE] [--user USER_ID] [PATH] pm install-create [-lrtsfdp] [-i PACKAGE] [-S BYTES] [--install-location 0/1/2] [--force-uuid internal|UUID] pm install-write [-S BYTES] SESSION_ID SPLIT_NAME [PATH] pm install-commit SESSION_ID pm install-abandon SESSION_ID pm uninstall [-k] [--user USER_ID] PACKAGE pmset-installer PACKAGE INSTALLER
       pm move-package PACKAGE [internal|UUID]
       pm move-primary-storage [internal|UUID]
       pm clear [--user USER_ID] PACKAGE
       pm enable [--user USER_ID] PACKAGE_OR_COMPONENT
       pm disable [--user USER_ID] PACKAGE_OR_COMPONENT
       pm disable-user [--user USER_ID] PACKAGE_OR_COMPONENT
       pm disable-until-used [--user USER_ID] PACKAGE_OR_COMPONENT pm hide [--user USER_ID] PACKAGE_OR_COMPONENT pm unhide [--user USER_ID] PACKAGE_OR_COMPONENT pm grant [--user USER_ID] PACKAGE PERMISSION pm revoke [--user USER_ID] PACKAGE PERMISSION  pm reset-permissions pmset-app-link [--user USER_ID] PACKAGE {always|ask|never|undefined}
       pm get-app-link [--user USER_ID] PACKAGE
       pm set-install-location [0/auto] [1/internal] [2/external]
       pm get-install-location
       pm set-permission-enforced PERMISSION [true|false]
       pm trim-caches DESIRED_FREE_SPACE [internal|UUID]
       pm create-user [--profileOf USER_ID] [--managed] USER_NAME
       pm remove-user USER_ID
       pm get-max-users

pm list packages: prints all packages, optionally only
  those whose package name contains the text in FILTER.  Options:
    -f: see their associated file.
    -d: filter to only show disbled packages.
    -e: filter to only show enabled packages.
    -s: filter to only show system packages.
    -3: filter to only show third party packages.
    -i: see the installer for the packages.
    -u: also include uninstalled packages.

pm list permission-groups: prints all known permission groups.

pm list permissions: 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 will see.

pm list instrumentation: use to list all test packages; optionally
  supply <TARGET-PACKAGE> to list the test packages for a particular
  application.  Options:
    -f: list the .apk file for the test package.

pm list features: prints all features of the system.

pm list users: prints all users on the system.

pm path: print the path to the .apk of the given PACKAGE.

pm dump: print system state associated with the given PACKAGE.

pm install: install a single legacy package
pm install-create: create an install session
    -l: forward lock application
    -r: replace existing application
    -t: allow test packages
    -i: specify the installer package name
    -s: install application on sdcard
    -f: install application on internal flash
    -d: allow version code downgrade
    -p: partial application install
    -g: grant all runtime permissions
    -S: size in bytes of entire session

pm install-write: write a package into existing session; path may
  be The '-' to read from stdin
    -S: size in bytes of package, required for stdin

pm install-commit: perform install of fully staged session
pm install-abandon: abandon session

pm set-installer: set installer package name

pm uninstall: removes a package from the system. Options:
    -k: keep the data and cache directories around after package removal.

pm clear: deletes all data associated with a package.

pm enable.disable.disable-user, disable-until-used: these commands
  change the enabled state of a given package or component (written
  as "package/class").

pm grant, revoke: these commands either grant or revoke permissions
    to apps. The permissions must be declared as used in the app's
    manifest, be runtime permissions (protection level dangerous),
    and the app targeting SDK greater than Lollipop MR1.

pm reset-permissions: revert all runtime permissions to their default state.

pm get-install-location: returns the current install location.
    0 [auto]: Let system decide the best location
    1 [internal]: Install on internal device storage
    2 [external]: Install on external media

pm set-install-location: changes the default install location.
  NOTE: this is only intended for debugging; using this can cause
  applications to break and other undersireable behavior.
    0 [auto]: Let system decide the best location
    1 [internal]: Install on internal device storage
    2 [external]: Install on external media

pm trim-caches: trim cache files to reach the given free space.

pm create-user: create a new user with the given USER_NAME,
  printing the new user identifier of the user.

pm remove-user: remove the user with the given USER_IDENTIFIER,
  deleting all data associated with that user

1|shell@JDtab:/ $ 
Copy the code
4.4.1 list
List packages [options] filter Displays all packages, or only packages whose package names contain the text in filter. Options:-f: View their associated files.-d: Filters to display only software packages that have been disabled.-e: Filters to display only enabled software packages.-s: Filters to display only system software packages. -3: Only third-party software packages are displayed. -i: View the installation program of the software package. -u: includes uninstalled software packages. --user user_id: user space to be queried. Adb shell PM list packages adb shell PM list packages-sAdb Shell PM List Packages -3Copy the code
4.4.2 install and uninstall
Install [options] path Installs the software package (specified by path) into the system. Options:-l: Installs the software package with the forward locking function. -r: reinstalls the existing application and saves its data. -t: allows test APK installation. -i installer_Package_name: specifies the installation package name.-s: Installs software packages on a shared large-capacity storage device, such as SDcard.-f: Installs software packages on internal system memory.-d: Allows version code to degrade. -g: grants all permissions listed in the application list. Uninstall [options] Package Removes software packages from the system. -k: Retain the data and cache directory after the software package is removed.Copy the code
4.4.3 Clearing Data and Cache
The adb shell PM the clear package name to remove qq data 1 | shell @ JDtab: / $PM clear com. Tencent. MobileqqCopy the code

4.5 Viewing and Performing Operations on the PS Process

help

adb shell ps --help usage: ps [-AadefLlnwZ] [-gG GROUP,] [-k FIELD,] [-o FIELD,] [-p PID,] [-t TTY,] [-uU USER,] List processes. Which processes to  show (selections may be comma separated lists): -A All processes-a	Processes with terminals that aren't session leaders
-d	All processes that aren't session leaders
-e	Same as -A
-g	Belonging to GROUPs
-G	Belonging to real GROUPs (before sgid)
-p	PIDs (--pid)
-P	Parent PIDs (--ppid)
-s	In session IDs
-t	Attached to selected TTYs
-T	Show threads
-u	Owned by USERs
-U	Owned by real USERs (before suid)

.....

Copy the code

Common process view operations

Adb shell ps | grep keywords: highlighting the adb shell cat/proc/process id/oom_adj shows process priority adb shellkill [pid]

Copy the code

Example: Display all Tencent APP processes

adb shell ps | grep tencent u0_a156 544 638 1313424 60448 0 0 S com.tencent.tim:Daemon u0_a156 623 638 1314488 60152 0 0  S com.tencent.tim:assist u0_a182 857 638 1385176 78028 0 0 S com.tencent.mobileqq:MSF u0_a165 1636 638 2473248 323928 0  0 S com.tencent.mm u0_a165 2204 638 2090388 117860 0 0 S com.tencent.mm:push system 10200 637 3924720 40540 0 0 S com.tencent.soter.soterserver u0_a156 10335 638 1334496 68572 0 0 S com.tencent.tim:MSF u0_a156 23472 638 1396960 107396  0 0 S com.tencent.tim:mailCopy the code

4.6 input input

input  <command> [<arg>...] See help at shell@JDtab:/ $inputhelp
Error: Unknown command: help
Usage: input [<source< >]command> [<arg>...]  The sources are: mouse keyboard joystick touchnavigation touchpad trackball stylus dpad 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) 3dtouch <x> <y> <z>(Default: touchscreen) shell@JDtab:/ $ sources? Adb shell input text is used to simulate commands"hahah"Similarly, tap input tap 123 312 Input keyevent 3 To return to the desktop. Event 1 menu KEYCODE_MENU 3 HOME KEYCODE_HOME 4 back KEYCODE_BACK 21 Move the cursor left KEYCODE_DPAD_LEFT 22 Move the cursor right KEYCODE_DPAD_RIGHT 67 Delete KEYCODE_DELCopy the code

4.7 Screenshot and Screen Recording

Adb shell screencap /sdcard/ Adb shell ScreenRecord /sdcard/ adb shell screenrecord /sdcard/ adb shell Screenrecord /sdcard Shell, use 'adb pull /sdcard/ IM video.mp4' to copy files from the phone to the PCCopy the code

4.8 monkey

Check out the help shell@JDtab:/ $monkeyhelp** Error: Count is not a number usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]  [-c MAIN_CATEGORY [-c MAIN_CATEGORY] ...]  [--ignore-crashes] [--ignore-timeouts] [--ignore-security-exceptions] [--monitor-native-crashes] [--ignore-native-crashes] [--kill-process-after-error] [--hprof] [--pct-touch PERCENT] [--pct-motion PERCENT] [--pct-trackball PERCENT] [--pct-syskeys PERCENT] [--pct-nav PERCENT] [--pct-majornav PERCENT] [--pct-appswitch PERCENT]  [--pct-flip PERCENT] [--pct-anyevent PERCENT] [--pct-pinchzoom PERCENT] [--pct-permission PERCENT] [--pkg-blacklist-file PACKAGE_BLACKLIST_FILE] [--pkg-whitelist-file PACKAGE_WHITELIST_FILE] [--wait-dbg] [--dbg-no-events] [--setup scriptfile] [-f scriptfile [-fscriptfile] ... ]  [--port port] [-sSEED] [-v [-v] ...]  [--throttle MILLISEC] [--randomize-throttle] [--profile-wait MILLISEC] [--device-sleep-time MILLISEC] [--randomize-script] [--script-log] [--bugreport] [--periodic-bugreport] [--permission-target-system] COUNT 255 | shell @ JDtab: / $example: adb shell monkey - v - p your. Package. The name of 500Copy the code

Dumpsys dumps the system data onto the screen

developer.android.com

Command format adb shell dumpsys [-t timeout] [-- help |-l| - skip services | service (the arguments) | | - c - h] options - t the timeout specified default 10 seconds -- help view the help-lList the available parameters -- Skip Services Specifies the services that youdo not want to include in the output.
service [arguments]	Specifies the service that you want to output. Some services may allow you to pass optional arguments. You can learn about these optional arguments by passing the -h option with the service, as shown below:
adb shell dumpsys procstats -h
    

-c	When specifying certain services, append this option to output data in a machine-friendly format.
-h	For certain services, append this option to see help text and additional options forDumpsys activity AMS service information dumpsys window WMS service information Dumpsys cpuInfo CPU information Dumpsys meminfo Memory informationCopy the code
  • dumpsys activity
Adb shell Dumpsys activity -h Activity manager dump options:-a] [-c] [-p PACKAGE] [-h] [WHAT] ... WHAT may be one of: a[Ctivities]: Activity stack state // check activity r[recents]: recent activities state b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state broadcast-stats [PACKAGE_NAME]: aggregated broadcast statistics i[ntents] [PACKAGE_NAME]: pending intent state p[rocesses] [PACKAGE_NAME]: process state o[om]: out of memory management perm[issions]: URI permission grant state prov[iders] [COMP_SPEC ...] : content provider state provider [COMP_SPEC]: provider client-side state s[ervices] [COMP_SPEC ...] : service state // Service as[sociations]: Tracked App associations Settings: currently applied config settings service [COMP_SPEC]: service client-side state package [PACKAGE_NAME]: all state related to given package all: dump all activities top: dump the top activity WHAT may also be a COMP_SPEC to dump activities. COMP_SPEC may be a component name (com.foo/.myApp), a partial substringin a component name, a
    hex object identifier.
  -a: include all available server state.
  -c: include client state.
  -p: limit output to given package.
  --checkin: output checkin format, resetting data.
  --C: output checkin format, not resetting data.
  --proto: output dump in protocol buffer format.
  --autofill: dump just the autofill-related state of an activity

Copy the code
Ex. : Adb shell Dumpsys activity a Check all wechat services adb shell Dumpsys activity s  com.tencent.mmCopy the code

Details common Adb commands