1.Android system architecture
Android system architecture is divided into five layers, from top to bottom are the application layer, application framework layer, system runtime layer, hardware abstraction layer and Linux kernel layer.
The application layer
Applications built into the system as well as non-system level applications belong to the application layer. Responsible for direct interaction with users, usually developed in Java.
Application Framework Layer (Java Framework)
Application framework layer for developers to provide the API required to develop applications, we usually develop applications are called this layer provided by the API, of course, including the system application. This layer is written in Java code and can be called the Java Framework. Let’s look at the major components that this layer provides.
The name of the | Functional description |
---|---|
Activity Manager | Manage the individual application lifecycle and the usual navigation fallback functionality |
Location Manager | Provide location and location function services |
Package Manager | Manage all applications installed on the Android system |
Notification Manager | Enables applications to display custom prompts in the status bar |
Resource Manager | Provides a variety of non-code resources used by the application, such as localized strings, images, layout files, color files, and so on |
Telephony Manager | Manage all mobile device functions |
Package Manager | Manage all applications installed on the Android system |
Window Manager | Manage all open window programs |
Content Providers | Enables data to be shared between different applications |
View System | Building the basic components of an application |
Table 1
System Runtime Layer (Native)
The system runtime layer is divided into two parts, namely C/C++ program library and Android runtime library. Here are some of them.
1. The C/C + + libraries
C/C++ libraries can be used by different components of the Android system and provide services to developers through the application framework. The main C/C++ libraries are listed in Table 2 below.
The name of the | Functional description |
---|---|
OpenGL ES | 3D drawing function library |
Libc | Standard C system function library inherited from BSD, customized for embedded Linux-based devices |
Media Framework | Multimedia library, supporting a variety of common audio and video formats recording and playback. |
SQLite | A lightweight relational database engine |
SGL | The underlying 2D graphics rendering engine |
SSL | The secure socket Layer (SSL) is a security protocol that provides security and data integrity for network communication |
FreeType | A portable font engine that provides a unified interface to access files in multiple font formats |
Table 2.
2.Android Runtime library
The runtime libraries are divided into core libraries and ART(after system 5.0, the Dalvik VIRTUAL machine was replaced by ART). The core library provides most of the functionality of the Java language core library so that developers can write Android applications using the Java language. In contrast to the JVM, the Dalvik VIRTUAL Machine is customized for mobile devices, allowing multiple instances of the virtual machine to run simultaneously in limited memory, and each Dalvik application to execute as a separate Linux process. A separate process prevents all programs from being shut down in the event of a virtual machine crash. The mechanism of ART that replaces Dalvik VIRTUAL Machine is different from Dalvik. In Dalvik, the bytecode needs to be converted into machine code by the just-in-time compiler every time an application is run, which slows down the efficiency of the application, while in ART, the bytecode is precompiled into machine code when the application is first installed, making it a truly native application.
Hardware Abstraction Layer (HAL)
Hardware abstraction layer is located between the operating system kernel and hardware circuit of the interface layer, its aim is to use hardware abstraction, in order to protect the hardware manufacturers of intellectual property rights, it hides the hardware interface of the details of a particular platform, provide virtual operating system hardware platform, make its have hardware independence, can be transplanted on multiple platforms. From the point of view of software and hardware testing, the software and hardware testing can be completed based on the hardware abstraction layer, which makes it possible to carry out the software and hardware testing in parallel. In plain English, the actions that control hardware are placed in a hardware abstraction layer.
The Linux kernel layer
The core system services of Android are based on the Linux kernel, and some special drivers for Android are added on this basis. System security, memory management, process management, network protocol stack and driver model all depend on this kernel. Android system five layers of architecture on this, understand the above knowledge of the later analysis of the system source code has a great help.
2.Android system source directory
We must first understand the Android system source directory, to lay the foundation for later source code learning. To read the source code, you can visit androidxref.com/ to read the system source code. Of course, it is best to download the source code. Download the source code can use open source software, tsinghua university Android mirror mirror stations: mirrors.tuna.tsinghua.edu.cn/help/AOSP/. If you feel that trouble can also find domestic web disk download, recommend the use of the Baidu web disk address download: pan.baidu.com/s/1ngsZs, it provides a number of Android versions of the source download.
The overall structure
Each version of the source directory is basically similar, if the compiled source directory will add an out folder, used to store the compiled files. The root directory structure of Android7.0 is described in the following table.
Android source code root directory | describe |
---|---|
abi | Application binary interface |
art | New ART runtime environment |
bionic | System C library |
bootable | Start boot-related code |
build | Store basic development package configurations such as system build rules and Generic |
cts | Android Compatibility test Suite standards |
dalvik | Dalvik virtual machine |
developers | Developer directory |
development | Application development related |
device | Device Configuration |
docs | Reference Document Catalog |
external | Open source module related files |
frameworks | Application framework, the core part of the Android system, written by Java and C++ |
hardware | This is mainly code at the hardware abstraction layer |
libcore | Core library related files |
libnativehelper | Dynamic library, the foundation of JNI library |
ndk | Ndk-related code to help developers embed C/C++ code in their applications |
out | The code output is in this directory after compilation |
packages | Application package |
pdk | Plug Development Kit stands for Local Development Kit |
platform_testing | The platform test |
prebuilts | Precompiled resources for x86 and ARM architectures |
sdk | Application package |
packages | SDK and emulator |
system | Underlying file system libraries, applications, and components |
toolchain | Toolchain file |
tools | Tool file |
Makefile | A global Makefile that defines compilation rules |
Table 3 As can be seen from Table 3, the system source code is clearly classified, and the content is huge and complex. Next, analyze the content in Packages, which is the application layer part.
Application layer
The application layer is the top layer of the entire Android system, where developers develop applications and built-in applications. The Packages directory in the source root corresponds to the system application layer. Its directory structure is shown in Table 4.
Packages directory | describe |
---|---|
apps | Core application |
experimental | Third Party applications |
inputmethods | Input method directory |
providers | Content Provider directory |
screensavers | The screen saver |
services | Communication service |
wallpapers | The wallpaper |
Table 4
Packages directories contain core applications, third-party applications, input methods, and so on. These applications run in the system application layer. Packages directories correspond to the system application layer.
Apply the framework layer section
Application framework layer is the core part of the system. On the one hand, it provides interfaces to the application layer, and on the other hand, it connects with C/C++ libraries and hardware abstraction layer. The main implementation codes of the application framework layer are in the /frameworks/base and /frameworks/av directories, where the structure of the /frameworks/base directory is shown in Table 5.
/ frameworks/base directory | describe | / frameworks/base directory | describe |
---|---|---|---|
api | Define the API | cmds | Important commands include am and app_proce |
core | Core library | data | Font and sound data files |
docs | The document | graphics | Graphic image correlation |
include | The header file | keystore | Related to data signature certificates |
libs | library | location | Geolocation library |
media | Multimedia correlation library | native | The local library |
nfc-extras | NFC related | obex | Bluetooth transmission |
opengl | 2 d / 3 d graphics API | packages | Setup, TTS, VPN program |
sax | The XML parser | services | System services |
telephony | Telephone communication management | test-runner | Test tool correlation |
tests | Relevant test | tools | tool |
wifi | Wifi wireless network |
Table 5
C/C++ library section
The C/C++ libraries in the system runtime layer (Native) have various types and powerful functions. The C/C++ libraries are not completely in a directory. Here, several common and more important C/C++ libraries are given.
Directory location | describe |
---|---|
bionic/ | System C library developed by Google, open source under BSD license. |
/frameworks/av/media | System media library |
/frameworks/native/opengl | Third party graphics rendering library |
/frameworks/native/services/surfaceflinger | Graphics display library, mainly responsible for graphics rendering, superposition and drawing and other functions |
external/sqlite | C++ implementation of lightweight relational database SQLite |
Table 6 covers the C/C++ libraries, and the rest is shown in Table 3: the Android runtime library code is placed in the art/ directory. The code of hardware abstraction layer is in the Hardware/directory, which is the part that the mobile phone manufacturer changes the most, and it will be implemented differently according to the hardware platform adopted by the mobile phone terminal.