Android Platform architecture Android

来源:互联网 发布:网络机房地板系统 编辑:程序博客网 时间:2024/05/17 04:40
  • Development
  • API guide

Platform architecture

This article content

  1. Linux kernel
  2. Hardware Abstraction Layer (HAL)
  3. Android Runtime
  4. Native C / C ++ library
  5. Java API framework
  6. system applications

Android is a Linux-based open source software stack created for a wide range of devices and models. The figure below shows the main components of the Android platform.

Figure 1. Android software stack.

Linux kernel


The Android platform is based on the Linux kernel. For example, Android Runtime (ART) relies on the Linux kernel to perform underlying functions such as threading and lower-level memory management.

Using the Linux kernel allows Android to take advantage of major security features and allows device makers to develop hardware drivers for the well-known kernel.

Hardware Abstraction Layer (HAL)


The Hardware Abstraction Layer (HAL) provides a standard interface for displaying device hardware capabilities to the higher-level Java API frameworkThe HAL contains several library modules, each of which implements an interface for a specific type of hardware component, such as a camera or Bluetooth module. When the framework API requires access to the device hardware, the Android system loads the library module for that hardware component.

Android Runtime


For devices running Android 5.0 (API level 21) or later, each app runs in its own process and has its own Android Runtime (ART) instance. ART has been written to run multiple virtual machines on low-memory devices by executing DEX files, a bytecode format designed for Android that is optimized to use very little memory. Compilation toolchains (such as Jack ) compile Java source code into DEX bytecode so that it runs on the Android platform.

Some of the major features of ART include:

  • AOT and JIT compilation
  • Optimized Garbage Collection (GC)
  • Better debug support, including a dedicated sample analyzer, detailed diagnostic exceptions and crash reports, and the ability to set watchpoints to monitor specific fields

Dalvik is Android Runtime prior to Android version 5.0 (API level 21). If your application works well on ART, it should work on Dalvik, but not necessarily the reverse .

Android also includes a set of core runtime libraries that provide most of the Java programming language features used by the Java API framework, including some Java 8 language features .

Native C / C ++ library


Many of the core Android system components and services (such as ART and HAL) are built from native code and require native libraries written in C and C ++. The Android platform provides the Java framework API to show some of the native library functionality to the application. For example, you can access OpenGL ES through the Android framework's Java OpenGL APIs to enable drawing and manipulating 2D and 3D graphics in your application.

If you are developing applications that require C or C ++ code, you can use the Android NDK to access some native platform libraries directly from native code .

Java API framework


You can use the entire feature set of the Android OS with APIs written in the Java language. These APIs form the building blocks needed to create Android applications that simplify reuse of core modular system components and services, including the following components and services:

  • Rich, extensible view system for building UIs for applications, including lists, grids, text boxes, buttons and even embeddable web browsers
  • Resource Manager for accessing non-code resources such as localized strings, graphics, and layout files
  • Notification Manager lets all apps show custom alerts in the status bar
  • Activity manager , used to manage the life cycle of the application, providing a common navigation return stack
  • Content providers that allow applications to access data in other applications (such as the Contacts app) or share their own data

Developers have complete access to the framework APIs used by Android system applications .

system applications


Android comes with a set of core applications for email, SMS, calendar, Internet browsing and contacts. The applications that come with the platform are the same as the apps that users can choose to install, with no special status. Therefore, third-party applications can become the user's default web browser, SMS messenger or even the default keyboard (with some exceptions, such as the system's "Settings" application).

The system application can be used as a user's application, as well as providing the main function developers can access from their own applications. For example, if your app wants to send text messages, you do not need to build it yourself. Instead, you can call the installed messaging app to send a message to the recipient you specify.

译文:

平台架构

本文内容

  1. Linux 内核
  2. 硬件抽象层 (HAL)
  3. Android Runtime
  4. 原生 C/C++ 库
  5. Java API 框架
  6. 系统应用

