You are on page 1of 9

Android system architecture

Posted On 2023-11-06 07:43:20 105 0 report

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!

Recommended Android system dry goods blogger: Gityuan

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.

Java API Framework

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.

It provides the following components:

name Feature description

Activity Manager Manage individual application lifecycles, as well as common navigation fallbacks

Location Manager Provide geolocation and location function services

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

Telephony Manage all mobile device features


Manager

Window Manager Manage all window programs

Content Provider One of the four major components of Android. Enables data to be shared between different applications

View System Build the basic components of your application

 

System Runtime Layer (Native)

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:

name Feature description

OpenGL ES 3D Drawing Library

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

SQLite Lightweight relational data engine

SGL The underlying 2D graphics rendering engine

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)

Android Runtime Library

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.

Hardware Abstraction Layer (HAL)

 
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

Version number code name API

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

Android 9.0 Pie 28

Android 8.1 Oreo 27

Android 8.0 Oreo 26


Version number code name API

Android 7.1.1 Nougat 25

Android 7.0 Nougat 24

Android 6.0 Marshmallow 23

Android 5.1 Lollipop 22

Android 5.0 Lollipop 21

Android 4.4W KitKat Wear 20

Android 4.4 KitKat 19

Android 4.3 Jelly Bean 18

Android 4.2 Jelly Bean 17

Android 4.1 Jelly Bean 16

Android 4.0.3 IceCreamSandwich 15

Android 4.0 IceCreamSandwich 14

Android 3.2 Honeycomb 13

Android 3.1 Honeycomb 12

Android 3.0 Honeycomb 11

Android 2.3.3 Gingerbread 10

Android 2.3 Gingerbread 9

Android 2.2 Froyo 8

Android 2.1 Eclair 7

The source code directory of the system

About Android source code download, you can refer to: install Ubuntu under Windows, graphical interface, download Android source code, just read this article

The catalog is based on Android 13.

Monolithic structure

Source code root description

art ART runtime environment

bionic System C library

bootable Start bootstrap related code

build Configure basic development kits such as system compilation rules and generic

cts Android Compatibility Test Suite standard


Source code root description

dalvik Dalvik virtual machine

developers Developer directory

development Application-related

device Device-related configurations

docs Refer to the documentation

external Open source mods

frameworks Application framework, the core part of the Android system

hardware Hardware abstraction layer code

kernel The kernel layer, including code for device drivers, hardware abstraction layers, system calls, etc

libcore Core library related files

libnativehelper Dynamic library, the basis for implementing the JNI library

packages Application packages

out Compile code output directory, customizable

pdk Plug Development Kit, a local development kit

platform_testing Platform testing

prebuilts Some of the resources pre-compiled under the x86 and ARM architectures

sdk SDKs and emulators

system Low-level file system libraries, applications, and components

test Store test code and test tools

toolchain Toolchain files

tools Tool files

There is also an important directory vendor, which stores the vendor custom code.

Application Layer (Packages)

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

apps Core applications

modules Standalone, pluggable application modules


 

inputmethods Input method directory


packagesdirectory description

providers Content Provider Directory

screensavers Screen saver

services Communication Services

wallpapers wallpaper

Application Framework Layer (Frameworks/Base)

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
 

apct_tests Store code and test cases related to automated testing

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

api Define APIs

boot Boot code and base class libraries for the operating system

cmds Important commands such as am, app_proce, etc

config The configuration files and data structures of the system

core Core Library

data Data files such as fonts, sounds, etc

docs documentation

drm Digital Rights Management (DRM) code and class libraries

errorprone Code and class libraries for error handling and exception handling

graphics graphic images

identity Code and class libraries for authentication and authorization

keystore Data Signing Certificates

libs storehouse

location Geolocation-related libraries

media Multimedia-related libraries

mime Definition and configuration information for MIME (Multipurpose Internet Mail Extension) types

mms Code and class libraries for SMS and multimedia messaging services

native Local library


frameworks/base description
directory

nfc-extras NFC related

obex Bluetooth transmission

omapi Open Mobile Alliance Device Provider (OMADP) API interface and class library

opengl 2D/3D graphics API

packages Settings, TTS, SystemUI, VPN programs, etc

proto Definition and configuration information for various protocols and data structures in the system

rs Code and class library for RenderScript

samples Various sample codes and demo programs

sax XML parser

services System services

startop Code and class libraries for StartOp

telecom Telecom code and class libraries

telephony Telephony communication management

test-runner Test tool related

tests Test-related

tools tool

wifi Wi-Fi

C/C++ library section

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.

Directory location description

bionic The system C library developed by Google, which is open source under the BSD license

frameworks/av/media System Media Library

frameworks/native/opengl Third-party graphics rendering libraries

frameworks/native/services/surfaceflinger A graphics display library that is responsible for graphics rendering, overlays, and drawing
functions

external/sqlite C++ implementation of SQLite, a lightweight relational database

 

Source code reading

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:

1. Change the memory settings to 8GB and above

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

You might also like