Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Roman Mazur: INTERACTING WITH YOUR APP THROUGH COMMAND LINE

1fa9cb8c7997c8c4d3d251fb5e41f749?s=47 Realm
October 22, 2016

Roman Mazur: INTERACTING WITH YOUR APP THROUGH COMMAND LINE

Android command line is a very powerful tool. During this talk, we'll briefly review what Android shell commands can be useful for development, testing, and automation. We'll concentrate on how your application can interact with the command line considering 2 approaches. The first one is based on Android framework tools and the second is the core of Facebook Stetho tool.

1fa9cb8c7997c8c4d3d251fb5e41f749?s=128

Realm

October 22, 2016
Tweet

Transcript

  1. Interacting with your app through command line Roman Mazur Software

    Engineer @ Stanfy @roman_mazur #androidshell
  2. #androidshell @roman_mazur #androidshell @roman_mazur Real time updates
 vs
 polling with

    “adb devices” How is the magic done?
  3. #androidshell @roman_mazur #androidshell @roman_mazur Stetho dumpapp Another magic

  4. #androidshell @roman_mazur #androidshell @roman_mazur Use Chrome Dev Tools for you

    app just like for a web browser
  5. #androidshell @roman_mazur Connecting to a device ADB

  6. #androidshell @roman_mazur adbd shell Local socket
 @stetho_my.pckg_devtools_remote tcp:<port> ADB Services

    Device 1 dumpapp ADB Server
 :5037 Dev machine Connecting to a device 1. Select device 2. Select service
 “localabstract:name” adbd Device 2 3. Delegate
  7. #androidshell @roman_mazur dumpapp ADB Server
 :5037 Dev machine ADB Server

    1. Select device 2. Select service
 “localabstract:name” $ lsof -i :5037 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME Google 458 roman 14u IPv4 0x6811aab866733861 0t0 TCP localhost:54221->localhost:5037 (ESTABLISHED) studio 11523 roman 31u IPv4 0x6811aab87e409539 0t0 TCP localhost:55391->localhost:5037 (ESTABLISHED) studio 11523 roman 32u IPv4 0x6811aab87e3c2861 0t0 TCP localhost:53970->localhost:5037 (ESTABLISHED) studio 11523 roman 33u IPv4 0x6811aab8668d3539 0t0 TCP localhost:53972->localhost:5037 (ESTABLISHED) studio 11523 roman 35u IPv4 0x6811aab865be8861 0t0 TCP localhost:59588->localhost:5037 (ESTABLISHED) studio 11523 roman 425u IPv4 0x6811aab866848861 0t0 TCP localhost:49906->localhost:5037 (ESTABLISHED) adb 11743 roman 4u IPv4 0x6811aab865bd6a51 0t0 TCP localhost:5037->localhost:54221 (ESTABLISHED) adb 11743 roman 6u IPv4 0x6811aab8667de861 0t0 TCP localhost:5037->localhost:49906 (ESTABLISHED) adb 11743 roman 7u IPv4 0x6811aab866765c41 0t0 TCP localhost:5037 (LISTEN) adb 11743 roman 10u IPv4 0x6811aab866788e31 0t0 TCP localhost:5037->localhost:53970 (ESTABLISHED) adb 11743 roman 12u IPv4 0x6811aab85e985a51 0t0 TCP localhost:5037->localhost:53972 (ESTABLISHED) adb 11743 roman 13u IPv4 0x6811aab8668cb861 0t0 TCP localhost:5037->localhost:55391 (ESTABLISHED) adb 11743 roman 14u IPv4 0x6811aab87e3f6861 0t0 TCP localhost:5037->localhost:59588 (ESTABLISHED) Google Chrome, Android Studio, adb client, Stetho dumpapp talk to it
  8. #androidshell @roman_mazur adbd shell Local socket
 @stetho_my.pckg_devtools_remote tcp:<port> ADB Services

    Device 1 ADB Deamon $ adb shell ps | grep adb shell 25878 1 26068 360 ffffffff 00000000 S /sbin/adbd Runs as a shell user on a device exposing different services $ adb shell cat /proc/net/unix | grep remote 00000000: 00000002 00000000 00010000 0001 01 309885 @stetho_com.stanfy.cmdline_devtools_remote 00000000: 00000002 00000000 00010000 0001 01 81886 @chrome_devtools_remote
  9. #androidshell @roman_mazur Other use case Stream your screen like Vysor:

    MediaProjection + VirtualDisplay API + adb connection
  10. #androidshell @roman_mazur #androidshell @roman_mazur adb shell

  11. #androidshell @roman_mazur adbd shell Local socket
 @stetho_my.pckg_devtools_remote tcp:<port> ADB Services

    Device 1 adb ADB Server
 :5037 Dev machine Connecting to a device adbd Device 2
  12. #androidshell @roman_mazur adb shell Start your activity am start -n

    <package>/<activity> Simulate key strokes input keyevent <code: 4 - back, 3 - home>
  13. #androidshell @roman_mazur #androidshell @roman_mazur dumpsys activity

  14. #androidshell @roman_mazur dumpsys activity Your entry point dumpsys activity -h

    Might be very useful dumpsys activity top dumpsys activity package <package>
 service <package>/<service-name> 
 provider <package>/<provider-name>
  15. #androidshell @roman_mazur References and further reading ADB sources https://github.com/android/platform_system_core/tree/master/adb Stetho

    tool https://github.com/facebook/stetho “Embedded Android” book http://shop.oreilly.com/product/0636920021094.do
  16. #androidshell @roman_mazur Thank you! Questions? Questions? #androidshell @roman_mazur +RomanMazur www.stanfy.com