Android 5.0 kernel and source code learning (2)-source code download and system startup process analysis, android5.0

Source: Internet
Author: User

Android 5.0 kernel and source code learning (2)-source code download and system startup process analysis, android5.0

I,AndroidSource code download

The last time I briefly introduced the hierarchical structure of the Android system, I started to figure it out-download the source code and analyze the source code!


So where is the Android source code? Of course is Google's official website, download method official website is also very detailed, but do China's wall is relatively thick, so the above method is useless, of course, some are useful, address: http://source.android.com/source/downloading.html


There are still some domestic websites on Google's official website. If you don't talk much about it, start the process directly:


Tools and environment: vmvm + Ubantu14 System

Step 1: Ubantu requires the git tool: sudoapt-get install git

Step 2: Download and configure the repo information:

A) mkdir ~ /Bin

PATH = ~ /Bin: $ PATH

Git clonegit: // aosp.tuna.tsinghua.edu.cn/android/git-repo.git

B) copy the repo file in git-repo obtained in step a to the bin directory.

Cpgit-repo/repo ~ /Bin/

C) modify the repo file and REPO_URL)

Sudo gedit ~ /Bin/repo

Modify the URL in this file (this is from Tsinghua University)

REPO_URL = 'git: // aosp.tuna.tsinghua.edu.cn/android/git-repo'

Step 3: Initialize repo and start downloading

Mkdir anroid

Cd android

Git config-global user. email "youremail@jileniao.net"

Git config -- global user. name "Your Name"

Repo init-ugit: // aosp.tuna.tsinghua.edu.cn/android/platform/manifest-B android-5.0.2_r1

Repo sync

 

Download result proof (5.0 source code, about 32 GB ):

 

II. Introduction to the Android source code package

The order of use will be roughly introduced one by one (there may be errors and details, and we will continue to follow up with the study in the future)

(1) abi: applicationbinaryinterface, application binary Interface

(2) art: AndroidRuntime, which is the new AOT Vm of 5.0.

(3) bionic: Bionic is the C/C ++ library of Android (why not use glibc? Small Size, copyright)

(4) bootable: boot guide code

(5) build: Basic Development Configuration packages such as system compilation rules and generic

(6) cts: Android compatibility test suite Standard

(7) dalvik: Virtual Machine

(8) developers: Unknown role

(9) development: routines and tools required by developers

(10) device: device-related code. The function is unknown. It contains the Google Samsung Motorola htc directory.

(11) docs: This document describes how to contribute to android open source.

(12) external: some open-source components used, such as AES, Web servers, and compression tools

(13) frameworks: the second layer. The core framework (including the core javaapi) is the framework of Android applications.

(14) hardware: mainly hardware Adaptation Layer HAL code

(15) libcore: Layer 3 core library

(16) libnativehelper: the function is unknown. There is only one sentence. It supports the function of the Android class library.

(17) ndk: ndk (nativedevelopment kit) development

(18) packages: A package contains many apps, such as alarm clocks, browsers, and input methods.

(19) pdk: PlatformDevelopment Kit, which is prepared for OEM

(20) prebuilts: resources pre-compiled in x86 and arm Architectures

(21) sdk: This is not required. The software development kit contains APIs and Simulators of different versions.

(22) system: system package, underlying file system library, applications, and components-C language, which should be focused on!

(23)Tools: tools, including fat32lib and gradle

The engineering structure of Android 5.0 is different from that of the previous version. Do not worry about what is missing or what is missing. After the package structure is simple, you can start to focus on a part. Next, you need to take the Android System startup process under the System package.

3. Introduction to the System package of Android source code

The Android source code System package is as follows, and a package overview is included. The focus of the research is the Core package.

 


Iv. Detailed explanation of the Android Startup Process

 1, Brief description

The Android system can be seen as a branch of Linux operating on the Linux kernel. Therefore, the boot process starts from the Linux BootLoader to the Android system after the Linux kernel is fully started, the main code of the Android startup process is in the android/system/core/init package. Android has done a lot of things during the startup process, but there are some key nodes, which are the steps described below.


2. Step 1 of Android startup: init process

After the Linux kernel is started, the Android ancestor-init process (PID: 0) will be started. What does this process do? In general, according to the content in the init. rc Script, some directories are mounted, some environment variables are configured, and many services are started.

(1) What is in init. rc?

Init. rc is located under android/system/core/rootdir, which defines some events and services (action, command, service, options ), its syntax rules are described in the android/system/core/init/readme.txt file.

(2)init.rc (more specifically, readme.txt is detailed ):

A) the syntax of action is as follows:

On <trigger>

<Command>

<Command>

B) Service Syntax:

Service <name> <pathname> [<argument>] *

<Option>

<Option>

...

3. Step 2 of Android startup: The init process starts the key process: ServiceManager Process

The Init process starts many key processes. ServiceManager is one of them. It can be found from the name that it is a Service manager that manages Service Registration and listening for Service requests. That's right, here, the Service is one of the four main components of Android. Is it open-minded?

It is defined in the/home/wang/android/frameworks/native/cmds/servicemanager package. It can be understood as the "DNS server" in the Binder mechanism ", resolves the name of the Binder service registration to the value provided by the underlying Binder driver. The following is how to start the init. rc Script:

Service servicemanager/system/bin/servicemanager

Class core-classification is the core service

User system

Group system

Critical -- restart the device when the device exits four times in four minutes. Does it seem critical?

Onrestartrestart healthd -- it also restarts other services when it restarts

Onrestartrestart zygote

Onrestartrestart media

Onrestartrestart surfaceflinger

Onrestartrestart drm


4. Step 3 of Android startup: Start the key process of the init process: Zygote Process

Zygote actually means a fertilized egg. Just like its name, it is used to generate a new process. The start point is different from the previous version. The android command is run on android/system/core/rootdir/init. zygoteXXX. in rc, XXX is 32 and 64 are changed based on different platforms. The code for init. zygote64.rc is as follows:

Service zygote/system/bin/app_process64-Xzygote/system/bin -- zygote -- start-system-server

Class main

Socket zygotestream 660 root system

Onrestart write/sys/android_power/request_state wake

Onrestart write/sys/power/state on

Onrestartrestart media

Onrestartrestart netd

The first sentence is very important. The split is as follows:

Service name: zygote

PATH (or program) to be started:/system/bin/app_process64-Xzygote

Startup parameters:/system/bin -- zygote -- start-system-server

 

Well, the question is, why isn't the start path end like servicemanager itself?

 

This path indicates that it is not a separate process, but in the process app_process64-Xzygote, its source code is located in android/frameworks/base/cmds/app_process/app_main.cpp.

 

Okay, it's not a problem? So, let's say what this app_process64-Xzygote has done. I think there are three key operations: a) Start Android runtime B) create a socket interface to receive Socket requests from ActivityManagerService to create a new process c) Start SystemServer

 

5. Step 4 of Android: SystemServer Process

In the previous step, the key step of zygote is to start the SystemServer process. What are the special features of this process? The SystemServer process is responsible for starting key services of the system, such as PackageManagerService and ActivityManagerService, which are the package management service and Application Component Management Service. This will not be detailed for the moment.

 

6. Step 5 of Android: Start the Home interface

After the preceding steps are completed, the last step is taken to start the Home interface. Well, the Android system is fully started.

 

V. Summary

This article mainly introduces the Engineering Package Structure of the Android source code and the Startup Process of the Android system, which is not detailed in some places. In the future, we will continue to deepen our study, the next article has not decided what to read yet, haha.

 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.