详细分析Android中实现Zygote的源码

2020-01-06 13:36:52丽君
  • char* result = strdup(className);  for (char* cp = result; *cp != ''; cp ++) { 
  • if (*cp == '.') {  *cp = '/'; 
  • }  } 
  •   return result; 
  • }   
  • /**  * Start the Android runtime. This involves starting the virtual machine 
  • * and calling the "static void main(String[] args)" method int the class  * named by "className". 
  • *  * 这两个参数的值分别为: 
  • * const char* className = "com.android.internal.os.ZygoteInit";  * const char* options = "start-system-server"; 
  • */  void AndroidRuntime::start(const char* className, const char* options) 
  • {  ALOGD("n>>>>> AndroidRuntime START %s <<<<<<n", 
  • className != NULL ? className : "(unknown)");   
  • /**  * 'startSystemServer == true' means runtime is obsolete and not run from 
  • * init.rc anymore, so we print out the boot start event here.  */ 
  • if (strcmp(options, "start-system-server") == 0) {  const int LOG_BOOT_PROGRESS_START = 3000; 
  • LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));  } 
  •   // 设置ANDROID_ROOT环境变量 
  • const char* rootDir = getenv("ANDROID_ROOT");  if (rootDir == NULL) { 
  • rootDir = "/system";  if (!hasDir("/system")) { 
  • LOG_FATAL("No root directory specified, and /android dose not exist.");  return; 
  • }  setenv("ANDROID_ROOT", rootDir, 1); 
  • }   
  •   JniInvocation jni_invocation; 
  • jni_invocation.Init(NULL);  JNIEnv* env;