美文网首页
Android进程的启动

Android进程的启动

作者: Allenlll | 来源:发表于2020-04-23 17:26 被阅读0次
  • init进程
    系统启动后,init进程会启动system/bin/app_process程序,源码为:app_main.cpp。根据zygote标志启动不同进程
int main(int argc, char* const argv[])
{
    AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv));

    if (!niceName.isEmpty()) {
        runtime.setArgv0(niceName.string(), true /* setProcName */);
    }
     bool zygote = false;
     if (strcmp(arg, "--zygote") == 0) {
            zygote = true;
            niceName = ZYGOTE_NICE_NAME;
        }
    if (zygote) {
        runtime.start("com.android.internal.os.ZygoteInit", args, zygote);
    } else if (className) {
        runtime.start("com.android.internal.os.RuntimeInit", args, zygote);
    } else {
        app_usage();
    }
}


AppRuntime继承AndoridRuntime

class AppRuntime : public AndroidRuntime
{
public:
    AppRuntime(char* argBlockStart, const size_t argBlockLength)
        : AndroidRuntime(argBlockStart, argBlockLength)
        , mClass(NULL)
    {
    }

 
    virtual void onVmCreated(JNIEnv* env)
    {
        
    }

    virtual void onStarted()
    {
       
    }

    virtual void onZygoteInit()
    {
        sp<ProcessState> proc = ProcessState::self();
        proc->startThreadPool();
    }

    virtual void onExit(int code)
    {
     

        AndroidRuntime::onExit(code);
    }


}


  • AndoridRuntime

相关文章

网友评论

      本文标题:Android进程的启动

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