ADB 源码分析

1、打开adb的详细日志:

  • 设置环境变量ADB_TRACE的值为: all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp
  • 重启命令行后设置生效

日志输出:

λ adb devices
adb D 05-03 11:00:07 39188 51408 adb_trace.cpp:192] Android Debug Bridge version 1.0.40
adb D 05-03 11:00:07 39188 51408 adb_trace.cpp:192] Version 28.0.2-5303910
adb D 05-03 11:00:07 39188 51408 adb_trace.cpp:192] Installed as F:\androidstudio\sdk\platform-tools\adb.exe
adb D 05-03 11:00:07 39188 51408 adb_trace.cpp:192]
List of devices attached
adb D 05-03 11:00:07 39188 51408 adb_client.cpp:287] adb_query: host:devices
adb D 05-03 11:00:07 39188 51408 adb_client.cpp:137] _adb_connect: host:version
adb D 05-03 11:00:07 39188 51408 sysdeps_win32.cpp:809] port 5037 type tcp => fd 2048
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:107] writex: fd=2048 len=16 30303063686f73743a76657273696f6e 000chost:version
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:81] readx: fd=2048 wanted=4
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:97] readx: fd=2048 wanted=4 got=4 4f4b4159 OKAY
adb D 05-03 11:00:07 39188 51408 adb_client.cpp:165] _adb_connect: return fd 2048
adb D 05-03 11:00:07 39188 51408 adb_client.cpp:197] adb_connect: service host:devices
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:81] readx: fd=2048 wanted=4
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:97] readx: fd=2048 wanted=4 got=4 30303034 0004
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:81] readx: fd=2048 wanted=4
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:97] readx: fd=2048 wanted=4 got=4 30303238 0028
adb D 05-03 11:00:07 39188 51408 adb_client.cpp:137] _adb_connect: host:devices
adb D 05-03 11:00:07 39188 51408 sysdeps_win32.cpp:809] port 5037 type tcp => fd 2049
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:107] writex: fd=2049 len=16 30303063686f73743a64657669636573 000chost:devices
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:81] readx: fd=2049 wanted=4
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:97] readx: fd=2049 wanted=4 got=4 4f4b4159 OKAY
adb D 05-03 11:00:07 39188 51408 adb_client.cpp:165] _adb_connect: return fd 2049
adb D 05-03 11:00:07 39188 51408 sysdeps_win32.cpp:509] adb_close: 2048(lo-client:5037)
adb D 05-03 11:00:07 39188 51408 adb_client.cpp:263] adb_connect: return fd 2049
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:81] readx: fd=2049 wanted=4
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:97] readx: fd=2049 wanted=4 got=4 30303130 0010
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:81] readx: fd=2049 wanted=16
adb D 05-03 11:00:07 39188 51408 adb_io.cpp:97] readx: fd=2049 wanted=16 got=16 3131386635656531096465766963650a 118f5ee1.device.
adb D 05-03 11:00:07 39188 51408 sysdeps_win32.cpp:509] adb_close: 2049(lo-client:5037)
118f5ee1        device

信息、

find_devices函数里面的一个细节,前一篇文章说到设备序列号,很多手机的序列号是一样的,就会导致同时插入多个手机的时候区分不开始哪个手机。由于序列号相同,所以执行adb命令的时候就不知道发给哪个手机了。这个过程涉及到USB接口的操作,谷歌的代码里面有一套adbwinapi,其实里面就是用的windows的setupapi函数而已

链接:https://juejin.im/post/5a30f67f6fb9a045204c370a

你可能感兴趣的:(ADB 源码分析)