AOSP Foundations
3 min read

The system/ Directory

Understand the core utilities, initialization scripts, and security policies that form the base of the Android OS.

While the frameworks/ directory contains the high-level Android features (like UI, Bluetooth, and Camera), the system/ directory contains the low-level Unix utilities and background daemons that keep the operating system breathing.

The code in this directory bridges the gap between the raw Linux kernel and the high-level Java framework.

Core Utilities (system/core)

The system/core directory is arguably the most important folder for device bring-up and low-level debugging. It contains the absolute minimum tools required to boot the device.

  • init: This is the very first user-space process started by the Linux kernel (Process ID 1). It reads configuration scripts (like init.rc), mounts the storage partitions, sets up security rules, and launches every other background daemon.
  • adb and adbd: The source code for the Android Debug Bridge client (which runs on your Ubuntu host) and the daemon (which runs on the phone).
  • fastboot: The source code for the bootloader flashing utility.
  • logcat: The utility that reads the circular log buffers in memory and prints system logs to your terminal.
# The 'init' system is defined by .rc scripts parsed during boot
# Example syntax found in system/core/rootdir/init.rc:
on boot
    # Basic network init
    ifup lo
    hostname localhost
    domainname localdomain

Core Libraries

Because Android relies so heavily on C++, Google wrote several generic foundational libraries to prevent developers from constantly rewriting common utility functions.

  • system/libbase: A collection of highly optimized, incredibly safe C++ utility classes. It provides standard methods for reading/writing files, handling strings, and managing system properties. Whenever possible, AOSP native code should use libbase rather than standard C library equivalents.
  • system/logging: Contains liblog, the core C++ library used by every native process to write diagnostic messages into the system's log buffers (which are later read by logcat).
// Example of using libbase for safe file reading in AOSP C++
#include <android-base/file.h>
#include <string>

std::string content;
if (android::base::ReadFileToString("/sys/class/power_supply/battery/capacity", &content)) {
    // Successfully read battery capacity!
}

Security Policies (system/sepolicy)

Android utilizes Security-Enhanced Linux (SELinux) to enforce Mandatory Access Control (MAC). SELinux is what prevents a compromised flashlight app from reading your banking data, even if the app somehow gains root privileges.

The system/sepolicy directory is entirely dedicated to this security architecture.

  • Policy Files (.te): These are text files defining strict rules (e.g., "Allow the Camera daemon to access the GPU memory, but deny it access to the network stack").
  • Compilation: During the build process, the tools in this directory compile hundreds of these text files into a single, massive binary policy file that the Linux kernel enforces at runtime.

When developing custom hardware features, you will almost certainly encounter "SELinux Denials". You will spend a significant amount of time in system/sepolicy writing custom rules to allow your new code to execute legally.

# Debugging SELinux denials in real-time
adb logcat | grep 'avc: denied'