Android framework Startup Process

Source: Internet
Author: User

When the embedded device starts, bootloader loads the Linux kernel. After the Linux kernel starts, it runs the first user-level process init. This process enters the Android world. Therefore, Android is a framework rather than a kernel.
When a Linux system is started, "init =/init" is usually set in the kernel boot parameters. When the underlying Linux kernel of Android is started, a user-level process init is executed, this process is the parent process of all processes, process number is 1, here is the portal of the entire android framework, INIT process is the parent process of all processes in Android. The init executable program is usually located in/xbin/init, And the INIT program source code is in the android source code system/CORE/init. Our analysis starts from main and enters the android framework.

/System/CORE/init. C # Main

The INIT process is a standard Linux Process. It can use the APIS provided by the Linux kernel or the standard library.

The INIT process is divided into two parts: boot and daemon,

Int main (INT argc, char ** argv)
{
/* Boot part */
 
For (;;){
/* Daemon part */
}
}
First, execute the boot part, which creates the basic directory of the file system, including/dev,/proc,/sys, and so on.
Initialize the kmsg log module, which is used to obtain the Linux kernle log information.

The final parsing of the boot part is the init. RC configuration file, init_parse_config_file ("/init. RC");/system/CORE/rootdir/init. RC
For more information about the init. RC syntax, see/system/CORE/init/readme.txt.

This file defines a series of actions and services. Which actions are performed during system startup? You can set environment variables,
Run a Linux Command to start the service and mount the file system.
Action is a sequence of commands. Each action defines a command. Action has a trigger mechanism and under what circumstances to execute this command. When an event matches the Starting Mechanism of this action, this action will be added to the action execution queue for execution.
Parse_service puts all parsed actions in the action_list linked list, And parse_action places the service in service_list.

Run the following command to traverse action_list at the end of boot:
(1) lele_init_action: Initialize the console and display the words a n d r o I d on the terminal.
(2) property_init_action
(3) set_init_properties_action
(4) property_service_init_action

Daemon part:
For:
(1) start the service specified in service_list. All other android services are started in service mode, such as virtual machines, servicemanager, and mediaserver,
Each Service corresponds to a sub-process of the INIT process.

(2) continuously call poll to monitor three FD statuses
Property_set_fd
Signal_recv_fd
Keychord_fd
Property_set_fd explanation:
As a system service, system configurations and statuses are managed. All these system configurations and statuses are properties ). Property is a key/value combination, and the key and value are both string types. Many applications and libraries in androd depend directly or indirectly on the attribute system, and thus determine the behavior during the runtime. For example, the adbd process determines whether or not it is currently running in the simulator through attributes. For example, the Java. Io. file. pathseparator method returns the value stored in the property service. property_service_init_action is called in the boot stage and Android is initialized.
Attribute system. The system has fixed attributes under the directory "/data/property. The INIT process manages all data in the android attribute system. Other processes use the ashmem drive read-only attribute system provided by Android.
Refer:

Http://hi.baidu.com/runsheng2005/blog/item/84734fd6ac12363b06088b1f.html

Signal_recv_fd:
Process the sub-process signal. waitpid waits for the sub-process to exit and cleans up the resources. If the sub-process is a service, restart the sub-process.
Keychord_fd:
Monitor input device events and start corresponding services.

So far, the INIT process has been started.

The preceding daamon section mentions that service_list stores the startup items configured in init. Rc. Some main services provided to the upper layer by Android are designated and started here.

Example: servicemanager
Service servicemanager/system/bin/servicemanager
User System
Critical
Onrestart restart zygote
Onrestart restart Media
-------------------- # Environment Virtual Machine startup during Android Runtime
Service zygote/system/bin/app_process-xzygote/system/bin -- zygote -- start-system-Server
Socket zygote stream 666
Onrestart write/sys/android_power/request_state wake
Onrestart write/sys/power/State on
Onrestart restart Media
Onrestart restart netd
---------------------------------
Service Media/system/bin/mediaserver # Start the multimedia service.
User Media
Group system audio camera graphics Inet net_bt net_bt_admin net_raw
Ioprio rT 4
------------------------------------------------------------------------

The INIT process starts other services by creating sub-processes. These services run as the Damon process in the background and provide services for the entire android upper-layer application.
This corresponds to the Service Section in init. RC,
It mainly includes the following parts:
(1) servicemanager: Start binder system. The IPC communication mechanism is implemented here. device/commands/binder.
(2) installd, install package daemon, device/servers/installd.
(3) Media Multimedia Service: Start audioflinger, mediaplayerservice and cameraservice, device/commands/mediaserver
(4) vodthd Bluetooth service
(5) dhcpcd Dhcp Service
(6) console, Shell, device/system/bin/ash
(7) adbd, ADB daemon process, device/tools/adbd
(8) mountd, device/system/bin/mountd
(9) flash_recovery, device/commands/recovery/mtdutils
(10) bootsound: boot sound/system/Media/Audio/UI/bootsound. The source is in device/commands/playmp3.
(11) rild, start radio interface layer daemon. device/commands/rind.

(12) zygote starts the runtime environment of Android Java and starts system server (built on a Java Virtual Machine). This sub-process is the most important service in Android, device/servers/app.

These sub-processes constitute the foundation of the android framework.

Zygote process startup process:
Zygote from main (...) @ Frameworks/base/cmds/app_main.cpp.

(1) Main (...) @ Frameworks/base/cmds/app_main.cpp
Create a VM and register the android local function.
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 // truly start the VM process zygote. /Java/Android/COM/Android/Internal/OS/zygoteinit. Java

Registerzygotesocket (); // register the listen Port
Startsystemserver (); start the sub-process of systemserver. This process is very important. It is divided into two parts: init1, init2, and init1 to start the service written in C ++, init2 starts all services at the android Java layer.

Call forksystemserver (implemented in device/Dalvik/Vm/internalnative. c) internally to start a new process,
Call Main # systemserver. Java (/frameworks/base/services/Java/COM/Android/Server/systemserver. Java ),
Init1, init2, and init1 are JNI calls. In com_android_server_systemserver.cpp, init1 is a modern code.
The specific implementation of system_init as init1,
Start the Java thread after entering init2 and start Android Java services (framesorks/base/services/Java/COM/Android/Server/systemserver. Java)

At this point, systemservice has been started and enters android.
Further analysis should be performed on various services (surfaceflinger, cameraservice., Activity
Manager ...)

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.