Android system architecture

Source: Internet
Author: User

Android
It is a platform developed by Google for mobile phones and most of the Code is published. Most of its applications are developed using Java. After all, it is a commercial product, reserved
Of course. For Embedded Linux developers, we can learn their strengths from them. It is also a development direction and trend in the future.

Let's take a look at the architecture of Android. The following is a public Android architecture diagram.

Android adopts a hierarchical architecture like its operating system. From the structural diagram, Android is divided into four layers: application layer, application framework layer, system Runtime Library layer, and Linux core layer. Blue represents the Java program. The yellow code is the virtual machine that runs the Java program. The green part is the library written in C/C ++ and the red code kernel (Linux kernel + drvier)

1. Applications

Android is released together with a series of core application packages, including email clients, SMS Short Message programs, calendars, maps, browsers, and contact management programs. All applications are written in Java.

2. Application Framework

Developers can also fully access the APIs used by core applications.
Framework. The architecture design of this application simplifies Component Reuse. Any application can publish its functional blocks and
All of its applications can use the feature blocks they have released (but they must comply with the security restrictions of the Framework ). Similarly, this application reuse mechanism allows you to easily replace program components.

A series of services and systems are hidden behind each application, including;

* Rich and scalable views can be used to build applications, including lists, grids, and text boxes ), button (buttons), or even an embedded web browser.
* Content providers allow applications to access data of another application (such as the contact database) or share their own data.
* Resource manager provides access to non-code resources, such as local strings, images, and layout files ).
* Notification Manager allows applications to display custom prompts in the status bar.
* Activity manager is used to manage the application lifecycle and provides common navigation rollback functions.

For more details and how to write an application from scratch, see how to write an Android Application.

3. System Runtime Library

1) Library

Android contains some C/C ++ libraries that can be used by different components in the Android system. They provide services to developers through the Android Application Framework. The following are some core databases:

* Bionic system C library-a standard C system function library (libc) inherited from BSD, which is specially customized for Embedded Linux devices.
* Media library-Based on packetvideo opencore. This Library supports multiple common audio and video formats for playback and recording, and supports static image files. The encoding formats include MPEG4, H.264, MP3, AAC, Amr, JPG, and PNG.
* Surface Manager-manages the display subsystem and provides seamless integration of 2D and 3D layers for multiple applications. This part of code
* WebKit, libwebcore-the latest web browser engine, supports Android browsers and an embedded Web View. The engine behind the famous Apple Safari is WebKit.
* SGL-underlying 2D graphics engine
* 3D libraries-implemented based on OpenGL ES 1.0 APIs. This library can use hardware 3D acceleration (if available) or highly optimized 3D soft acceleration.
* FreeType-bitmap and Vector Fonts.
* SQLite-a lightweight relational database engine that is available to all applications and has powerful functionality.

* What is not shown above is the hardware abstraction layer. Its
In actual Android, not all device drivers are placed in the Linux kernel, but are implemented in the userspace. The main reason for this is the GPL protocol, which Linux follows
The source code must be released for any modifications to the Linux kernel. Now, this can be avoided without having to publish its source code. After all, it is used to make money.
While
In the Linux kernel, open a backdoor for these userspace driver codes so that hardware that is not directly controlled by the userspace driver can be accessed. You only need to publish this
Backdoor code. Generally, to port android to other hardware for running, you only need to implement this part of code. Including: display drive, sound, camera, GPS, GSM, etc.

2) Android Runtime Library

Android includes a core library that provides most of the functions of the core library of Java programming language.

Every android application is running in its own process.
All have an independent Dalvik Virtual Machine instance. Dalvik is designed as a device to efficiently run multiple virtual systems at the same time.
Dalvik executable file of Dalvik virtual machine execution (. Dex), which is used for small memory usage
Optimized. At the same time, the virtual machine is register-based. All classes are compiled by the Java compiler, and then converted to the. Dex format using the "dx" tool in the SDK is executed by the virtual machine.

