adb代码实现及debug

本文详细解析了ADB(Android Debug Bridge)命令的工作流程,包括设备连接、版本验证、设备列表获取等关键步骤,并深入介绍了相关核心代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码见 /system/core/adb


enable logs:
adb_trace.h
+#define VLOG_IS_ON(TAG) 1


add more logs:
#if defined(_WIN32)
#if ADB_HOST
#if !ADB_HOST
D("readx: fd=%d wanted=%zu", fd, len);


user key 'C:\Users\28847867\.android\adbkey

 
windows PC: adb.exe; linux PC: adb
Phone: adbd




adb devices
同adb server建立socket, new socket, connect, 
send("host:version"), 首先得到版本信息,判断是否需要重启adb server.
然后send("host:devices"), then read response. 


adb_commandline() in commandline.cpp called in main() in client/main.cpp
   std::string query = android::base::StringPrintf("host:%s%s", argv[0], listopt);
   printf("List of devices attached\n");
   return adb_query_command("host:devices")


adb_query_command("host:devices")
  adb_query("host:devices")
    adb_connect("host:devices")
    ReadProtocolString()




adb_connect("host:devices")
  int fd = _adb_connect("host:version", error);  //根据version,判断是否要重启server
  fd = _adb_connect("host:devices", error);




_adb_connect("host:devices", error);
    network_connect()     new socket, connect() in sysdeps_win32.cpp
    SendProtocolString(fd, service)) 
     


SendProtocolString(fd, service)) 
   WriteFdFmt()
      WriteFdExactly(int fd, const void* buf, size_t len)
         adb_write()  in sysdeps_win32.cpp
             _fh_socket_write
                send









Reference:

android adb源码分析

 http://blog.youkuaiyun.com/xgbing/article/details/52058390 

http://blog.youkuaiyun.com/xgbing/article/details/52059755                        
http://blog.youkuaiyun.com/xgbing/article/details/52065277                        
http://blog.youkuaiyun.com/xgbing/article/details/52075667                        
http://blog.youkuaiyun.com/xgbing/article/details/52096880                        
                                                                            
                                                                                                                                                        
http://blog.youkuaiyun.com/xiaojsj111/article/details/18599653                    
                                                                            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值