Introduction to the android Startup Process

Source: Internet
Author: User
Document directory
  • Overview
  • Details

In a certain aspect, we can regard android as an XWindow on Linux. Therefore, the process of starting the system will inevitably start with Linux kernel. Of course, the startup of Linux kernel is not a problem we need to discuss here.

I recently tried to add my own service in the framework layer. I have studied it before, but it is not very clear. So we can clarify our ideas. I also hope to give a good reminder to my friends who are studying this part. The Android system is huge. Therefore, to clearly understand these things, we must study its implementation mechanism.

Overview

When the Android system is started, it will first start the basic Linux system, then boot and load the Linux kernel and start the initialization process (init ). Start the Linux daemon. When you start the Linux daemon, you also need to start the zygote process. This includes initializing a Dalvik Virtual Machine instance. Class and listener required for loading socket requests. Create a virtual machine instance to manage the application process.

Initialize the runtime process after zygote. In this process, initialize and register the Service Manager.

Step 1: initial process (System \ core \ init) INIT process, which is a user-level process started by the kernel. After the kernel is started on its own, it starts a user-level program init to complete the boot process. Init. RC will be read in the first process. In this file, servicemanager, zygote… will be started ...... And other basic services. In init. c @ system/CORE/init. Parse_config_file (init. Rc) is called to parse the script file init. RC. (Init. RC is Android init language. The specific description is in./readme.txt) here.

After Android is started, after a series of loading processes, it will enter frameworks \ base \ cmds \ app_process \ app_main.cpp and then execute the main () method.

188 If (zygote ){
189 runtime. Start ("com. Android. Internal. OS. zygoteinit ",
190 startsystemserver? "Start-system-server ":"");
191} else if (classname ){
192 // remainder of argS get passed to startup class main ()
193 runtime. mclassname = classname;
194 runtime. margc = argc-I;
195 runtime. margv = argv + I;
196 runtime. Start ("com. Android. Internal. OS. runtimeinit ",
197 application? "Application": "tool ");
198} else {
199 fprintf (stderr, "error: no class name or -- zygote supplied. \ n ");
200 app_usage ();
201 log_always_fatal ("app_process: no class name or -- zygote supplied .");
202 return 10;
203}

(The com_android_internel_ OS _zygoteinit.cpp file exists in the frameworks \ base \ core \ JNI folder. In this file, use the register_com_android_internel_ OS _zygoteinit function to call the androidruntime: registernativemethods function .)

The START () method of frameworks/base/CORE/JNI/androidruntime. cpp will be called. In fact, the registration association between Android APIs and local methods is completed in the androidruntime. cpp module.

Analysis of Local method ing and registration principles corresponding to API functions at the android framework layer:

After Android is started, the registration Association of Local methods is completed when androidruntime: starregulatory is called. The static array gregjni [] of androidruntime stores the local Method Association information of each framework submodule. Each element of the array gregjni [] Stores registration-related function pointers for each module. This function pointer is used to add a large number of local functions in the sub-module to the system. Many local functions in the sub-module are also used as parameters through the static array pointed by the above function pointer. The registration Association is to register the local Method Association information of each framework sub-module stored in the static array gregjni [] to the system by calling the register_jni_process method in starregulatory.

Procedure for registering JNI: (to be continued)

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.