The Dalvik virtual machine depends on some features of the Linux kernel, such as the thread mechanism and the underlying memory management mechanism.

4. Linux Kernel

Android core system services depend on Linux 2.6 kernel
Such as security, memory management, process management, network protocol stack, and driver model. The Linux kernel is also an abstraction layer between the hardware and software stacks. In addition, some modifications have been made, mainly involving two parts:

1 ). binder (IPC): provides effective inter-process communication. Although the Linux kernel itself provides these functions, many Android services require this function, for some reason, it implements its own set.

2). Power Management: mainly for power saving. After all, it is a handheld device. Low Power Consumption is our pursuit.

Finally, let's talk about the language used by Android. Its Application Development adopts the Java language. The Java we call generally contains three parts:

1) Java language: Its syntax. It is a program that writes code.

2 ). java Virtual Machine: To achieve the principle that a compilation can run everywhere, Java does not generate the target machine language after the compilation connection, but uses the Java bytecode shared instruction, in this case, a virtual machine is required to execute the change command.

3). Library: provides some common libraries like the common C language.

The combination of the two is Java Runtime Environment.

The Virtual Machine Used by Android is called Dalvik. It was originally not designed for Java and cannot run the Java bytecode command. Instead, it runs Dalvik executable, DX for short. Android provides the DX tool to convert Java bytecode to DX.

Android source code structure:

Android provided by Google contains the original Android target machine code, host compilation tools, and simulation environment. After the code package is decompressed, the first-level directories and files are as follows:
.
| -- Makefile (Global makefile)
| -- Bionic)
| -- Bootloader)
| -- Build (the content in the build directory is not the code used by the target, but the scripts and tools required for compilation and configuration)
| -- Dalvik (Java Virtual Machine)
| -- Development (templates and tools required for Program Development)
| -- External (some libraries used by the target machine)
| -- Frameworks (framework layer of the Application)
| -- Hardware (hardware-related Library)
| -- Kernel (source code of linux2.6)
| -- Packages (various Android applications)
| -- Prebuilt (preset scripts compiled by android on various platforms)
| -- Recovery (related to the recovery function of the target)
'-- System (some underlying libraries of Android)

The bionic directory is displayed as follows:
Bionic/
| -- Android. mk
| -- Libc
| -- Libdl
| -- Libm
| -- Libstdc ++
| -- Libthread_db
'-- Linker

Two levels of bootloader directory expansion:
Bootloader/
'-- Legacy
| -- Android. mk
| -- Readme
| -- Arch_armv6
| -- Arch_msm7k
| -- Fastboot_protocol.txt
| -- Include
| -- Libboot
| -- Libc
| -- Nandwrite
'-- Usbloader

The build directory is displayed in the following directory:
Build/
| -- Buildspec. mk. Default
| -- Cleanspec. mk
| -- Core (various files ending with MK, which are makefiles required for compilation)
| -- Envsetup. Sh
| -- Libs
| -- Target (contains two directories: Board and product, which are the files required by the target)
'-- Tools (tools required by the host during compilation, which must be compiled and generated)

The makefile in core is the real makefile required for the entire android compilation. It is referenced by the makefile in the top-level directory.
Envsetup. Sh is a script used to set the environment when running with a simulator.
The Dalvik directory is used to provide the Java Virtual Machine (JVM), the Foundation for running Android Java applications.
The Development Directory is displayed in the following directory:
Development
| -- Apps (Android Application Template)
| -- Build (compile Script Template)
| -- Cmds
| -- Data
| -- Docs
| -- Emulator (simulation related)
| -- Host (including some tools on the Windows platform)
| -- Ide
| -- PDK
| -- Samples (some sample programs)
| -- Simulator (mostly some tools on the target machine)
'-- Tools

