Android培训班(39)
<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } -->
在init.rc文件里,可以看到加载下面的服务:
service installd /system/bin/installd
socket installd stream 600 system system
installd 服务的代码在目录:
Android-2.0/frameworks/base/cmds/installd
installd服务是提供安装dex文件的服务。
它的主要入口函数代码如下:
int main(const int argc, const char *argv[]) {
char buf[BUFFER_MAX];
struct sockaddr addr;
socklen_t alen;
int lsocket, s, count;
创建一个控制的SOCKET。
lsocket = android_get_control_socket(SOCKET_PATH);
if (lsocket < 0) {
LOGE("Failed to get socket from environment: %s ", strerror(errno));
exit(1);
}
监听这个SOCKET。
if (listen(lsocket, 5)) {
LOGE("Listen on socket failed: %s ", strerror(errno));
exit(1);
}
fcntl(lsocket, F_SETFD, FD_CLOEXEC);
循环里处理接收到的SOCKET连接。
for (;;) {
alen = sizeof(addr);
s = accept(lsocket, &addr, &alen);
if (s < 0) {
LOGE("Accept failed: %s ", strerror(errno));
continue;
}
fcntl(s, F_SETFD, FD_CLOEXEC);
从新连接里接收到命令并处理。
LOGI("new connection ");
for (;;) {
unsigned short count;
if (readx(s, &count, sizeof(count))) {
LOGE("failed to read size ");
break;
}
if ((count < 1) || (count >= BUFFER_MAX)) {
LOGE("invalid size %d ", count);
break;
}
if (readx(s, buf, count)) {
LOGE("failed to read command ");
break;
}
buf[count] = 0;
if (execute(s, buf)) break;
}
LOGI("closing connection ");
close(s);
}
return 0;
}
补充:移动开发 , Android ,