美文网首页
Android之installd的进化

Android之installd的进化

作者: 锄禾豆 | 来源:发表于2022-01-20 08:01 被阅读0次

    代码路径

    frameworks/native/cmds/installd
    

    7.1的installd

    installd.rc --- socket服务端
    service installd /system/bin/installd
        class main
        socket installd stream 600 system system
    
    
    installd.cpp
    main --> installd_main
    static int installd_main(const int argc ATTRIBUTE_UNUSED, char *argv[]) {
        ···
        lsocket = android_get_control_socket(SOCKET_PATH);//创建socket服务端
        if (lsocket < 0) {
            ALOGE("Failed to get socket from environment: %s\n", strerror(errno));
            exit(1);
        }
        if (listen(lsocket, 5)) {//执行监听
            ALOGE("Listen on socket failed: %s\n", strerror(errno));
            exit(1);
        }
        fcntl(lsocket, F_SETFD, FD_CLOEXEC);
    
        for (;;) {
            alen = sizeof(addr);
            s = accept(lsocket, &addr, &alen);//接收数据
            if (s < 0) {
                ALOGE("Accept failed: %s\n", strerror(errno));
                continue;
            }
            fcntl(s, F_SETFD, FD_CLOEXEC);
    
            ALOGI("new connection\n");
            for (;;) {
                unsigned short count;
                if (readx(s, &count, sizeof(count))) {//读取数据
                    ALOGE("failed to read size\n");
                    break;
                }
                if ((count < 1) || (count >= BUFFER_MAX)) {
                    ALOGE("invalid size %d\n", count);
                    break;
                }
                if (readx(s, buf, count)) {
                    ALOGE("failed to read command\n");
                    break;
                }
                buf[count] = 0;
                if (selinux_enabled && selinux_status_updated() > 0) {
                    selinux_android_seapp_context_reload();
                }
                if (execute(s, buf)) break;//分发数据
            }
            ALOGI("closing connection\n");
            close(s);
        }
    
        return 0;
    }
    

    10.0的installd

    installd.rc
    service installd /system/bin/installd
        class main
    
    installd.cpp
    main --> installd_main
    
    static int installd_main(const int argc ATTRIBUTE_UNUSED, char *argv[]) {
        ···
        if ((ret = InstalldNativeService::start()) != android::OK) {//binder服务端
            SLOGE("Unable to start InstalldNativeService: %d", ret);
            exit(1);
        }
    
        IPCThreadState::self()->joinThreadPool();
    
        ····
    
        return 0;
    }
    
    详细解析
    InstalldNativeService.cpp
    status_t InstalldNativeService::start() {
        IPCThreadState::self()->disableBackgroundScheduling(true);
        status_t ret = BinderService<InstalldNativeService>::publish();//addService到ServiceManager中。
        if (ret != android::OK) {
            return ret;
        }
        sp<ProcessState> ps(ProcessState::self());
        ps->startThreadPool();
        ps->giveThreadPoolName();
        return android::OK;
    }
    
    InstalldNativeService.h
     static char const* getServiceName() { return "installd"; }
    

    相关文章

      网友评论

          本文标题:Android之installd的进化

          本文链接:https://www.haomeiwen.com/subject/ebuthrtx.html