PPrepLearn
Progress Β· 0/7 phases

πŸ›οΈ πŸ›οΈ Phase 2 β€” AOSP Architecture & Source Code

3 min read Β· Notion

Phase 2 β€” AOSP Architecture & Source Code

Duration: 3–4 weeks | Level: Intermediate

Understand the layered architecture of Android before diving into any single component.


πŸ—‚οΈ Android System Architecture (Layers)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚            Applications                  β”‚  ← APKs (your apps)
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Application Framework            β”‚  ← Java APIs: AMS, WMS, PMS, etc.
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚    Native Libraries  β”‚  Android Runtime  β”‚  ← C/C++ libs + ART/Dalvik
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Hardware Abstraction Layer       β”‚  ← HAL: camera, audio, sensors
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              Linux Kernel                β”‚  ← Drivers, memory, power
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Android is built in layers. Each layer only communicates with the layer directly below it through well-defined interfaces.


πŸ—οΈ Build System: Soong + Make

Android's build system has two components:

Android.mk (legacy Make)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := hello_world
LOCAL_SRC_FILES := hello.cpp
include $(BUILD_EXECUTABLE)

Android.bp (Soong β€” modern)

cc_binary {
    name: "hello_world",
    srcs: ["hello.cpp"],
    shared_libs: ["liblog"],
}

Soong uses Blueprint language. Most new modules use .bp. Key build rules:

  • cc_binary, cc_library_shared, cc_library_static β€” C/C++ targets
  • java_library, android_app β€” Java/app targets
  • hidl_interface, aidl_interface β€” IPC interface definitions

πŸ“¦ Key Directories Deep Dive

frameworks/base/

The heart of the Android Framework. Read these:

frameworks/base/
β”œβ”€β”€ core/java/android/         # Public Android APIs
β”œβ”€β”€ services/core/java/        # System services (AMS, WMS, PMS)
β”œβ”€β”€ core/jni/                  # JNI bridge to native code
└── cmds/                      # System command-line tools

system/core/

Low-level system daemons:

system/core/
β”œβ”€β”€ init/       # Android init process (PID 1)
β”œβ”€β”€ adb/        # ADB daemon
β”œβ”€β”€ fastboot/   # Fastboot protocol
└── libutils/   # Base utility libraries

hardware/interfaces/

HIDL/AIDL HAL interface definitions:

hardware/interfaces/
β”œβ”€β”€ audio/
β”œβ”€β”€ camera/
β”œβ”€β”€ sensors/
└── wifi/

πŸ” Reading AOSP Source Code

How to find anything fast

# Find all files with a class name
find . -name "ActivityManagerService.java"
 
# grep with context
grep -rn "startActivity" frameworks/base/services/core/ --include="*.java" | head -30
 
# Use cs.android.com (best for navigation)

Key source files to read first

FileWhy
system/core/init/main.cppEntry point of Android userspace
frameworks/base/core/java/android/app/ActivityThread.javaApp process main loop
frameworks/base/services/core/java/com/android/server/SystemServer.javaLaunches all system services
frameworks/base/core/java/android/os/Binder.javaIPC base class
build/soong/Android.bpBuild system entry

🧩 Android Runtime (ART)

ART replaced Dalvik in Android 5.0+.

  • AOT compilation: On install, .dex bytecode β†’ native machine code via dex2oat
  • JIT compilation: At runtime, hot paths get JIT compiled
  • Garbage Collection: Concurrent, generational GC
  • Profile-guided optimization (PGO): After first run, frequently-used paths get AOT compiled

Key ART files: art/runtime/, art/compiler/


πŸ› οΈ Hands-On Tasks

  1. Add a log line to SystemServer.java and rebuild framework only:

    mmm frameworks/base/services
    adb sync system
    adb reboot
  2. Add a new cc_binary hello world using Soong (Android.bp), build and push to emulator.

  3. Explore ActivityThread.java β€” find where onCreate() is called.

  4. Read SystemServer.java β€” list all services started in startOtherServices().


βœ… Phase 2 Checklist

  • Can explain all 5 layers of Android architecture
  • Understand Soong build system (Android.bp)
  • Can build a single module (mmm)
  • Know top-level dirs: frameworks/, system/, hardware/, art/
  • Read SystemServer.java and listed all started services
  • Read ActivityThread.java β€” understand app main loop
  • Added a custom Android.bp module and built it
  • Can use cs.android.com for code navigation
  • Understand what ART does vs Dalvik

Related