Android System Architecture
Android System Architecture
First Words
Due to the change of work content, I have changed to the direction of Android system, and for an Android system engineer, it is inevitable to understand the
entire system architecture of Android. This article is the beginning of the learning of the Android system, which is huge and complex, but can have a deeper and
more comprehensive understanding of Android. Let's start your Android journey!
System architecture
The Android system architecture is divided into five layers. From top to bottom, there is the application layer, the application framework layer, the system
runtime layer, the hardware abstraction layer, and the Linux kernel layer.
System Apps
Applications that are built into the system, as well as applications that are not at the system level, belong to the application layer and are responsible for
interacting directly with the user.
The application framework layer provides developers with the APIs they need to develop applications, and we in Heisei develop applications by calling the APIs
provided by this layer, including system applications. This layer is written in Java code and can be called the Java Framework.
Activity Manager Manage individual application lifecycles, as well as common navigation fallbacks
Package Manager Manage all the apps installed on the Android system
Notification Enables the app to display a custom prompt message in the notification bar
Manager
Resource Provide a variety of non-code resources used by the application, such as localized strings, images, layout files,
Manager color files, and so on
Content Provider One of the four major components of Android. Enables data to be shared between different applications
As you can see from the figure above, the system runtime layer is divided into two parts, which are the C/C++ library and the Android runtime library.
C/C++ libraries
The C/C library is used by different components in the Android system and provides services to developers through the application framework. The following
are the main C/C libraries:
Libc A standard C system library inherited from BSD, tailored specifically for embedded Linux devices
Media Multimedia library that supports recording and playback of a variety of commonly used audio and video formats
Framework
SSL Secure Sockets Layer (SSL) is a security protocol that provides security and data integrity for network
communications
Free Type A portable font engine that provides a unified interface to access files in multiple font formats
Webkit Browser web typesetting engine, including WebCore typesetting engine and JSCore engine.
name Feature description
OpenMax is a framework standard for multimedia applications, and OpenMax is divided into three layers: the first
OpenMax AL layer: OpenMax DL (Development Layer), the second layer: OpenMax IL (Integration Layer), and the third layer:
OpenMax AL (Appliction Layer)
As you can see from the figure above, the runtime library is divided into the core library and the ART.
Core Library
The core library provides most of the functionality of the Java language core library, and developers write applications in the Java language.
ART
After Android 5.0, the Dalvik virtual machine was replaced by ART. In contrast to the JVM, the Dalvik Virtual Machine (DVM) is specifically tailored for mobile
devices, allowing multiple instances of virtual machines to run simultaneously with limited memory, and each Dalvik application executes as a separate Linux
process. This prevents all programs from shutting down when the virtual machine crashes. The mechanism of ART is different from that of DVM, and every time
an application in DVM runs, the bytecode needs to be converted into machine code through a just-in-time compiler (JIT), which makes the application run less
efficiently. In ART, the system will perform sequential pre-compilation (AOT) when installing the application, and the bytecode will be pre-compiled into machine
code and stored locally, so that there is no need to perform compilation every time it runs, which improves operation efficiency.
The hardware abstraction layer is the interface layer that sits between the operating system kernel and the hardware circuits, and is designed to abstract the
hardware. In order to protect the intellectual property of hardware vendors, it hides the hardware interface details of a specific platform and provides a virtual
hardware platform for the operating system, making it hardware-agnostic and portable on multiple platforms. From the perspective of software and hardware
testing, the testing of software and hardware can be completed based on the hardware abstraction layer respectively, which makes it possible to carry out
software and hardware testing work in parallel. In layman's terms, it is to put the action of controlling the hardware in the hardware abstraction layer.
Linux Kernel
Android's core services are based on the Linux kernel layer, which provides powerful underlying drivers for various hardware of Android devices, such as
display drivers, audio drivers, camera drivers, Bluetooth drivers, Wi-Fi drivers, power management, etc. On this basis, some Android-specific drivers, such as
Binder, Alarm, and Logger, are added. The kernel is relied upon for the system's security, memory management, process management, networking stack, and
driver model.
Android version
Android 14.0 U 34
Android 13.0 T 33
Android 12.0L S 32
Android 12.0 S 31
Android 11.0 R 30
Android 10.0 Q 29
About Android source code download, you can refer to: install Ubuntu under Windows, graphical interface, download Android source code, just read this article
Monolithic structure
build Configure basic development kits such as system compilation rules and generic
development Application-related
kernel The kernel layer, including code for device drivers, hardware abstraction layers, system calls, etc
libnativehelper Dynamic library, the basis for implementing the JNI library
prebuilts Some of the resources pre-compiled under the x86 and ARM architectures
There is also an important directory vendor, which stores the vendor custom code.
The application layer is the top layer of the Android system, and the applications developed by developers and the applications built into the system are in the
application layer. The packages directory in the root directory of the source code corresponds to the system application layer.
packagesdirectory description
wallpapers wallpaper
The application framework layer is the core part of the system, which provides interfaces to the application layer to call, and communicates with C/C++ libraries
and hardware abstraction layers downward, and the main implementation code is in the frameworks/base and frameworks/av directories, and the framework
directory structure is as follows:
frameworks/base description
directory
The APEX (Android Package Executable) module is a new Android application packaging format that is used
apex to encapsulate system components and services, as well as vendor components and services, into separate
modules
boot Boot code and base class libraries for the operating system
docs documentation
errorprone Code and class libraries for error handling and exception handling
libs storehouse
mime Definition and configuration information for MIME (Multipurpose Internet Mail Extension) types
mms Code and class libraries for SMS and multimedia messaging services
omapi Open Mobile Alliance Device Provider (OMADP) API interface and class library
proto Definition and configuration information for various protocols and data structures in the system
tests Test-related
tools tool
wifi Wi-Fi
There are many types of C/C libraries at the system runtime layer, and they are powerful. The following are some of the more commonly used and important
C/C libraries.
bionic The system C library developed by Google, which is open source under the BSD license
frameworks/native/services/surfaceflinger A graphics display library that is responsible for graphics rendering, overlays, and drawing
functions
There are two ways to read the source code: online reading and local reading. Online Reading Recommendation Official: https://cs.android.com
Local reading is all about downloading the code locally and reading it through Android Studio. Here's how to read the environment configuration:
2. In the root directory of the source code, compile the idegen module
source build/envsetup.sh
mmm development/tools/idegen/
After the compilation is successful, a file will be generated in the directory. /out/host/linux-x86/framework idegen.jar
3. Execute the sh script and it will use this jar to generate the required files: .ipr
development/tools/idegen/idegen.sh