Android 是一种基于 Linux 的开放源代码软件栈,为广泛的设备和机型而创建。下图所示为 Android 平台的主要组件。

图 1. Android 软件栈。

Linux 内核


Android 平台的基础是 Linux 内核。例如,Android Runtime (ART) 依靠 Linux 内核来执行底层功能,例如线程和低层内存管理。

使用 Linux 内核可让 Android 利用主要安全功能,并且允许设备制造商为著名的内核开发硬件驱动程序。

硬件抽象层 (HAL)


硬件抽象层 (HAL) 提供标准界面,向更高级别的 Java API 框架显示设备硬件功能。HAL 包含多个库模块,其中每个模块都为特定类型的硬件组件实现一个界面,例如相机或蓝牙模块。当框架 API 要求访问设备硬件时,Android 系统将为该硬件组件加载库模块。

Android Runtime


对于运行 Android 5.0(API 级别 21)或更高版本的设备,每个应用都在其自己的进程中运行,并且有其自己的 Android Runtime (ART) 实例。ART 编写为通过执行 DEX 文件在低内存设备上运行多个虚拟机,DEX 文件是一种专为 Android 设计的字节码格式,经过优化,使用的内存很少。编译工具链(例如 Jack)将 Java 源代码编译为 DEX 字节码,使其可在 Android 平台上运行。

ART 的部分主要功能包括:

  • 预先 (AOT) 和即时 (JIT) 编译
  • 优化的垃圾回收 (GC)
  • 更好的调试支持,包括专用采样分析器、详细的诊断异常和崩溃报告,并且能够设置监视点以监控特定字段

在 Android 版本 5.0(API 级别 21)之前,Dalvik 是 Android Runtime。如果您的应用在 ART 上运行效果很好,那么它应该也可在 Dalvik 上运行,但反过来不一定。

Android 还包含一套核心运行时库,可提供 Java API 框架使用的 Java 编程语言大部分功能,包括一些 Java 8 语言功能。

原生 C/C++ 库


许多核心 Android 系统组件和服务(例如 ART 和 HAL)构建自原生代码,需要以 C 和 C++ 编写的原生库。Android 平台提供 Java 框架 API 以向应用显示其中部分原生库的功能。例如,您可以通过 Android 框架的 Java OpenGL API 访问 OpenGL ES,以支持在应用中绘制和操作 2D 和 3D 图形。

如果开发的是需要 C 或 C++ 代码的应用,可以使用 Android NDK 直接从原生代码访问某些原生平台库。

Java API 框架


您可通过以 Java 语言编写的 API 使用 Android OS 的整个功能集。这些 API 形成创建 Android 应用所需的构建块,它们可简化核心模块化系统组件和服务的重复使用,包括以下组件和服务:

  • 丰富、可扩展的视图系统,可用以构建应用的 UI,包括列表、网格、文本框、按钮甚至可嵌入的网络浏览器
  • 资源管理器,用于访问非代码资源,例如本地化的字符串、图形和布局文件
  • 通知管理器,可让所有应用在状态栏中显示自定义提醒
  • Activity 管理器,用于管理应用的生命周期,提供常见的导航返回栈
  • 内容提供程序,可让应用访问其他应用(例如“联系人”应用)中的数据或者共享其自己的数据

开发者可以完全访问 Android 系统应用使用的框架 API。

系统应用


Android 随附一套用于电子邮件、短信、日历、互联网浏览和联系人等的核心应用。平台随附的应用与用户可以选择安装的应用一样,没有特殊状态。因此第三方应用可成为用户的默认网络浏览器、短信 Messenger 甚至默认键盘(有一些例外,例如系统的“设置”应用)。

系统应用可用作用户的应用,以及提供开发者可从其自己的应用访问的主要功能。例如,如果您的应用要发短信,您无需自己构建该功能,可以改为调用已安装的短信应用向您指定的接收者发送消息。


原创粉丝点击