android2.3-adb源码分析

本文详细分析了adb工具的数据传输机制,包括socket pair的创建、transport_registration_func回调函数的作用,以及input_thread和output_thread的运行原理。此外,还介绍了adb如何执行shell命令,如启动交互式shell、创建子进程以及安装和卸载应用程序的过程。
摘要由CSDN通过智能技术生成

来自:http://www.apkbus.com/android-20594-1-1.html


 

3、以常用命令为实例

常用的指令如下:

  1. adb push <local> <remote>    - copy file/dir to device
  2. adb pull <remote> [<local>]  - copy file/dir from device
  3. adb shell                    - run remote shell interactively
  4. adb install [-l] [-r] [-s] <file> - push this package file to the device and install it
  5. adb kill-server              - kill the server if it is running
  6. connect <host>[:<port>]      - connect to a device via TCP/IP
  7.                                Port 5555 is used by default if no port number is specified.
复制代码


所有这些cmd处理函数都在:\system\core\adb\Commandline.c 中:

int adb_commandline(int argc, char **argv)


为了更好的理解这些命令,有必须找到代码理解一下这些命令的处理主要函数:


函数启动点: adb.c 中的main函数,根据ADB_HOST决定执行哪些代码:

  1. int main(int argc, char **argv)
  2. {
  3. ...
  4. adb_trace_init();
  5. #if ADB_HOST
  6.     adb_sysdeps_init();
  7.     return adb_commandline(argc - 1, argv + 1);  //这里运行PC端,用于命令发送
  8. #else
  9.     start_device_log();
  10.     return adb_main(0, DEFAULT_ADB_PORT);  //运行于android系统的盒子或设备上,用于命令接收及反馈
  11. #endif
  12. }
复制代码

先分析PC端这边:

a、首先建立adb server:

   有两种方式,

手工建立:adb fork-server server 调用:adb_main(is_daemon, server_port);

默认5037端口,也可以设置:service.adb.tcp.port 这个属性获取

自动建立:调用 launch_server(server_port),利用 CreateProcess 或者fork建立后台进程进行运行

// child process

     int result = execl(path, "adb", "fork-server", "server", NULL);

这个进程利用fdevent_loop();处理所有数据及消息

     

b、ADB command-line client即发送命令界面:

主要处理函数:int adb_commandline(int argc, char **argv)

主要利用如下几个函数:

adb_query  查询

adb_connect 连接

adb_status 获取状态


命令发送格式:

1. A 4-byte hexadecimal string giving the length of the payload

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值