Android system architecture (1)
Android
What is Andriod?
It can be seen that the main components of Android are the underlying Linux kernel, including file, memory, and system resource management, google's work in this part mainly involves power management and some drivers, and integrates upper-layer extensions and public components. If you want to study this part, it should be a good way to learn about Linux. Next, an important component is Dalvik, a Java virtual machine, similar to jvm. It mainly provides a virtual runtime environment to adapt to the upper-layer Java bytecode. Here is. dex file). Theoretically, you can run the Android App by installing Dalvik on other system platforms, such as Mac and Windows, many applications are based on services provided by Android, so if you want to run them normally on other platforms, it may be Hello World.
The following is a public Android architecture diagram.
Android System Structure
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 API framework used by core applications. The architecture design of this application simplifies Component reuse; any application can publish its functional blocks, and any of its applications can use the released functional blocks without complying 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), which can be used to build the user interface of an application, including lists, grids, text box boxes), and buttons ), A web browser that can be embedded.
Content Providers (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, graphics, and layout files ).
Notification Manager) enables applications to display custom prompts in the status bar. Provides a non-intrusive mechanism to notify users, that is, users are not interrupted)
Activity Manager (Activity Manager) is used to manage the application lifecycle and provides common navigation rollback functions. (Control the lifecycle of the interface, including the stack for managing activities)
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. So you can write C Programs)
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. (It should mean that the file formats can be parsed without using a third-party package)
Surface Manager-manages the display subsystem and provides seamless integration of 2D and 3D layers for multiple applications. (Manage display items, such as allocating a display ing memory to View)
Webkit, LibWebCore-a new web browser engine that 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 APIs; this library can be used for hardware 3D acceleration if available) or highly optimized 3D soft acceleration. 2.2 and later OpenGL versions are 2.0)
FreeType-bitmap) and vector font display.
SQLite-a lightweight relational database engine that is available and powerful for all applications.
SSL-supports secure Internet communication using the Secure Socket Layer encryption protocol.
* What is not shown above is the hardware abstraction layer. In Android, not all device drivers are placed in the Linux kernel, but in the userspace. The main reason for this is the GPL protocol, which is followed by Linux, this means that 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. In the Linux kernel, you can 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 the 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 runs in its own process and has 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 optimized for small memory usage. 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.
Some function libraries provided by the corresponding system:
Android. util: the Core toolkit contains underlying classes, string formatting and XML parsing tools, and underlying classes.
Android. OS: the operating system package provides access to basic operating system services, such as message transmission, inter-process communication, clock functions, and debugging.
Android. graphics: The graphic API provides a low-level graphic class that supports canvases, colors, and graphic elements, and supports drawing canvases.
Android. text: a text processing tool used to display and parse text.
Android. database: Provides underlying class support when the database processes the cursor.
Android. content: content API manages data access and provides services to manage resources and content providers) and packages.
Android. view: view is the core user interface class. All user interface elements use a series of views to form user interaction components.
Android. widget: embedded in the View package. Including list, buttons, and layout.
Com. google. android. maps: an advanced API that provides access to local map controls and can be used in your own applications. Including MapView control, tagging and control of your embedded map overlays, and MapController class.
Android. app: a high-level package that allows access to the application model. This application package includes Activity and Service APIs, which are the basis of Android applications.
Android. provider: allows developers to access standard content providers such as contact databases. The provider package provides classes for developers to access standard databases.
Android. telephony: The telephony API allows developers to directly access the underlying layer of the phone. developers can call, answer the phone, display call records, call status, and short messages.
Android. webkit: WebKit Software Package functions API and Web-based content work, including a WebView control embedded in your activity browser and cookie manager.
Because Android is expected to have more extensive adaptability to mobile hardware, pay attention to the scenarios and use of the following APIs and whether fashion settings are available.
Android. location: location-based service APIs allow applications to access the current physical location of devices. Location-Based Services provide general access to available location information on any fixed hardware or technical device.
Android. media: media API provides support for playing audio and video media files, including streaming media and recording.
Android. opengl: the OpenGL es api used by Android. You can use it to create a dynamic 3D user interface as a powerful 3D rendering engine for your application.
Android. hardware: Sensor hardware exposed by hardware APIs, including cameras, accelerometer, and compass sensors, if possible.
Android. bluetooth, android.net. wifi, android. telephony: Android also provides hardware platforms, including low-level access to bluetooth, Wi-Fi, and telephone hardware.
4. Linux Kernel
Android core system services depend on the 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:
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.
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:
Java language: Its syntax, which is used to write code programs
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.
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:
For Android 2.1
| -- Makefile: Global Makefile)
| -- Bionic (bionic C library, Bionic refers to bionic, Which is the source code of some basic libraries)
| -- Bootable (startup guide code)
| -- Build (stores basic development kit configurations such as system compilation rules and generic, instead of the code used by the target, but the scripts and tools required for compilation and configuration)
| -- Cts (Android compatibility test suite Standard)
| -- Dalvik (dalvik Java Virtual Machine)
| -- Development (templates and tools required for Program development)
| -- External (some open-source modules used by android)
| -- Frameworks (core framework -- java and C ++ language)
| -- Hardware (some open-source hardware solution Adaptation Layer HAL code)
| -- Out (the code output after compilation is in this directory)
| -- Packages (Application Package)
| -- Prebuilt (precompiled scripts and some resources in x86 and arm architectures)
| -- Sdk (sdk and simulator)
| -- System (underlying file system library, applications and components -- C language)
'-- Vendor (vendor-defined code)
Bionic directory
| -- Libc (C Library)
| -- Arch-arm (ARM architecture, including system call Assembly implementation)
| -- Arch-x86 x86 architecture, including system call Assembly implementation)
| -- Bionic functions implemented by C, architecture independent)
| -- Docs Documentation)
| -- Include header file)
| -- Inet? Inet problems. The specific role is unknown)
| -- Some header files in the kernel Linux kernel)
| -- Netbsd? Nesbsd system related, specific role unknown)
| -- Private? Some private header files)
| -- Stdio implementation)
| -- Stdlib implementation)
| -- String function implementation)
| -- Tools)
| -- Tzcode Time Zone code)
| -- Unistd implementation)
| '-- Zoneinfo Time Zone Information)
| -- Libdl implementation. dl is a dynamic link and provides the function of accessing the dynamic link library)
| -- Libm mathematical library implementation ,)
| -- Alpha apaha Architecture)
| -- Amd64 amd64 Architecture)
| -- Arm architecture)
| -- Bsdsrc? Bsd source code)
| -- I386 i386 architecture)
| -- I387 i387 architecture ?)
| -- Ia64 ia64 Architecture)
| -- Include header file)
| -- Man mathematical function, suffixed with. 3. Some freeBSD library files)
| -- Powerpc architecture)
| -- Sparc64 sparc64 Architecture)
| '-- Src Source Code)
| -- Libstdc ++ C ++ implementation Library)
| -- Include header file)
| '-- Src Source Code)
| -- Libthread_db multi-threaded program debugger Library)
| '-- Include header file)
'-- Linker dynamic linker)
'-- Arch supports both arm and x86 architectures)
Bootable directory
.
| -- Bootloader is applicable to common codes of various bootloaders)
| '-- Legacy cannot be used directly. For details, refer)
| -- Arch_armv6 V6 architecture, several simple assembly files)
| -- Several basic drivers of arch_msm7k Qualcomm 7k Processor Architecture)
| -- Include general header files and Qualcomm 7 k architecture header files)
| -- Libboot startup library, which is easy to write)
| -- Libc some common c functions)
| -- Nandwrite nandwirte function implementation)
| '-- Usbloader implementation)
| -- Diskinstaller android image package, x86 can produce iso)
'-- Recovery Related to the recovery System)
| -- Edify script language used by the edify upgrade script)
| -- Etc init. rc recovery script)
| -- Minui: A simple UI)
| -- Minzip is a simple compression tool)
| -- Mtdutils mtd tool)
| -- Res Resource)
| '-- Images)
| -- Tools)
| '-- Ota Over The Air Updates upgrade tool)
'-- Updater upgradeer)
Build directory
.
| -- Core compilation rules)
| -- History)
| -- Libs
| '-- Host database, replaced by the android "cp" function)
| -- Target machine compilation object)
| -- Board development platform)
| -- Emulator simulator)
| -- Generic)
| -- Added by idea6410)
| '-- Sim is the simplest)
| '-- Compilation rules for the product development platform)
| '-- Security Key-related)
'-- Tools and scripts used by the host during compilation)
| -- Acp Android "acp" Command)
| -- Apicheck api Check Tool)
| -- Applypatch tool)
| -- Prelinking tool of apsaradb for redis)
| -- Atree tree tool)
| -- Bin2asm bin conversion to asm tool)
| -- Check_prereq check the compilation timestamp tool)
| -- Dexpreopt simulator related tools with unknown functions)
| -- Droiddoc? Unknown role, java language. Someone on the Internet said it was related to JDK 5)
| -- Fs_config This program takes a list of files and directories)
| -- Fs_get_stats obtains the file system status)
| -- Iself determines whether the ELF format is used)
| -- Isprelinked determines whether prelinked is used)
| -- Kcm buttons)
| -- Lsd List symbol dependencies)
| -- Releasetools tool and script for generating images)
| -- Rgb2565 rgb conversion to 565)
| -- Signapk apk signature tool)
| -- Soslim strip tool)
'-- Zipalign zip archive alignment tool)
Dalvik directory dalvik Virtual Machine
.
| -- Directory of dalvikvm main. c)
| -- Dexdump dex disassembly)
| -- Dexlist List all methods in all concrete classes in a DEX file .)
| -- Dexopt pre-verification and optimization)
| -- Docs Documentation)
| -- A command related to dvz and zygote)
| -- Dx tool, which converts multiple java to dex)
| -- Hit? Written in java)
| -- Libcore core library)
| -- Libcore-disabled? Disabled Library)
| -- Libdex Library)
| -- Libnativehelper Support functions for Android's class libraries)
| -- Tests Test code)
| -- Tools)
'-- Vm implementation)
Some routines and tools required by developers in the development Directory)
| -- Apps: some core applications)
| -- Debuthdebug Bluetooth debugging program)
| -- CustomLocale custom region settings)
| -- Development)
| -- Fallback is a language-related Program)
| -- FontLab Font Library)
| -- GestureBuilder gesture action)
| -- NinePatchLab ?)
| -- OBJViewer OBJ viewer)
| -- SdkSetup SDK installer)
| -- SpareParts advanced settings)
| -- Term remote logon)
| '-- Launchperf ?)
| -- Build the Script Template)
| -- Cmds has a monkey tool)
| -- Data configuration data)
| -- Docs Documentation)
| -- Host USB driver)
| -- Ide integrated development environment)
| -- Ndk Local Development Kit -- C Language Development Kit)
| -- Pdk Plug Development Kit)
| -- Samples routine)
| -- AliasActivity ?)
| -- ApiDemos API demo program)
| -- Bluetooth chat)
| -- BrowserPlugin browser plug-in)
| -- BusinessCard commercial card)
| -- Compass)
| -- ContactManager Contact Manager)
| -- A simple routine of CubeLiveWallpaper live wallpaper)
| -- FixedGridLayout is like layout)
| -- GlobalTime global time)
| -- HelloActivity Hello)
| -- Home)
| -- JetBoy jetBoy game)
| -- LunarLander seems to be another game)
| -- MailSync email sync)
| -- MultiResolution Multi-Resolution)
| -- MySampleRss RSS)
| -- NotePad)
| -- RSSReader RSS reader)
| -- SearchableDictionary Directory Search)
| -- SimpleJNI JNI routine)
| -- SkeletonApp shell APP)
| -- Snake snake Program)
| -- SoftKeyboard)
| -- Wiktionary? Wiki)
| '-- WiktionarySimple? Wikipedia)
| -- Scripts script)
| -- Sdk configuration)
| -- Simulator? Simulator)
| -- Testrunner? For testing)
'-- Tools)