Introduction
In this series, we read the actual source code of the Android Open Source Project (AOSP) and follow its structure and design as we go.
Part 1 is the big picture: what AOSP is, how it differs from the Android on the devices we use every day, which components make up the software stack, and where each component lives in the source tree.
For setting up a development environment, see the official get-started guide.
How AOSP Differs from "Regular Android"
AOSP is the open source operating system that Google publishes under the Apache 2.0 license. Anyone can download it and modify it freely.
The Android smartphones we use every day, by contrast, are AOSP plus Google Mobile Services (GMS). GMS bundles the Google Play Store, Google Play services (a background service that provides location, authentication, push notifications, and more), and Google apps such as Chrome and Gmail.
GMS is not open source. It is licensed to Original Equipment Manufacturers (OEMs, the device makers) under a legal agreement called the Mobile Application Distribution Agreement (MADA). In other words, AOSP itself can be used freely with no contract, but pre-installing the Google Play Store requires signing a MADA. This distinction is the first key to understanding the Android ecosystem.
The Software Stack at a Glance
The official documentation uses the word "layers" for the AOSP software stack, but it does not give the layers names or numbers; it presents the components through a figure and a set of term definitions. This article does not invent its own layers either. It follows the official terms and their order, from top to bottom.
The Three Kinds of Apps
There are three kinds of apps. They differ in which APIs they may use and in how they must be delivered.
- Android app: An app created solely using the Android API. Third-party apps fall into this category
- Privileged app: An app created using a combination of the Android API and the system API. It must be preinstalled on the device as a privileged app
- Device manufacturer app: An app that, in addition to the Android API and the system API, can access the Android framework implementation directly
Because a device manufacturer app might directly access unstable APIs within the framework, it must be preinstalled, and it can be updated only when the device's system software is updated.
Android API and System API
Apps can see two kinds of APIs.
- Android API: The publicly available API for third-party Android app developers
- System API: APIs available only to partners and OEMs. In the source code, these are marked with the
@SystemApiannotation
APIs with different visibility live side by side inside the same framework. When you read the code, it helps to be aware of which of the two a given method belongs to, because it changes how you read it.
Android Framework
The Android framework is a group of Java classes, interfaces, and other precompiled code upon which apps are built. Portions of it are publicly accessible through the Android API, and other portions are available only to OEMs through the system APIs. Framework code runs inside an app's process.
System Services and Android Runtime (ART)
- System services: Modular, focused components such as
system_server, SurfaceFlinger, and MediaService. Functionality exposed by the Android framework API communicates with system services to access the underlying hardware - Android runtime (ART): The Java runtime environment provided by AOSP. It translates an app's bytecode into processor-specific instructions and executes them
HAL and Native Daemons and Libraries
- HAL (Hardware Abstraction Layer): An abstraction layer with a standard interface for hardware vendors to implement. Using a HAL lets Android stay agnostic about lower-level driver implementations, so functionality can be implemented without affecting or modifying the higher-level system
- Native daemons and libraries: Components that interact directly with the kernel or other interfaces and don't depend on a userspace-based HAL implementation. Daemons include
init,healthd,logd, andstoraged; libraries includelibc,liblog,libutils, andlibbinder
Kernel
The kernel is the central part of the operating system and talks directly to the hardware on a device. Where possible, the AOSP kernel is split into hardware-agnostic modules and vendor-specific modules.
Repositories and Directory Layout
The AOSP source code is not a single large repository. It is managed with a tool called repo, built on top of Git. The .repo/manifest.xml file defines the full set of Git repositories and where each one is checked out. A checkout contains more than 1,000 individual Git repositories, each corresponding to a subdirectory of the source tree (the exact count varies by branch and by how you count).
On Android Code Search, you can find three repositories (superprojects).
platform/superproject/main: the superproject for the main development branch
platform/superproject: the superproject for the base branch or release lines
kernel/superproject: the kernel-related group of repositories
At the top level, the source tree is broadly organized as follows.
Runtime & Core: art/, bionic/, libcore/, libnativehelper/, dalvik/
Framework: frameworks/, packages/
Build System: build/, toolchain/, prebuilts/
Platform & Hardware: system/, hardware/, device/, kernel/, bootable/, trusty/
Testing & Development: cts/, test/, platform_testing/, development/, tools/, developers/, sdk/, pdk/
External Libraries: external/
Mapping Components to Directories
Finally, here is where each component of the software stack lives in the source tree. This map will guide the code reading in the following parts.
Android API: frameworks/base/core/java/android/
System API: the parts of the Android API marked with the @SystemApi annotation (the annotation itself is defined in frameworks/libs/modules-utils/java/android/annotation/SystemApi.java)
Android framework: frameworks/base/core/
System services: frameworks/base/services/
Android runtime (ART): art/
HAL: hardware/interfaces/, hardware/libhardware/
Native daemons: system/core/ (init, healthd, storaged, debuggerd, watchdogd), system/logging/ (logd), system/netd/, system/vold/
Native libraries: bionic/ (libc and others), system/core/libutils/ and libcutils/, system/logging/ (liblog), frameworks/native/libs/binder/ (libbinder)
Kernel: under the kernel/superproject repository in Code Search
Summary
In Part 1, we covered the distinction between AOSP and GMS, the components of the software stack, and how each component maps to directories in the source tree. From Part 2 onward, we will use this map to read the code of each component in turn.


No comments:
Post a Comment