Android培训班(35)
<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } -->
在init.rc文件里,可以看到加载下面的服务:
service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
socket zygote stream 666
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on
onrestart restart media
zygote服务的代码在目录:
Android-2.0/frameworks/base/cmds/app_process
zygote服务主要作用就是创建一个服务监听用户的命令,并且根据用户的命令创建应用程序运行。
它的主要入口函数代码如下:
int main(int argc, const char* const argv[])
{
// These are global variables in ProcessState.cpp
mArgC = argc;
mArgV = argv;
mArgLen = 0;
for (int i=0; i<argc; i++) {
mArgLen += strlen(argv[i]) + 1;
}
mArgLen--;
AppRuntime runtime;
这里创建JAVA运行库对象。
const char *arg;
const char *argv0;
argv0 = argv[0];
// Process command line arguments
// ignore argv[0]
argc--;
argv++;
// Everything up to -- or first non - arg goes to the vm
int i = runtime.addVmArguments(argc, argv);
这里添加命令行参数。
// Next arg is parent directory
if (i < argc) {
runtime.mParentDir = argv[i++];
}
// Next arg is startup classname or "--zygote"
if (i < argc) {
arg = argv[i++];
if (0 == strcmp("--zygote", arg)) {
bool startSystemServer = (i < argc) ?
strcmp(argv[i], "--start-system-server") == 0 : false;
setArgv0(argv0, "zygote");
set_process_name("zygote");
runtime.start("com.android.internal.os.ZygoteInit",
startSystemServer);
这里根据命令行参数来创建JAVA虚拟机,并从 com.android.internal.os.ZygoteInit开始运行,然后启动所有JAVA的服务。
} else {
set_process_name(argv0);
runtime.mClassName = arg;
// Remainder of args get passed to startup class main()
runtime.mArgC = argc-i;
runtime.mArgV = argv+i;
LOGV("App process is starting with pid=%d, class=%s. ",
getpid(), runtime.getClassName());
runtime.start();
}
} else {
LOG_ALWAYS_FATAL("app_process: no class name or --zygote supplied.");
fprintf(stderr, "Error: no class name or --zygote supplied. ");
app_usage();
return 10;
}
}
补充:移动开发 , Android ,