Gopalakrishnan M
21. November 2024 Categories: Technology,

Optimizing Android boot time is a crucial task in embedded systems, especially for devices in automotive, consumer electronics, and IoT sectors, where faster startup times directly translate to improved user experience. The journey towards reducing Android boot time starts with a thorough understanding of the boot process of the target platform. In general, any Android-powered device passes through a series of well-defined stages during its boot sequence. These include Boot Loader, U-Boot (optional), Kernel, and finally, Android framework initialization. Each of these stages plays a critical role in bringing up the device and has its own set of optimization opportunities.

Android Boot-process

Android Boot-process


Boot Loader

The Boot Loader is the first code that executes when a device is powered on. Residing in non-volatile storage like ROM or flash memory, its primary function is to initialize the most basic hardware elements essential for system startup. This includes configuring the system clocks, setting up memory, initializing power domains, and performing basic checks on the system's health. The Boot Loader also verifies the integrity of the subsequent boot stages to ensure that only authenticated and untampered code is loaded. Depending on the platform architecture, there might be multiple stages within the Boot Loader itself, such as Primary Boot Loader (PBL) and Secondary Boot Loader (SBL), each handling specific initialization routines.

U-Boot

U-Boot, short for Universal Boot Loader, is a secondary stage boot loader used in many embedded platforms. Not every Android device uses U-Boot, but in platforms where it is present, it provides a rich set of features for booting flexibility and development convenience. U-Boot supports multiple storage interfaces, various boot media like eMMC, NAND, NOR, and SD cards, and offers environment variables for configuration settings. It can decompress kernel images, provide a boot menu, and handle recovery or fastboot modes for system debugging. Optimizing U-Boot involves disabling unnecessary features, reducing boot delays, and fine-tuning storage access speeds.

Kernel

The Linux Kernel is the heart of the Android platform. Once loaded by the Boot Loader or U-Boot, the Kernel is responsible for initializing the hardware, setting up drivers, and mounting the root filesystem. During the Kernel boot phase, device-specific drivers and platform-specific configurations come into play. Any delay in driver initialization or waiting for hardware peripherals to become ready can directly impact the boot time. Kernel optimization techniques include reducing driver initialization times, enabling asynchronous driver loading, and disabling unused features or debug logs to streamline the startup process.

Android

After the Kernel has set up the hardware and basic services, control is passed to the Android userspace. This phase involves the initialization of the Android Runtime (ART) and various framework components. The Android boot process itself is divided into several sub-stages:

Init

Init is the first user-space process started by the Kernel. It reads configuration files like init.rc to mount file systems, set permissions, start essential daemons, and initiate the rest of the Android framework. Optimizing init involves reducing the number of services started at boot, deferring non-critical services, and simplifying init scripts.

Zygote

Zygote is a critical component of the Android runtime responsible for launching app processes. In Android 13+, Zygote starts early during the boot process after the init process completes essential services. The main role of Zygote is to preload common classes, resources, and system libraries into memory, which are later shared across all app processes. This reduces memory footprint and speeds up app startup. Android 13 introduces optimizations in Zygote's class preloading and system server startup to reduce startup latency.

Key changes in Android 13+
  • Separation of 64-bit & 32-bit Zygote for architectures supporting both.
  • Use of usap (unspecialized app pool) to have pre-forked, ready-to-use app processes.
  • Move towards native isolated processes for sensitive services.
  • More Zygote preloading control via zygote-preload.xml.

System Server

System Server is the heart of Android's core services. Started by Zygote, the System Server process hosts key framework services like:

Services Role
ActivityManagerService (AMS) App lifecycle management Manages apps, activities, tasks
PackageManagerService (PMS) App installation & permissions Reads packages.xml at boot
PowerManagerService Power control Manages wake locks, sleep
WindowManagerService (WMS) UI window handling Controls app UI display
InputManagerService Input devices Keyboard, touch, gestures
ConnectivityService Network stack Wi-Fi, Mobile Data
DisplayManagerService Display handling Multi-display, HDR, refresh rates

In Android 13 and above, System Server has been optimized to start services in a staged manner, prioritizing essential services for faster user interaction readiness. Service dependencies are managed better to prevent bottlenecks during boot. Few core changes are listed below

  • Many services moved to Mainline modules (.apk or .apex) for OTA updates independent of system image.
  • Some services started in isolated sandboxes or dedicated processes for better security.
  • Boot optimization by deferring non-critical services.
  • Increased use of native (C++) services with HIDL/AIDL outside System Server for better performance.

Service Manager

The Service Manager is a binder daemon that handles registration and discovery of Android system services. It facilitates inter-process communication (IPC) between different processes and services in the system. From Android 13 onwards, Service Manager continues to follow a more secure and isolated architecture, reducing exposure of critical services and supporting newer binder communication features. Few core changes are listed below

  • Deprecating HIDL completely in favor of AIDL HALs.
  • AIDL gets versioning, stability, lazy loading.
  • servicemanager binary is more secure:
    • Namespaces restrictions
    • SELinux tightened
    • Only allowed services can register

It starts services in a strict order (to manage dependencies). Few examples

Service Responsibility
DisplayManagerService Screen / Display init
PowerManagerService Power / Wake locks
ActivityManagerService (AMS) App lifecycle manager
PackageManagerService Apps & permissions
WindowManagerService (WMS) UI / Windows control
InputManagerService Touch / Input events
ConnectivityService Network / Wi-Fi
AlarmManagerService Timers / Alarms
NotificationManagerService Notifications
LocationManagerService GPS etc

Other Daemons and Processes

Apart from System Server, several native daemons are launched during Android boot. These include:

  • vold (Volume Daemon) for storage management
  • surfaceflinger for display composition
  • audioserver for audio services
  • cameraserver for camera access
  • keystore2 for secure key storage

Android 13 further modularizes these daemons, with some components running as isolated processes or dedicated APEX modules for better security and updatability.

Core Applications

Once the system services and daemons are ready, the launcher application and other pre-installed apps are started. Core applications like System UI, Settings, and launcher are initialized.

Once all boot process completed, sys.boot_completed=1 will be set by AMS as broadcast to intiate all process that android booting is completed.

Android 13 introduces optimizations in launcher process management, background app restrictions, and splash screen handling to ensure a smoother and faster app experience immediately after boot.

Conclusion

Understanding the Android boot process is essential for identifying boot time optimization opportunities. From the Boot Loader to the Kernel, and all the way through Android Init, Zygote, System Server, and core applications, each stage has its own set of responsibilities and optimization levers. With Android 13 and newer versions, Google has introduced several architectural improvements focusing on modularity, security, and faster startup. A detailed analysis and profiling of each stage can significantly help in reducing boot times and enhancing the user experience.

Subscribe to our Blog