In the emulator directory, qemud is the background program running on the target machine during qemu simulation, and skins are the mobile phone interface during simulation.
Samples contains many simple Android projects, which provide great convenience for developers to learn and develop Android programs and can be used as templates.
The external directory is expanded as follows:
External/
| -- AES
| -- APACHE-HTTP
| -- Bluez
| -- Clearsilver
| -- Snapshot
| -- Dhcpcd
| -- Dropbear
| -- Elfcopy
| -- Elfutils
| -- Emma
| -- ESD
| -- Expat
| -- Fdlibm
| -- FreeType
| -- Gdata
| -- Giflib
| -- Googleclient
| -- Icu4c
| -- Iptables
| -- Jdiff
| -- Jhead
| -- JPEG
| -- Libffi
| -- Libpcap
| -- Libpng
| -- Libxml2
| -- Netcat
| -- Netperf
| -- Neven
| -- Opencore
| -- OpenSSL
| -- Oprofile
| -- Ping
| -- PPP
| -- Protobuf
| -- Qemu
| -- Safe-IOP
| -- Skia
| -- Sonivox
| -- SQLite
| -- SREC
| -- Strace
| -- Tagsoup
| -- Tcpdump
| -- Tinyxml
| -- Tremor
| -- WebKit
| -- Wpa_supplicant
| -- Yaffs2
'-- Zlib

In external, each directory represents a module in the android target system, which may contain one or more libraries. Where:
Opencore is PV (packetvideo), which is the core of the android multimedia framework.
WebKit is the core of the android web browser.
SQLite is the core of the android database system.
OpenSSL is a Secure Socket Layer, a network protocol layer, used to provide security support for data communication.
The frameworks directory is displayed in the following directory:
Frameworks/
| -- Base
| -- OPT
'-- Policies

Frameworks is the framework of Android applications.
Hardware is a hardware-related library.
Kernel is the source code of linux2.6

The packages directory is displayed in the following two levels:
Packages/
| -- Apps
| -- Alarmclock
| -- Browser
| -- Calculator
| -- Calendar
| -- Camera
| -- Contacts
| -- Email
| -- Googlesearch
| -- Htmlviewer
| -- Im
| -- Launcher
| -- MMS
| -- Music
| -- Packageinstaller
| -- Phone
| -- Settings
| -- Soundrecorder
| -- STK
| -- Sync
| -- Updater
| '-- Voicedialer
'-- Providers
| -- Calendarprovider
| -- Contactsprovider
| -- Downloadprovider
| -- Drmprovider
| -- Googlecontactsprovider
| -- Googlesubscribedfeedsprovider
| -- Improvider
| -- Mediaprovider
'-- Telephonyprovider

Packages contains two directories, among which apps are various Android applications, and providers are some content providers (a data source in Android ).
The contents of the two directories in packages are mostly programs written in Java, and the hierarchical structure of each folder is similar.
The prebuilt directory is displayed in the following directory:
Prebuilt/
| -- Android. mk
| -- Android-arm
| -- Common
| -- Darwin-x86
| -- Linux-x86
'-- Windows

The two levels of system directory expansion are as follows:
System/
| -- Bluetooth
| -- Bluedroid
| '-- Brfpatch
| -- Core
| -- Android. mk
| -- Readme
| -- ADB
| -- Cpio
| -- Debugadh
| -- Fastboot
| -- Include (header files of each library interface)
| -- Init
| -- Libctest
| -- Libcutils
| -- Liblog
| -- Libmincrypt
| -- Libnetutils
| -- Libpixelflinger
| -- Libzipfile
| -- Logcat
| -- Logwrapper
| -- Mkbootimg
| -- Mountd
| -- Netcfg
| -- Rootdir
| -- Sh
| '-- Toolbox
| -- Extras
| -- Android. mk
| -- Latencytop
| -- Libpagemap
| -- Librank
| -- Procmem
| -- Procrank
| -- Showmap
| -- Showslab
| -- Sound
| -- Su
| -- Tests
| '-- Timeinfo
'-- WLAN
'-- Ti




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.