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:
- [java] view plaincopypublic class Process {
- ......
- private static int startViaZygote(final String processClass,
- final String niceName,
- final int uid, final int gid,
- final int[] gids,
- int debugFlags,
- String[] extraArgs)
- throws ZygoteStartFailedEx {
- int pid;
- synchronized(Process.class) {
- ArrayList argsForZygote = new ArrayList();
- // --runtime-init, --setuid=, --setgid=,
- // and --setgroups= must go first
- argsForZygote.add("--runtime-init");
- argsForZygote.add("--setuid=" + uid);
- argsForZygote.add("--setgid=" + gid);
- if ((debugFlags & Zygote.DEBUG_ENABLE_SAFEMODE) != 0) {
- argsForZygote.add("--enable-safemode");
- }
- if ((debugFlags & Zygote.DEBUG_ENABLE_DEBUGGER) != 0) {
- argsForZygote.add("--enable-debugger");
- }
- if ((debugFlags & Zygote.DEBUG_ENABLE_CHECKJNI) != 0) {
- argsForZygote.add("--enable-checkjni");
- }
- if ((debugFlags & Zygote.DEBUG_ENABLE_ASSERT) != 0) {
- argsForZygote.add("--enable-assert");
- }
- //TODO optionally enable debuger
- //argsForZygote.add("--enable-debugger");
- // --setgroups is a comma-separated list
- if (gids != null && gids.length > 0) {
- StringBuilder sb = new StringBuilder();
- sb.append("--setgroups=");
- int sz = gids.length;
- for (int i = 0; i < sz; i++) {
- if (i != 0) {
- sb.append(',');
- }
- sb.append(gids[i]);
- }
- argsForZygote.add(sb.toString());
- }
- if (niceName != null) {
- argsForZygote.add("--nice-name=" + niceName);
- }
- argsForZygote.add(processClass);
- if (extraArgs != null) {
- for (String arg : extraArgs) {
- argsForZygote.add(arg);
- }
- }
- pid = zygoteSendArgsAndGetPid(argsForZygote);
- }
- }
- ......
- }
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.