intmain(int argc, char* const argv[]) { if (!LOG_NDEBUG) { String8 argv_String; for (int i = 0; i < argc; ++i) { argv_String.append("\""); argv_String.append(argv[i]); argv_String.append("\" "); } ALOGV("app_process main with argv: %s", argv_String.string()); }
AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv)); // Process command line arguments // ignore argv[0] argc--; argv++; ...... if (zygote) { runtime.start("com.android.internal.os.ZygoteInit", args, zygote); } elseif (className) { runtime.start("com.android.internal.os.RuntimeInit", args, zygote); } else { fprintf(stderr, "Error: no class name or --zygote supplied.\n"); app_usage(); LOG_ALWAYS_FATAL("app_process: no class name or --zygote supplied."); } }
// Mark zygote start. This ensures that thread creation will throw // an error. ZygoteHooks.startZygoteNoThreadCreation();
// Zygote goes into its own process group. try { Os.setpgid(0, 0); } catch (ErrnoException ex) { thrownew RuntimeException("Failed to setpgid(0,0)", ex); }
Runnable caller; ...... if (startSystemServer) { //启动system_server Runnable r = forkSystemServer(abiList, zygoteSocketName, zygoteServer);
// {@code r == null} in the parent (zygote) process, and {@code r != null} in the // child (system_server) process. if (r != null) { r.run(); return; } } ......
/** * The main entry point from zygote. */ publicstaticvoidmain(String[] args){ new SystemServer().run(); }
publicSystemServer(){ // Check for factory test mode. mFactoryTestMode = FactoryTest.getMode();
// Record process start information. // Note SYSPROP_START_COUNT will increment by *2* on a FDE device when it fully boots; // one for the password screen, second for the actual boot. mStartCount = SystemProperties.getInt(SYSPROP_START_COUNT, 0) + 1; mRuntimeStartElapsedTime = SystemClock.elapsedRealtime(); mRuntimeStartUptime = SystemClock.uptimeMillis();
// Remember if it's runtime restart(when sys.boot_completed is already set) or reboot // We don't use "mStartCount > 1" here because it'll be wrong on a FDE device. // TODO: mRuntimeRestart will *not* be set to true if the proccess crashes before // sys.boot_completed is set. Fix it. mRuntimeRestart = "1".equals(SystemProperties.get("sys.boot_completed")); }