An in-depth understanding of Android's system framework

Source: Internet
Author: User

Android uses a hierarchical system architecture that is officially published as shown in the standard architecture. Android is divided into 4 main functional layers, namely the Linux kernel layer (Linux Kernel), the System Runtime Library layer (libraries and Android runtime) , The Application Architecture layer (application Framework) and the Application layer (applications).

Linux kernel layer

Based on the Linux operating system kernel, Android uses Linux kernel service to realize the core functions of hardware device driver, process and memory management, network protocol stack, power management, wireless communication and so on. Before the Android4.0 version was based on the Linux2.6 series kernel, the 4.0 and later versions used the updated linux3.x kernel, and two open source projects began to interoperate. The Linux3.3 kernel officially includes some Android code that can be directly booted into Android. Linux3.4 will add more features such as power management to increase hardware compatibility with Android and enable Android to be supported on more devices.

The Android kernel has enhanced the Linux kernel, adding some unique features for mobile computing. For example, the Low memory manager LMK (Keller), Anonymous shared memory (ASHMEM), and the lightweight interprocess communication binder mechanism. These kernel enhancements have enabled Android to further enhance the security of memory management, interprocess communication, and so on, while inheriting the Linux kernel security mechanism. The following table lists the main driver modules for the Android kernel:

Driver name Description
Android Power Management (Power Ma nagement) Lightweight power management drivers for embedded devices, based on standard Linux power management systems
Low memory Manager (Keller) You can kill the process as needed to free up the required memory. extended the oom mechanism of Linux to form a unique LMK mechanism
Anonymous shared memory (ASHMEM) Provides shared memory resources between processes, while providing a mechanism for the kernel to reclaim and manage memory
Log (Android Logger) A lightweight log device
Timers (Anroid Alarm) Provides a timer to wake the device from sleep
Physical Memory mapping Management (Android Pmem) DSP and other devices can only work on continuous physical memory, PMEM is used to provide continuous physical memory area mapping to user space
Android Timer devices (Android Timed device) Can perform timing control functions on the device
YAFFS2 File System Android uses large-capacity NAND flash memory as a storage device, using YAFFS2 as the file system to manage large-capacity MTD NAND FLASH;YAFFS2 takes up little memory and garbage collection is quick and simple.
Android Paranoid Network The network code of the Linux kernel is changed, and the network authentication mechanism is added. It can be set in Ipv4,ipv6 and Bluetooth and is enabled by the Android_paranoid_network macro.

Hardware Abstraction Layer

There is also a so-called hardware abstraction layer (Hardware abstract layer,hal) between the kernel driver and the user software, which abstracts the specific implementation of the hardware device. HAL is not identified in the Android official system architecture diagram, marking the location of the hardware abstraction layer on the Android system:

Since many hardware vendors do not want to expose their device-driven source code, Android will reduce its reliance on the Linux kernel if it can isolate the Android application framework layer from the device drivers of the Linux system kernel, so that the development of the application framework is as independent of the specific driver as possible. The HAL is the result of the encapsulation of the Linux kernel driver, the abstraction of the hardware, and the masking of the underlying implementation details. HAL specifies a set of application layer to the hardware layer read-write and configuration of the unified interface, in essence, the hardware driver is divided into user space and kernel space two levels; The Linux kernel driver runs in kernel space and the hardware abstraction layer runs in user space.

System run-level library

In the official system architecture diagram, the System runtime layer on top of the Linux kernel layer is the support of the application framework, which serves the various components in the Android system. The System runtime layer is composed of the System class library and the Android runtime.

1. System Class Library

Most of the System class libraries are written in C + +, and the functionality provided is used by the developer through the Android application framework. The main system class libraries and descriptions are as follows:

System Class Library Name Description
Surface Manager Display of the management subsystem when executing multiple applications, plus support for 2D and 3D graphics
Media Framework The Packetvideoopencore-based multimedia library supports recording and playback of a variety of commonly used audio and video formats, including Mpeg4,mp3,h264,aac,arm
Sqlite Local small relational database, Android provides some new SQLite database APIs to replace the traditional resource-intensive JDBC API
Opengl|es 3D cross-platform graphics library based on OpenGL ES 1.0API Standard
FreeType Used to display bitmaps and vector fonts
Webkit Software engine for Web browser
SGL The underlying 2D graphics engine
LIBC (Bionic L IBC) Inherits from BSD's C function library bionic libc, more suitable for embedded Linux-based mobile devices
Ssl Secure Sockets Layer is a security protocol that provides security and data integrity for network communication

