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

Eyal Lezmy - ADB - Break On Through To The Othe...

Eyal Lezmy - ADB - Break On Through To The Other Side

droidcon Berlin

July 17, 2018
Tweet

More Decks by droidcon Berlin

Other Decks in Programming

Transcript

  1. How adb works > Some adb commands > The internals

    > Dev on the adb project > The Android dev tools >
  2. Part of the SDK on the platform-tools directory 2 versions

    distributed Stable & Preview channel
  3. adb client adb server localhost adb daemon 5557 Android Studio

    Emulator Open a connection to the device
  4. adb client adb server adb daemon Nexus 6P adb daemon

    Network device adb daemon AS Emulator
  5. adb client adb server adb daemon Nexus 6P adb daemon

    Network device adb daemon AS Emulator
  6. adb tcpip 5555 > ADB Server asks the Daemon to

    enable the network connection “tcpip:5555”
  7. adb tcpip 5555 > ADB Server asks the Daemon to

    enable the network connection The daemon sets a system property setprop service.adb.tcp.port 5555
  8. adb tcpip 5555 > ADB Server asks the Daemon to

    enable the network connection The daemon sets a system property ADB Daemon closes itself exit(1)
  9. adb tcpip 5555 > ADB Server asks the Daemon to

    enable the network connection The daemon sets a system property ADB Daemon closes itself The system restarts automatically ADB Daemon service adbd /sbin/adbd
  10. adb tcpip 5555 > ADB Server asks the Daemon to

    enable the network connection The daemon sets a system property ADB Daemon closes itself The system restarts automatically ADB Daemon The Daemon will read the property at start and will listen to this port getprop service.adb.tcp.port
  11. adb devices -l > 192.168.63.101:5555 device product:vbox86p model:myGenymotionNexus5 device:vbox86p F5AZFG013292

    device usb:336592896X product:WW_Z00A model:ASUS_Z00AD device:Z00A HT4CNJT00728 device usb:336592896X product:volantis model:Nexus_9 device:flounder Detailed device list
  12. adb -e shell > Filter the type of device Emulator

    or network device adb -d shell > USB device
  13. adb client adb server 5037 adb -H 10.5.0.5 -P 5037

    devices > Device farm server 10.5.0.5
  14. adb client adb server Samsung S6 Genymotion Kitkat Pixel 2

    XL 5037 adb -H 10.5.0.5 -P 5037 devices > Device farm server 10.5.0.5
  15. adb shell settings put global http_proxy localhost:3333 > adb reverse

    tcp:3333 tcp:3128 > docker run --name squid \ --publish 127.0.0.1:3128:3128 \ --volume $HOME/squid.conf:/etc/squid3/squid.conf \ --volume /tmp/squid/cache:/var/spool/squid3 \ --volume /tmp/squid/cache:/var/log/squid3 \ sameersbn/squid:3.3.8-12 >
  16. adb > ... -p <name or path> - simple product

    name like 'sooner', or a relative/absolute path to a product out directory like 'out/target/product/sooner'. If -p is not specified, the ANDROID_PRODUCT_OUT environment variable is used, which must be an absolute path.
  17. adb > ... -p <name or path> - simple product

    name like 'sooner', or a relative/absolute path to a product out directory like 'out/target/product/sooner'. If -p is not specified, the ANDROID_PRODUCT_OUT environment variable is used, which must be an absolute path. Sooner??
  18. adb client adb server adb shell ls > shell:ls Please

    execute the shell service with the parameter “ls”
  19. adb client adb server adb shell ls > shell:ls “ls

    output” cache charge config ...
  20. adb client adb server adb shell ls > host:version OKAY

    36 host:transport-any OKAY shell:ls “ls output”
  21. adb devices > adb server version (32) doesn't match this

    client (36); killing… adb devices > adb server is out of date. killing...
  22. adb > adb -s <serial> > At device selection adb

    -d > adb -e > host:transport:<serial> host:transport-any host:transport-usb host:transport-local
  23. adb daemon adb client adb server Requests a service execution

    Executes host services Executes local services
  24. host:version Get the ADB Server version host:kill Kill the ADB

    Server host:devices List the connected devices host:devices-l List the connected devices with details host:track-devices Track the list of the connected devices host:transport* Target a device to interact with Some host services
  25. shell:<command> Run a shell command shell: Open an interactive shell

    session remount: Remount the filesystem in r-w mode framebuffer: Get framebuffer snapshots jdwp:<pid> Connects to the JDWP thread of a process track-jdwp Track the list of all processes in debug sync: Specific service used for push & pull Some local services
  26. amessage data struct amessage { unsigned command; /* command identifier

    constant */ unsigned arg0; /* first argument */ unsigned arg1; /* second argument */ unsigned data_length; /* length of payload (0 is allowed) */ unsigned data_crc32; /* crc32 of data payload */ unsigned magic; /* command ^ 0xffffffff */ };
  27. amessage data struct amessage { unsigned command; /* command identifier

    constant */ unsigned arg0; /* first argument */ unsigned arg1; /* second argument */ unsigned data_length; /* length of payload (0 is allowed) */ unsigned data_crc32; /* crc32 of data payload */ unsigned magic; /* command ^ 0xffffffff */ }; The verb of the action
  28. amessage data struct amessage { unsigned command; /* command identifier

    constant */ unsigned arg0; /* first argument */ unsigned arg1; /* second argument */ unsigned data_length; /* length of payload (0 is allowed) */ unsigned data_crc32; /* crc32 of data payload */ unsigned magic; /* command ^ 0xffffffff */ }; The arguments of the action
  29. amessage data struct amessage { unsigned command; /* command identifier

    constant */ unsigned arg0; /* first argument */ unsigned arg1; /* second argument */ unsigned data_length; /* length of payload (0 is allowed) */ unsigned data_crc32; /* crc32 of data payload */ unsigned magic; /* command ^ 0xffffffff */ }; The size of the data
  30. adb daemon adb server adb connect <ip:port> > CNXN, 0x01000000,

    256K device::ro.product... Command Arg 1 Arg 2
  31. adb daemon adb server adb connect <ip:port> > CNXN, 0x01000000,

    256K device::ro.product... Device identity string
  32. adb daemon adb server adb shell ls > OPEN, server-id,

    0, shell:ls Command Arg1 Arg2 Data
  33. adb daemon adb server adb shell ls > OPEN, server-id,

    0, shell:ls The ADB service to execute
  34. adb daemon adb server adb shell ls > OPEN, server-id,

    0, shell:ls OKAY, daemon-id, server-id
  35. adb daemon adb server adb shell ls > OPEN, server-id,

    0, shell:ls OKAY, daemon-id, server-id WRITE, daemon-id, server-id “DATA”
  36. adb daemon adb server adb shell ls > OPEN, server-id,

    0, shell:ls OKAY, daemon-id, server-id WRITE, daemon-id, server-id “DATA” OKAY, server-id, daemon-id
  37. adb daemon adb server adb shell ls > OPEN, server-id,

    0, shell:ls OKAY, daemon-id, server-id WRITE, daemon-id, server-id “DATA” OKAY, server-id, daemon-id WRITE, daemon-id, server-id “DATA” CLOSE, daemon-id, server-id
  38. adb daemon adb server adb shell ls > OPEN, server-id,

    0, shell:ls OKAY, daemon-id, server-id WRITE, daemon-id, server-id “DATA” OKAY, server-id, daemon-id WRITE, daemon-id, server-id “DATA” OKAY, server-id, daemon-id CLOSE, server-id, daemon-id CLOSE, daemon-id, server-id
  39. adb daemon adb server WRITE, “256KB DATA” OKAY OKAY WRITE,

    “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA” WRITE, “256KB DATA” OKAY OKAY WRITE, “256KB DATA”
  40. repo init \ -u https://android.googlesource.com/platform/manifest \ -b master repo sync

    -c --force-sync source build/envsetup.sh lunch make -j24 adb > > > > >
  41. adb The client host binary Bundle in the Android SDK

    The one you use everyday Output path ./out/host/<your-platform>/bin/adb
  42. adbd The device’s daemon binary Bundle in the Android OS

    The one you use everyday Maybe without noticing
  43. adb client adb server adb daemon Nexus 6P adb daemon

    Network device adb daemon AS Emulator adb client adb client
  44. adb devices > ... adb I 39295 1708488 adb_client.cpp:135] _adb_connect:host:devices

    adb I 39295 1708488 adb_io.cpp:99] writex: fd=3 len=16 30303063686f73743a64657669636573 000chost:devices ... ADB Client logs tail -f /tmp/adb.log Linux tail -f $TMPDIR/adb.*.log Mac ADB Server logs > >
  45. ddmlib as library Maintained by Google Open source Many thousands

    of daily users Still need the adb binary Possibly a good tool for your project
  46. repo init \ -u https://android.googlesource.com/platform/manifest \ -b gradle_3.0.0 repo sync

    -c --force-sync cd ./tools/base/build-system/ > > > Get the source code
  47. When there is an interaction with a device Install an

    APK Launch instrumented tests Get devices information
  48. Manages the list of connected devices Interacts with the device

    through ddmlib DeviceProvider ConnectedDevice
  49. gradlew <yourTask> --debug > Make ddmlib verbose from the build.gradle

    import com.android.ddmlib.DdmPreferences DdmPreferences.setLogLevel("verbose")
  50. Make ddmlib verbose from the build.gradle V/ddms: execute: running pm

    install-create -r -S 945819 V/ddms: execute: running pm install-write -S 945819 26732 0_binocle-flavor1-debug - V/ddms: execute: running pm install-commit 1802739235 … V/ddms: execute: running am instrument -w -r com.genymotion.binocle.test/android.test.InstrumentationTestRunner V/InstrumentationResultParser: INSTRUMENTATION_STATUS: numtests=5 V/InstrumentationResultParser: INSTRUMENTATION_STATUS: stream= V/InstrumentationResultParser: com.genymotion.binocle.test.TestBattery: V/InstrumentationResultParser: INSTRUMENTATION_STATUS: id=InstrumentationTestRunner V/InstrumentationResultParser: INSTRUMENTATION_STATUS: test=testBatteryWarning …
  51. Inject ADB options from the build.gradle for all the tasks

    android.adbOptions { timeOutInMs 5000 // 5 seconds installOptions “-g” }
  52. Inject ADB options from the build.gradle for a single task

    android.testVariants.all { variant -> variant.connectedInstrumentTest.installOptions = ["-g"] }