Cheat tips \[Become as ADBknowledgeable] ୧╏ ՞ _ ՞ ╏୨
You won’t see here a cool story about knowledge. Just some tips to be more knowledgeable with adb tool in Android☺
List of attached devices:
adb devices
To do something with some specific device:
adb -s SERIAL_NUMBER …
Install app/apk action (use -r to keep all app’s data):
adb install -r APK_FILE_NAME
Uninstall app/apk action (you can find a app name/package via App Info):
adb uninstall PACKAGE_NAME
Go to the shell !:
adb shell
Current activity on screen:
adb shell dump sys window windows | grep -E ‘mCurrentFocus|mFocusedApp’
All activities, tasks:
adb shell dump sys activity activities
Start some specific activity of your app:
adb shell am start -n YOUR_PACKAGE_NAME/.ACTIVITY_NAME
adb shell am start -n YOUR_PACKAGE_NAME/PACKAGE.ACTIVITY_NAME
You can also specify actions to be filter by your intent-filters:
adb shell am start -a com.example.ACTION_NAME -n …
Do you want to see logs (with timestamp)? OK.
adb logcat -v time
Do you want to see logs and filter them by some data? OK.
adb logcat -v time | grep data
Take a screenshot (What did u say?):
adb shell screencap -p | perl -pe ‘s/\x0D\x0A/\x0A/g’ > screenshot.png
Record a screencast (copy + delete):
adb shell screenrecord [options] /sdcard/screencast.mp4 — time-limit 21
adb pull /sdcard/screencast.mp4
adb shell “rm /sdcard/screencast.mp4”
[options]
— size <WIDTHxHEIGHT> Sets the video size: 1280x720. The default value is the device’s native display resolution (if supported), 1280x720 if not. For best results, use a size supported by your device’s Advanced Video Coding (AVC) encoder.
— bit-rate <RATE> Sets the video bit rate for the video, in megabits per second. The default value is 4Mbps. You can increase the bit rate to improve video quality, but doing so results in larger movie files. The following example sets the recording bit rate to 6Mbps:
screenrecord
— bit-rate 6000000 /sdcard/demo.mp4 — time-limit <TIME> Sets the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes).
— rotate Rotates the output 90 degrees. This feature is experimental.
— verbose Displays log information on the command-line screen. If you do not set this option, the utility does not display any information while running.
Turn the device on or off:
adb shell input keyevent 26
Unlock:
adb shell input keyevent 82
Even more, you can combine it (on + unlock):
adb shell input keyevent 26 82
List of codes for keyevent (also see additional info here):
0 --> "KEYCODE_UNKNOWN"
1 --> "KEYCODE_MENU"
2 --> "KEYCODE_SOFT_RIGHT"
3 --> "KEYCODE_HOME"
4 --> "KEYCODE_BACK"
5 --> "KEYCODE_CALL"
6 --> "KEYCODE_ENDCALL"
7 --> "KEYCODE_0"
8 --> "KEYCODE_1"
9 --> "KEYCODE_2"
10 --> "KEYCODE_3"
11 --> "KEYCODE_4"
12 --> "KEYCODE_5"
13 --> "KEYCODE_6"
14 --> "KEYCODE_7"
15 --> "KEYCODE_8"
16 --> "KEYCODE_9"
17 --> "KEYCODE_STAR"
18 --> "KEYCODE_POUND"
19 --> "KEYCODE_DPAD_UP"
20 --> "KEYCODE_DPAD_DOWN"
21 --> "KEYCODE_DPAD_LEFT"
22 --> "KEYCODE_DPAD_RIGHT"
23 --> "KEYCODE_DPAD_CENTER"
24 --> "KEYCODE_VOLUME_UP"
25 --> "KEYCODE_VOLUME_DOWN"
26 --> "KEYCODE_POWER"
27 --> "KEYCODE_CAMERA"
28 --> "KEYCODE_CLEAR"
29 --> "KEYCODE_A"
30 --> "KEYCODE_B"
31 --> "KEYCODE_C"
32 --> "KEYCODE_D"
33 --> "KEYCODE_E"
34 --> "KEYCODE_F"
35 --> "KEYCODE_G"
36 --> "KEYCODE_H"
37 --> "KEYCODE_I"
38 --> "KEYCODE_J"
39 --> "KEYCODE_K"
40 --> "KEYCODE_L"
41 --> "KEYCODE_M"
42 --> "KEYCODE_N"
43 --> "KEYCODE_O"
44 --> "KEYCODE_P"
45 --> "KEYCODE_Q"
46 --> "KEYCODE_R"
47 --> "KEYCODE_S"
48 --> "KEYCODE_T"
49 --> "KEYCODE_U"
50 --> "KEYCODE_V"
51 --> "KEYCODE_W"
52 --> "KEYCODE_X"
53 --> "KEYCODE_Y"
54 --> "KEYCODE_Z"
55 --> "KEYCODE_COMMA"
56 --> "KEYCODE_PERIOD"
57 --> "KEYCODE_ALT_LEFT"
58 --> "KEYCODE_ALT_RIGHT"
59 --> "KEYCODE_SHIFT_LEFT"
60 --> "KEYCODE_SHIFT_RIGHT"
61 --> "KEYCODE_TAB"
62 --> "KEYCODE_SPACE"
63 --> "KEYCODE_SYM"
64 --> "KEYCODE_EXPLORER"
65 --> "KEYCODE_ENVELOPE"
66 --> "KEYCODE_ENTER"
67 --> "KEYCODE_DEL"
68 --> "KEYCODE_GRAVE"
69 --> "KEYCODE_MINUS"
70 --> "KEYCODE_EQUALS"
71 --> "KEYCODE_LEFT_BRACKET"
72 --> "KEYCODE_RIGHT_BRACKET"
73 --> "KEYCODE_BACKSLASH"
74 --> "KEYCODE_SEMICOLON"
75 --> "KEYCODE_APOSTROPHE"
76 --> "KEYCODE_SLASH"
77 --> "KEYCODE_AT"
78 --> "KEYCODE_NUM"
79 --> "KEYCODE_HEADSETHOOK"
80 --> "KEYCODE_FOCUS"
81 --> "KEYCODE_PLUS"
82 --> "KEYCODE_MENU"
83 --> "KEYCODE_NOTIFICATION"
84 --> "KEYCODE_SEARCH"
85 --> "TAG_LAST_KEYCODE"
If you want to send some text (even if you want to send embedded spaces with the input command, use %s):
adb shell input text ‘This%sis%sSPARTA!’
Print all installed packages:
adb shell pm list packages -f
Clear application data:
adb shell pm clear PACKAGE_NAME
To show the log stream on your command line & filter by tagname:
adb logcat -s TAG_NAME
adb logcat -s TAG_NAME_01 TAG_NAME_02 …
To show logs of a specific priority warning and above (for instance :W is warning):
adb logcat “*:PRIORITY”
adb logcat “*:W”
Here are the priority levels:
V — Verbose (lowest priority)
D — Debug
I — Info
W — Warning
E — Error
F — Fatal
S — Silent (highest priority, on which nothing is ever printed)
Filter by tagname and priority:
adb logcat -s TAG_NAME:PRIORITY
adb logcat -s TAG_NAME_01:PRIORITY TAG_NAME_02:PRIORITY
Use this to clear the buffer to remove any old log data:
adb logcat -c
Toggle Android Emulator 2G network limits over and over (toggler.sh):
while true
do echo “network speed full” | nc localhost 5554 sleep 1 echo “network speed gsm” | nc localhost 5554 sleep 1
done
Forwarding ports (to set up arbitrary port forwarding — forwarding of requests on a specific host port to a different port on an emulator/device instance):
adb forward tcp:FROM_LOCAL tcp:TO_REMOTE
adb forward tcp:6100 tcp:7100
Port specifications can use these schemes:
tcp: <portnum>
local: <UNIX domain socket name>
dev: <character device name>
jdwp: <pid>
To copy a file or directory (and its sub-directories) from the emulator or device, use:
adb pull REMOTE_PATH LOCAL_PATH
To copy a file or directory (and its sub-directories) to the emulator or device, use:
adb push LOCAL_PATH REMOTE_PATH
adb push file.txt /sdcard/file.txt
This command will start the server if the server is off or killed:
adb start-server
This command will close ADB server. Useful if ADB server is acting up or not connecting to any devices:
adb kill-server
To print the adb instance serial number string:
adb get-serialno
This command will mounts the /system/ partition Read/Writable pending the device is allow to:
adb remount
This command will restart ADB with root permissions if the build allows for it:
adb root
This command will restart ADB on device to use USB connection for ADB communication:
adb usb
This command will restart ADB on device to use TCPIP connection for ADB. Standard port is 5555:
adb tcpip PORT
This command will restart your device. If either of the two options (recovery/bootloader) are given, the device will boot into that mode:
adb reboot MODE
To print dumpsys, dumpstate, and logcat data to the screen, for the purposes of bug reporting:
adb bugreport
Start an Activity specified by <INTENT>:
adb shell start <INTENT>
Start the Service specified by <INTENT>:
adb shell startservice <INTENT>
To force stop everything associated with <PACKAGE> (the app’s package name):
adb shell force-stop <PACKAGE>
Kill all processes associated with <PACKAGE> (the app’s package name). This command kills only processes that are safe to kill and that will not impact the user experience:
adb shell kill <PACKAGE>
To kill all background processes:
adb shell kill-all
Issue a broadcast intent:
adb shell broadcast <INTENT>
To start profiler on <PROCESS>, write results to <FILE>:
adb shell profile start <PROCESS> <FILE>
To stop profiler on <PROCESS>:
adb shell profile stop <PROCESS>
To dump the heap of <PROCESS>, write to <FILE> (use -n to dump native heap instead of managed heap):
adb shell dumpheap <PROCESS> <FILE>
To start monitoring for crashes or ANRs:
adb shell monitor
To print the given intent specification as a URI:
adb shell to-uri <INTENT>
To print the given intent specification as an intent (URI):
adb shell to-intent-uri <INTENT>
For activity manager commands that take a <INTENT> argument, you can specify the intent with the following options:
-a <ACTION> Specify the intent action, such as “android.intent.action.VIEW”. You can declare this only once.
-d <DATA_URI> Specify the intent data URI, such as “content://contacts/people/1”. You can declare this only once.
-t <MIME_TYPE> Specify the intent MIME type, such as “image/png”. You can declare this only once.
-c <CATEGORY> Specify an intent category, such as “android.intent.category.APP_CONTACTS”.
-n <COMPONENT> Specify the component name with package name prefix to create an explicit intent, such as “com.example.app/.ExampleActivity”.
-f <FLAGS> Add flags to the intent, as supported by setFlags(). — esn <EXTRA_KEY> Add a null extra. This option is not supported for URI intents.
-e| — es <EXTRA_KEY> <EXTRA_STRING_VALUE> Add string data as a key-value pair. — ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> Add boolean data as a key-value pair. — ei <EXTRA_KEY> <EXTRA_INT_VALUE> Add integer data as a key-value pair. — el <EXTRA_KEY> <EXTRA_LONG_VALUE> Add long data as a key-value pair. — ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> Add float data as a key-value pair. — eu <EXTRA_KEY> <EXTRA_URI_VALUE> Add URI data as a key-value pair. — ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE> Add a component name, which is converted and passed as a ComponentName object. — eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE…] Add an array of integers. — ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE…] Add an array of longs. — efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE…] Add an array of floats. — grant-read-uri-permission Include the flag FLAG_GRANT_READ_URI_PERMISSION. — grant-write-uri-permission Include the flag FLAG_GRANT_WRITE_URI_PERMISSION. — debug-log-resolution Include the flag FLAG_DEBUG_LOG_RESOLUTION. — exclude-stopped-packages Include the flag FLAG_EXCLUDE_STOPPED_PACKAGES. — include-stopped-packages Include the flag FLAG_INCLUDE_STOPPED_PACKAGES. — activity-brought-to-front Include the flag FLAG_ACTIVITY_BROUGHT_TO_FRONT. — activity-clear-top Include the flag FLAG_ACTIVITY_CLEAR_TOP. — activity-clear-when-task-reset Include the flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET. — activity-exclude-from-recents Include the flag FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS. — activity-launched-from-history Include the flag FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY. — activity-multiple-task Include the flag FLAG_ACTIVITY_MULTIPLE_TASK. — activity-no-animation Include the flag FLAG_ACTIVITY_NO_ANIMATION. — activity-no-history Include the flag FLAG_ACTIVITY_NO_HISTORY. — activity-no-user-action Include the flag FLAG_ACTIVITY_NO_USER_ACTION. — activity-previous-is-top Include the flag FLAG_ACTIVITY_PREVIOUS_IS_TOP. — activity-reorder-to-front Include the flag FLAG_ACTIVITY_REORDER_TO_FRONT. — activity-reset-task-if-needed Include the flag FLAG_ACTIVITY_RESET_TASK_IF_NEEDED. — activity-single-top Include the flag FLAG_ACTIVITY_SINGLE_TOP. — activity-clear-task Include the flag FLAG_ACTIVITY_CLEAR_TASK. — activity-task-on-home Include the flag FLAG_ACTIVITY_TASK_ON_HOME. — receiver-registered-only Include the flag FLAG_RECEIVER_REGISTERED_ONLY. — receiver-replace-pending Include the flag FLAG_RECEIVER_REPLACE_PENDING. — selector Requires the use of -d and -t options to set the intent data and type.
<URI> <COMPONENT> <PACKAGE> You can directly specify a URI, package name, and component name when not qualified by one of the above options. When an argument is unqualified, the tool assumes the argument is a URI if it contains a “:” (colon); it assumes the argument is a component name if it contains a “/” (forward-slash); otherwise it assumes the argument is a package name.
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 disabled 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. — user <USER_ID>: The user space to query.
adb shell list packages [options] <FILTER>
Prints all known permission groups:
adb shell list permission-groups
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.
adb shell list permissions [options] <GROUP>
List all test packages:
adb shell list instrumentation
Prints all features of the system:
adb shell list features
Prints all the libraries supported by the current device:
adb shell list libraries
Prints all users on the system:
adb shell list users
Print the path to the APK of the given <PACKAGE>:
adb shell path <PACKAGE>
Installs a package (specified by <PATH>) to the system:
Options:
-l: Install the package with forward lock.
-r: Reinstall an exisiting app, keeping its data.
-t: Allow test APKs to be installed.
-i <INSTALLER_PACKAGE_NAME>: Specify the installer package name.
-s: Install package on the shared mass storage (such as sdcard).
-f: Install package on the internal system memory.
-d: Allow version code downgrade.
adb shell install [options] <PATH>
Removes a package from the system:
Options:
-k: Keep the data and cache directories around after package removal.
adb shell uninstall [options] <PACKAGE>
Deletes all data associated with a package:
adb shell clear <PACKAGE>
Enable/Disable the given package or component (written as “package/class”):
adb shell enable/disable <PACKAGE_OR_COMPONENT>
Grant/Revoke permissions to applications. Only optional permissions the application has declared can be granted/revoked:
adb shell grant/revoke <PACKAGE_PERMISSION>
Changes the default install location. Location values:
0: Auto — Let system decide the best location.
1: Internal — install on internal device storage.
2: External — install on external media.
adb shell set-install-location <LOCATION>
Returns the current install location. Return values:
0 [auto]: Lets system decide the best location
1 [internal]: Installs on internal device storage
2 [external]: Installs on external media
adb shell get-install-location
Trim cache files to reach the given free space:
adb shell trim-caches <DESIRED_FREE_SPACE>
Create a new user with the given <USER_NAME>, printing the new user identifier of the user:
adb shell create-user <USER_NAME>
Remove the user with the given <USER_IDENTIFIER>, deleting all data associated with that user:
adb shell remove-user <USER_ID>
Prints the maximum number of users supported by the device:
adb shell get-max-users
For a list of all the available shell programs, use the following command:
adb shell ls /system/bin
OK, that’s it for today. See ya & gl & hf!(・∀・)