来自:http://www.apkbus.com/android-20594-1-1.html
3、以常用命令为实例
常用的指令如下:
所有这些cmd处理函数都在:\system\core\adb\Commandline.c 中:
int adb_commandline(int argc, char **argv)
为了更好的理解这些命令,有必须找到代码理解一下这些命令的处理主要函数:
函数启动点: adb.c 中的main函数,根据ADB_HOST决定执行哪些代码:
先分析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