Android system start-up process

Source: Internet
Author: User

When we get an Android smartphone, from the switch on, to the app that we can use, what does this boot process do?


System power-up

When the Android system is powered on, the CPU resets, the program pointer points to the startup address, the executable code that reads the launcher from that address runs directly, or the executable code and data are loaded into the CPU's built-in RAM to run again.

CPU reset, in fact, in the instant the power is on, the register and each pin in the CPU will be set to the initial state, and the program pointer to the location of the boot program.

This piece of code, placed in a PC, is called the BIOS, and embedded systems such as Android are called bootloader.

Bootloader Boot Program

Through the bootloader boot program, you can initialize the hardware device, set up the memory space map, prepare the environment for the operating system kernel, and complete the loading and launching task of the whole system.

Bootloader is to support interactive operation, the general brush machine will be used in the FastBoot mode, that is, after the bootloader startup, according to the user input instructions (on the phone with volume keys, home health and other operations), stay in the current state.

Under normal circumstances, when the bootloader program executes, it will start loading the Android operating system.

Load kernel

We know that the kernel of the Android OS is actually the Linux kernel. When the Bootlader boot is started, it enters the Linux kernel boot phase.

The boot phase initializes the kernel and device drivers, then starts the kernel, mounts the file system, and finally initiates the user-space process.

Init program

The INIT program is the first process in user space. It is responsible for parsing a configuration file called Init.rc, which initiates some service processes running on the bottom of the Android system.

The init.rc file defines a different action and service, in the following format:

Action

On boot     ...     Class_start Core     Class_start Main

The action is defined with the keyword on, and the boot is followed by a trigger condition, as the action above indicates what to do when Android starts (boot).

Service

Service Servicemanager/system/bin/servicemanager #声明一个service, while ServiceManager is the name of the     class core                          #optioin, This service belongs to the core class user     system                         $option, which belongs to the System user     Group system

The service is defined by the keyword Servie, followed by its name and the file it launches, as above, the/system/bin/serviemanager file is executed and named ServiceManager.

As above, the Class_start core after the Action boot is the service that the INIT program will start when it is powered on.

These services include UEVENTD, ServiceManager, void, zygote, INSTALLD, Ril-daemon, etc., which we generally call daemons.

The INIT program also opens the property service, storing some information about the global system settings of the Android system.

Finally, when all the actions and services are started, the INIT program enters an infinite loop, listens to events that occur in the system, and handles events such as restarting some service.

ServiceManager

ServiceManager is one of the daemons that init program initiates, which is the basis of binder communication in Android.

ServiceManager provides the ability to register and retrieve services. Each service that is started in the zygote subprocess System_server (below) will be registered with ServiceManager and managed uniformly by ServiceManager. It is important to note that ServiceManager itself is also a service, so it also registers itself with itself.

And ServiceManager started the process by doing three things:

1) The binder device is opened and the binder device is mapped to the kernel space, because the kernel space is the area shared by all processes, so the use of this area can realize the sharing of resources among different processes to achieve interprocess communication.

2) ServiceManager itself will become a contextmanager, that is, the above-mentioned registration to themselves, responsible for the various service context management.

3) The final ServiceManager will also enter an infinite loop.

Zygote

Zygote is also one of the services launched by the INIT program, but it is the first Dalvik virtual machine in the Android world. After that, all Dalvik virtual machines were hatched by zygote, because every app in Android has its own process, and each process has a dalvik virtual machine, and if each application creates a virtual machine, it's inefficient, By replicating zygote, not only can you increase the speed of the creation, but you can also share the resources of the system and the framework, greatly increasing the speed of application startup.

After the zygote is started

1) First, a socket is created to wait for a client request.

2) then create its first child thread, called System_server. System_server will open the native service and Java service of the Android system.

The native service is a shared library implemented using JNI, while the Java service is implemented through the Java language Activitmanagerservice, all at this stage by system_ The server starts and registers into a service process called ServiceManager.

After the Activitymanagerservice is started, it enters a state called system ready, and before it reaches the state of the system ready, it launches an application called launcher. This launcher is the home desktop that was seen when the Android system was launched successfully.

In the Systemready state, it will communicate with the socket at the beginning of zygote, telling Zygote that everything is ready.

3) Zygote know that it has started successfully, it begins to enter an infinite loop, waiting for the request to arrive on the socket.

At this point, from the moment the phone is power, to the loading of the kernel, to the final display of the home desktop the entire process is over, and this article would like to introduce the same.

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.