From: http://blog.csdn.net/maxleng/article/details/5508372
Android startup process details
Android has four steps to start from Linux;
(1) Start the INIT process
(2) Native Service Startup
(3) system server, Android Service Startup
(4) Start home
The overall startup framework is shown in the following figure:
Step 1: initial process (System/CORE/init)
INIT process, which is a user-level process started by the kernel. After the kernel is started by itself (it has been loaded into the memory, started to run, and initialized to all the device drivers and data structures), it starts a user-level program init, complete the boot process. Init is always the first process.
Init. RC
Init. Marvell. RC
Together with the INIT process, several basic services are established based on the init. RC and init. XXX. RC script files:
...
In the end, init does not exit, but acts as the property service function.
1.1 script file
Init @ system/CORE/init
Init. C: parse_config_file (init. Rc)
@ Parse_config_file (init. marvel. Rc)
Parsing script files: init. RC and init. xxxx. RC (hardware platform related)
Init. RC is the initialization script specified by Android (Android init language, system/CORE/init/readme.txt)
The script contains four types of statements:
- Actions
- Commands
- Services
- Options.
1.2 Service Startup Mechanism
Let's take a look at how init parses the. RC file to enable the Service.
(1) Open the. RC file and parse the file content @ system/CORE/init. c
Place service information in service_list. @ System/CORE/init parser. c
(2) restart_service () @ system/CORE/init. c
Service_start
Execve (...). Create a service process.
Step 2 zygote
The servicemanager and zygote processes lay the foundation for Android. The zygote process creates a real Android runtime space. The initialized services are all navtive services. In the. RC Script file, the description of zygote is as follows:
Service zygote/system/bin/app_process-xzygote/system/bin -- zygote -- start-system-Server
So zygote starts from main (...) @ Frameworks/base/cmds/app_main.cpp.
(1) Main (...) @ Frameworks/base/cmds/app_main.cpp
- Create a Java Runtime
- Runtime. Start ("com. Android. Internal. OS. zygoteinit", startsystemserver );
(2) runtime.start@AndroidRuntime.cpp
- Create a virtual machine
- Run: COM. Android. Internal. OS. zygoteinit: main function.
(3) Main () @ com. Android. Internal. OS. zygoteinit // zygote.
- Registerzygotesocket (); // register the listen Port
- Startsystemserver ();
- Go to the zygote service framework.
After these steps, zygote has been established and uses Socket Communication to receive activitymanangerservice requests and fork applications.
Step 3: System server
The startSystemServer@com.android.internal. OS .ZygoteInit fork a process on zygote: COM. Android. server. systemserver. So systemserver @ (systemserver. Java) was created. All service cycle frameworks of Android are built on systemserver @ (systemserver. Java. The circular structure is not visible in systemserver. Java, but the init2 implementation function is created, a lot of services are created, and addservice is sent to service manager.
Main () @ COM/Android/Server/systemserver
{
Init1 ();
}
Init1 () is implemented in the native space (com_andoird_server_systemserver.cpp ). As soon as we look at this function, we can see that init1-> system_init () @ system_init.cpp
In system_init (), we can see the closed loop management framework.
{
Call "com/Android/Server/systemserver", "init2"
.....
Processstate: Self ()-> startthreadpool ();
Ipcthreadstate: Self ()-> jointhreadpool ();
}
Init2 () @ systemserver. Java sets up all the services to be used in Android.
This init2 () creates a thread to create the new service and addservice.
Step 3 Start home
In the second half of the ServerThread@SystemServer.java, we can see that the system after starting all the android services, do such actions:
(1) Use XXX. systemready () to notify each service. The system is ready.
(2) especially for activitymanagerservice. systemready (callback)
Widget. wallpaper, Imm (input method) and other ready notifications.
Home is created during the activitymanagerservice. systemready () notification process. The following is the pseudocode of activitymanagerservice. systemready:
Systemready () @ activitymanagerservice. Java
Resumetopactivitylocked ()
Starthomeactivitylocked (); // if it is the first, start homeactivity.
Startactivitylocked (...) Category_home