Reference: 1, Lao Luo's Android tour http://blog.csdn.net/luoshengyang/article/details/66897482,Android core analysis/HTTP Www.linuxidc.com/Linux/2011-04/33966.htm
Android System Start-up:We want to have a picturesystem architecture Diagram:
One, the above with git download the compilation process slightly off, directly to see the final product of our build. The most important product of Build is three image files, located in the/out/target/product/<product_name>/directory
ramdisk.img: The Linux kernel is mounted as a read-only partition at boot time, it contains the/init file and some configuration files. It is used to mount other system images and start the
init process.
that is, the source \system\core\init\init.c file system.img: System files, libraries, executables, and pre-built applications that contain the Android OS, will be mounted as root partitions 。 USERDATA.IMG: will be mounted as/data, containing the application-related data and user-related data.
Second, the Android system starts the process 1, ininit.cThere is a main () method in the file, with "
init_parse_config_file ("/init.rc"), which resolves this profile 2, we open
init.rcThis document, found in fact is open service-xzygote (incubator;: Hatching the whole world)
This service starts after startup
App_process.cpp, we find this file in the Mian () method of Runtime.start ("Com.android.internal.os.ZygoteInit", startsystemserver); we continue to explore
Com.android.internal.os.ZygoteInit.javaFile, the method is called in its Main method
Startsystemserver(), there is an array in this method, there is a class name in this array, string args[] = {"--setuid=1000",
"--setgid=1000",
"--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,3001,3002,3003",
"--capabilities=130104352,130104352",
"--runtime-init",
"--nice-name=system_server",
"
Com.android.server.SystemServer"That the main purpose of this method is to load theCom.android.server.SystemServer.java This classOK, let's go on to find the main () method in this class, we found that the call through JNI
init1 ()Method, the Init1 () method is the function of opening the native world
The function of the Init1 () method is to open the native World Init2 () method to open the Java world
Init1 () code in the source \frameworks\base\services\jni\
Com_android_server_systemserver.cpp
Core code in System_init ()------->system_init.system_init ()We continue to find
system_init.cpp in System_init () so this native the world to start up,
The statement is then called in this method:
runtime->callstatic ("Com/android/server/systemserver", "init2");That started the Java world after launching the native world.
Let's take a look at the Init2 () method.
123456 |
public
static
final
void
init2() {
Slog.i(TAG,
"Entered the Android system server!"
);
Thread thr =
new
ServerThread();
thr.setName(
"android.server.ServerThread"
);
thr.start();
}
|
we found the Serverthread extends thread class in Systemserver.java.
then let's take a look at its Run method:
Serverthread.run () {
...
looper.prepare ();//
a whole bunch of service and manager
Activity Manager Package
manager:// Scan system for all APK (time consuming operation)
}
here is a clear picture to show:
Take a look at the extra bitZygote (incubation) process:The following is an excerpt from the Web blog, the original author and blog address forgot [Sorry!]----------------------------------------------------------------------------------------------------------- -----------------------
The Android platform is designed for handheld embedded devices, and most handheld devices work with batteries, which themselves have very limited resources.
Therefore, the handheld device requires embedded system platform must provide an efficient operating environment, on the one hand to improve the utilization of equipment resources, on the other hand, as long as possible to increase the use of equipment time.
Android Phone user interaction with the device is summed up as: Open the app and switch to the next app;
To effectively reduce the burden of the system, Android uses the Zygote (hatching) process to start a new process (open a new application).
The init process is the first process that runs in user space after the system starts , and the init process starts the zygote process after the various daemons that are required to run the system are started;
After the zygote process starts, Android services and applications have the process start running.
The following is the process initiation of a simulator, the process number of zygote is 33, and its parent process number is 1 (init process);
The following application's parent process number is 33, indicating that all applications are generated by the zygote process.
Google described the platform features when releasing the Android platform:
Zygote is a major feature of the Android system, with the COW (copy on Write) method to maximize the reuse of processes running in memory and to effectively reduce the amount of memory used through library sharing .
Here's a closer look at the process of hatching a new process in the zygote process:
The zygote process calls the fork () function to create a zygote ' child process zygote ' share the code area and connection information of the parent process zygote.
As shown, the Fork () Orange arrow to the left is the zygote process, and the right is the created zygote ' subprocess;
The zygote ' child process then hands the execution process to the application A,android program to start running.
The newly generated application A will use the connection information for the library and resources that already have the zygote parent process, so it runs fast.
In addition, for zygote startup, the DVM is initialized and run, and then the required classes and resources are loaded into memory.
The fork () is then called to create the zygote ' child process, and then the child process dynamically loads and runs application A.
running application A uses Zygote to initialize and start the DVM code that runs , speeding up the operation by using classes and resources that have been loaded into memory.
The above is just an abstract process, no specific to the implementation of the code layer, if you want to analyze this part of the source code, we recommend the "Android Framework Secret" this book.
Android System Launcher--app launcher--interface display (i)