Source code analysis of Android Application Process Startup Process (3)

Source: Internet
Author: User

The above mDriverFD is the open descriptor of the device file/dev/binder. If the device file is successfully opened, its value is greater than or equal to 0. Therefore, its return value is true.

Return to the Process. start function, which calls the startViaZygote function for further operations.

Step 3. Process. startViaZygote

This function is defined in the frameworks/base/core/java/android/OS/Process. java file:

 
 
  1. [java] view plaincopypublic class Process { 
  2. ...... 
  3. private static int startViaZygote(final String processClass, 
  4. final String niceName, 
  5. final int uid, final int gid, 
  6. final int[] gids, 
  7. int debugFlags, 
  8. String[] extraArgs) 
  9. throws ZygoteStartFailedEx { 
  10. int pid; 
  11. synchronized(Process.class) { 
  12. ArrayList argsForZygote = new ArrayList(); 
  13. // --runtime-init, --setuid=, --setgid=, 
  14. // and --setgroups= must go first 
  15. argsForZygote.add("--runtime-init"); 
  16. argsForZygote.add("--setuid=" + uid); 
  17. argsForZygote.add("--setgid=" + gid); 
  18. if ((debugFlags & Zygote.DEBUG_ENABLE_SAFEMODE) != 0) { 
  19. argsForZygote.add("--enable-safemode"); 
  20. if ((debugFlags & Zygote.DEBUG_ENABLE_DEBUGGER) != 0) { 
  21. argsForZygote.add("--enable-debugger"); 
  22. if ((debugFlags & Zygote.DEBUG_ENABLE_CHECKJNI) != 0) { 
  23. argsForZygote.add("--enable-checkjni"); 
  24. if ((debugFlags & Zygote.DEBUG_ENABLE_ASSERT) != 0) { 
  25. argsForZygote.add("--enable-assert"); 
  26. //TODO optionally enable debuger 
  27. //argsForZygote.add("--enable-debugger"); 
  28. // --setgroups is a comma-separated list 
  29. if (gids != null && gids.length > 0) { 
  30. StringBuilder sb = new StringBuilder(); 
  31. sb.append("--setgroups="); 
  32. int sz = gids.length; 
  33. for (int i = 0; i < sz; i++) { 
  34. if (i != 0) { 
  35. sb.append(','); 
  36. sb.append(gids[i]); 
  37. argsForZygote.add(sb.toString()); 
  38. if (niceName != null) { 
  39. argsForZygote.add("--nice-name=" + niceName); 
  40. argsForZygote.add(processClass); 
  41. if (extraArgs != null) { 
  42. for (String arg : extraArgs) { 
  43. argsForZygote.add(arg); 
  44. pid = zygoteSendArgsAndGetPid(argsForZygote); 
  45. ...... 

This function places the parameters of the created process in the argsForZygote list. For example, the parameter "-- runtime-init" indicates that the runtime Library is to be initialized for the newly created process, and then calls the zygoteSendAndGetPid function for further operations.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.