droidconBerlin - Life is too short not to use ADB commands

droidconBerlin - Life is too short not to use ADB commands

Talk given at droidcon Berlin 2019 (https://www.de.droidcon.com).

ADB is a versatile command-line tool that lets you communicate with a device. The ADB command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device. It is maybe one of the most used tools by the Android developers, but it is for sure the less known.

Do you want to learn the basic ADB commands or extends your knowledge with some advanced commands? Are you struggling with some bugs? Are you tired to perform some repetitive test? This talk is for you! You can make ADB work for you with automation and assist you to kill bugs. I spent weeks diving into the ADB commands for Sony Mobile and Motorola, and I learned helpful commands that will make your life easier.

It’s time for me to share this with you!

Ff2bfd42d37c150f01bfd5eab3e4c1fe?s=128

Zhenlei Ji

July 01, 2019
Tweet

Transcript

  1. ADB "Life is too short not to use ADB commands"

    Zhenlei Ji @zhenleiji
  2. About this talk How does it work? Brushing up some

    basics commands Some ADB commands you may have never heard about
  3. How does it work? Android Debug Bridge (adb) ADB Daemon

    (adbd) Android ADB Server (adb) Client Client Host TCP 5555 to 5585 (WiFi) Usb or TCP 5037 TCP 5037
  4. Brushing up some basic commands…

  5. ~$ adb Android Debug Bridge Usages

  6. Android Debug Bridge version 1.0.40 Version 4797878 Installed as /Users/zji/Library/Android/sdk/platform-tools/adb

    global options: -a listen on all network interfaces, not just localhost -d use USB device (error if multiple devices connected) -e use TCP/IP device (error if multiple TCP/IP devices available) -s SERIAL use device with given serial (overrides $ANDROID_SERIAL) -t ID use device with given transport id -H name of adb server host [default=localhost] -P port of adb server [default=5037] -L SOCKET listen on given socket for adb server [default=tcp:localhost:5037] ~$ adb Usages Android Debug Bridge
  7. ~$ adb tcpip 5555 Debug connections Wireless debugging

  8. ~$ adb tcpip 5555 Wireless debugging ~$ adb connect <device-ip>

    Debug connections
  9. ~$ adb tcpip 5555 Wireless debugging ~$ adb connect <device-ip>

    ~$ adb usb Usb debugging Debug connections
  10. None
  11. ~$ adb devices -l Devices Show device detail list

  12. ~$ adb devices -l Devices Show device detail list List

    of devices attached ZX1G4295NB device usb:336592896X product:shamu model:Nexus_6 device:shamu transport_id:2 emulator-5554 device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:4
  13. ~$ adb devices -l Devices Show device detail list List

    of devices attached ZX1G4295NB device usb:336592896X product:shamu model:Nexus_6 device:shamu transport_id:2 emulator-5554 device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:4 ~$ adb -s [serial_number] … Send commands to a specific device ZX1G4295NB, emulator-5554
  14. Transfer ~$ adb install <apk-path> Install/Uninstall an app ~$ adb

    uninstall <package>
  15. Transfer ~$ adb install <apk-path> Install/Uninstall an app ~$ adb

    uninstall <package> ~$ adb install -r <apk-path> Reinstall an app
  16. Transfer ~$ adb install <apk-path> Install/Uninstall an app ~$ adb

    uninstall <package> ~$ adb push <local> <remote> Copy files to/from a device ~$ adb pull <remote> <local> ~$ adb install -r <apk-path> Reinstall an app
  17. Some ADB commands you may have never heard about…

  18. ~$ adb shell pm Package Manager Call package manager

  19. ~$ adb shell pm Package Manager Call package manager usage:

    pm path [--user USER_ID] 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 pm set-installer PACKAGE INSTALLER pm move-package PACKAGE [internal|UUID] . . .
  20. ~$ adb shell pm list packages Package Manager Show package

    list
  21. ~$ adb shell pm list packages | grep youtube Package

    Manager Show package list
  22. ~$ adb shell pm list packages | grep youtube Package

    Manager Show package list ~$ adb shell pm path [package] Print the path to the APK of the given package
  23. APK Analyzer Search for youtube package Locate youtube.apk path Pull

    youtube.apk to the machine
  24. Package Manager

  25. Package Manager ~$ adb shell pm clear [package] Clear data

  26. Package Manager ~$ adb shell pm clear [package] Clear data

  27. Package Manager ~$ adb shell pm clear [package] Clear data

    ~$ adb shell pm grant[package][permission] Grant a permission to an app ~$ adb shell pm revoke[package][permission] Revoke a permission to an app
  28. ~$ adb shell pm list packages | grep youtube Package

    Manager ~$ adb shell pm dump [package] Print current system state associated with the given PACKAGE Actions Schemes Broadcast Receivers ContentProviders Permissions Pending Intents Activity Back Stack Memory Usage
  29. Upload video

  30. Activity Launcher

  31. Deeplink

  32. Broadcast Receiver

  33. Content Provider

  34. Permissions

  35. Pending Intents

  36. Activity Back Stack

  37. Memory Usage

  38. ~$ adb shell am Activity Manager Call activity manager

  39. ~$ adb shell am Activity Manager Call activity manager usage:

    am [subcommand] [options] usage: am start [-D] [-N] [-W] [-P <FILE>] [--start-profiler <FILE>] [--sampling INTERVAL] [-R COUNT] [-S] [--track-allocation] [--user <USER_ID> | current] <INTENT> am startservice [--user <USER_ID> | current] <INTENT> am stopservice [--user <USER_ID> | current] <INTENT> am force-stop [--user <USER_ID> | all | current] <PACKAGE> am kill [--user <USER_ID> | all | current] <PACKAGE> am kill-all am broadcast [--user <USER_ID> | all | current] <INTENT> . . .
  40. ~$ adb shell am start [options] [intent] Start an Activity

    specified by intent Intent
  41. ~$ adb shell am start [options] [intent] Start an Activity

    specified by intent Intent -D: Enable debugging. -W: Wait for launch to complete. --start-profiler file: Start profiler and send results to file. -P file: Like --start-profiler, but profiling stops when the app goes idle. -R count: Repeat the activity launch count times. Prior to each repeat, the top activity will be finished. -S: Force stop the target app before starting the activity. --opengl-trace: Enable tracing of OpenGL functions. --user user_id | current: Specify which user to run as; if not specified, then run as the current user.
  42. ~$ adb shell am start [options] [intent] Start an Activity

    specified by intent Intent -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().
  43. ~$ adb shell am start [options] [intent] Start an Activity

    specified by intent Intent
  44. ~$ adb shell am start [options] [intent] Start an Activity

    specified by intent ~$ adb shell am startservice [options] [intent] Start a Service specified by intent Intent
  45. ~$ adb shell am start [options] [intent] Start an Activity

    specified by intent ~$ adb shell am startservice [options] [intent] Start a Service specified by intent ~$ adb shell am broadcast [options] [intent] Send a Broadcast intent Intent
  46. ~$ adb shell am force-stop [package] Force stop everything associated

    with package Kill
  47. ~$ adb shell am force-stop [package] Force stop everything associated

    with package ~$ adb shell am kill [package] Kill all process associated with package Kill
  48. ~$ adb shell am force-stop [package] Force stop everything associated

    with package ~$ adb shell am kill [package] Kill all process associated with package ~$ adb shell am kill-all Kill all background processes Kill
  49. ~$ adb shell wm Window Manager Call window manager

  50. ~$ adb shell wm Window Manager Call window manager usage:

    wm [subcommand] [options] wm size [reset|WxH|WdpxHdp] wm density [reset|DENSITY] wm overscan [reset|LEFT,TOP,RIGHT,BOTTOM] wm scaling [off|auto] wm screen-capture [userId] [true|false] wm size: return or override display size. width and height in pixels unless suffixed with 'dp'. wm density: override display density. wm overscan: set overscan area for display. . . .
  51. Simulate other devices ~$ adb shell wm size [WxH|WdpxHdp|reset] Return

    or override display size
  52. Simulate other devices ~$ adb shell wm size [WxH|WdpxHdp|reset] Return

    or override display size ~$ adb shell wm density [DENSITY|reset] Return or override density size mdpi (~160) hdpi (~240) xhdpi (~320) xxhdpi (~480) xxxhdpi (~640)
  53. Default size and density

  54. Simulate a tablet

  55. Narrow screen

  56. Small screen

  57. System Properties ~$ adb shell getprop List of system properties

  58. System Properties ~$ adb shell getprop List of system properties

  59. System Properties ~$ adb shell getprop List of system properties

    ~$ adb shell getprop [system_property] Provides information about the specific system property
  60. System Properties ~$ adb shell getprop List of system properties

    ~$ adb shell getprop [system_property] Provides information about the specific system property
  61. None
  62. System Properties ~$ adb shell getprop List of system properties

    ~$ adb shell getprop [system_property] Provides information about the specific system property ~$ adb shell setprop [system_property] [value] Change a system property
  63. Enable overdraw

  64. https://android.googlesource.com/platform/frameworks/base/+/master/libs/hwui/Properties.h Enable profile

  65. ~$ adb shell input Simulate Input Call input

  66. ~$ adb shell input Simulate Input Call input Usage: input

    [<source>] <command> [<arg>...] . . . 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) draganddrop <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen) press (Default: trackball) roll <dx> <dy> (Default: trackball)
  67. Simulate Input ~$ adb shell input keyevent [keycode_number or name]

    Keyevent https://developer.android.com/reference/android/view/KeyEvent
  68. Simulate Input ~$ adb shell input keyevent [keycode number or

    name] Keyevent ~$ adb shell input tap [X] [Y] Tap https://developer.android.com/reference/android/view/KeyEvent
  69. Simulate Input ~$ adb shell input keyevent [keycode number or

    name] Keyevent ~$ adb shell input tap [X] [Y] Tap ~$ adb shell input swipe [X1] [Y1] [X2] [Y2] Swipe https://developer.android.com/reference/android/view/KeyEvent
  70. Simulate Input

  71. Just to wrap up…

  72. Versatile command-line tool Provides access to a Unix shell Powerful

    throughout development
  73. Some tips…

  74. Create alias

  75. Create a folder for your scripts Environment Variable

  76. Create scripts https://github.com/zhenleiji/AndroidScripts

  77. "Life is too short not to use ADB commands"

  78. Zhenlei Ji A n d r o i d S

    o f t w a r e E n g i n e e r zhenlei.ji@gmail.com @zhenleiji THANK YOU! We are hiring!
  79. References https://developer.android.com/studio/command-line/adb http://developer.famoco.com/Android_development/ADB_commands/ http://adbshell.com/ https://jiafei427.wordpress.com/2016/11/21/adb-in-android/ https://gist.github.com/Pulimet/5013acf2cd5b28e55036c82c91bd56d8 https://nelenkov.blogspot.com/2012/06/unpacking-android-backups.html https://medium.com/@filipe.batista/ezadb-easy-android-debug-bridge-8cef841a7124 https://developer.android.com/studio/debug/bug-report https://source.android.com/setup/contribute/read-bug-reports