In addition to the main system class libraries listed in the table above, the Android NDK (Native development Kit), the Android native library, is also important. The NDK provides developers with an interface to directly use Android system resources and write programs in the C or C + + languages. As a result, third-party applications can be developed without relying on dalvik virtual machines. In fact, the NDK provides a range of tools needed to generate native code from C or C + +, facilitating rapid development of C or C + + dynamic libraries for developers, and the ability to automatically package the generated dynamic libraries and Java applications together into an application package file, the. apk file.

Note that the application Framework layer API cannot be accessed using native libraries, and compatibility may not be guaranteed. And from a security standpoint, the Android native library is written in a non-type-safe programming language c,c++, which is more prone to security vulnerabilities, and a bug in the native library may be more likely to directly affect the security of the application.

2. Run-time

The Android runtime contains both the core library and the Dalvik virtual machine.

Core Library: The core library provides most of the functionality of the Java5 SE API and provides the core API for Android, such as Android.os,android.net,android.media.

Dalvik virtual machine: The Dalvik virtual machine is an Apache-based Java Virtual machine and is improved to accommodate low-memory, low-processor-speed mobile device environments. Dalvik virtual machines rely on the Linux kernel for process isolation and thread debug management, security and exception management, garbage collection and other important functions.

Essentially, the Dalvik virtual machine is not a Java Virtual machine (JVM) in the traditional sense. Dalvik virtual machines are not implemented in accordance with the specifications of the Java Virtual machine, and they are not compatible.

The following are the main differences between Dalvik and standard Java virtual machines:

    • The Dalvik is based on a register, and the JVM is stack-based. It is generally believed that the register-based implementation, although more dependent on the specific CPU structure, the hardware versatility is slightly worse, but its use of equal-length instructions, in terms of efficiency faster than the traditional JVM more advantages.

    • Dalvik is optimized to allow instances of multiple virtual machines to run efficiently in limited memory, and each Dalvik application executes as a standalone Linux process with a separate Dalvik virtual machine instance. Android, the Linux-based process "sandbox" mechanism, is one of the foundations of the entire security design.

    • The Dalvik virtual machine reads instructions and data from a file in Dex (Dalvik executable) format, which is interpreted to run. Dex files are generated by traditional, compiled class files that are processed by the DX tool software.

    • Dalvik's Dex files can also be further optimized to improve operational performance. Typically, an OEM application can generate the optimization file directly after the system compiles (. ODEX); third-party applications can be optimized and saved in the cache at run time, with the optimized format dey (. dey file).

Application Framework Layer

The application framework layer provides a range of class libraries that are required to develop Android applications, enabling developers to quickly develop applications, facilitate reuse of components, and allow for personalized extensions through inheritance. The specific modules are as follows:

Application framework Layer Class library name Function
Event Manager (Activity Mananger) Manage individual application lifecycles and provide common navigation fallback functionality for interfaces that interact with Windows for all Programs
Window Manager (Windows Manager) Manage all open Windows programs
Content provider (contents Provider) Provide one application with the ability to access another application's data, or implement data sharing between applications
View System Create the basic components of your application, including lists (lists), grids (grids), text boxes (texts boxes), buttons (buttons), and web browsers that can be embedded.
Notification Manager (Notification Manager) Enables applications to display customized customer tip information in the status bar
Package Manager Manage applications, provide functions such as installing applications, uninstalling applications, querying related permissions, and more.
Resource Manager (Resource Manager) Provides a variety of non-code resources for the use of programs such as localized strings, pictures, audio, etc.
Location Manager (Locator manager) Provide location services
Phone Manager (Telephony manager) Manage all your mobile device features
XMPP Service is a common process in Google Online instant communication software, providing background push service

Application Layer

The application layer on the Android platform includes a variety of applications that interact directly with the user, or a service program written in the Java language that runs in the background. For example, the common basic function programs implemented on smartphones, such as SMS, phone dialing, picture browser, calendar, games, maps, Web browsers, and other applications developed by developers.

Reproduced from: Android based Android system architecture

An in-depth understanding of Android's system framework

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.