Previously, we called the Process. start function to create a new Process for the application.
Note that the first parameter is "android. app. activityThread ", this is the Java class to be loaded during process initialization. After this class is loaded to the process, the static member function main in it will be used as the entry point of the process, we will see it later.
Step 2. Process. start
This function is defined in the frameworks/base/core/java/android/OS/Process. java file:
- [java] view plaincopypublic class Process {
- ......
- public static final int start(final String processClass,
- final String niceName,
- int uid, int gid, int[] gids,
- int debugFlags,
- String[] zygoteArgs)
- {
- if (supportsProcesses()) {
- try {
- return startViaZygote(processClass, niceName, uid, gid, gids,
- debugFlags, zygoteArgs);
- } catch (ZygoteStartFailedEx ex) {
- ......
- }
- } else {
- ......
- return 0;
- }
- }
- ......
- }
Here, the supportsProcesses function returns true, which is a Native function, implemented in the frameworks/base/core/jni/android_util_Process.cpp file:
- [Cpp] view plaincopyjboolean android_ OS _Process_supportsProcesses (JNIEnv *
- Env, jobject clazz)
- {
- Return ProcessState: self ()-> supportsProcesses ();
- }
- ProcessState: supportsProcesses functions are defined in the frameworks/base/libs/binder/ProcessState. cpp file:
- [Cpp] view plaincopybool ProcessState: supportsProcesses () const
- {
- Return mDriverFD> = 0;
- }
The mDriverFD is the identifier of the/dev/binder device file. 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.