Android Boot process introduction

This article provides information about the major components of the Android Boot process.

Narendra Harny
Make Android
10 min readNov 30, 2023

--

Photo by Rohit Tandon on Unsplash

The Boot Process is an essential part of any operating system which is the primary phase of user interaction level where waiting time for the system to up is crucial. This is why boot time optimization is always the focus of any product customization of Android-based custom products. The boot process involves many essential components that play a crucial role not even in the boot process as the core of the complete Android Ecosystem.

Bootloader Initialization

The bootloader plays an essential role in the boot-up process of a computer or mobile device, including Android devices.

Hardware Initialization: The bootloader initializes elementary hardware components, providing that the hardware is in a stable and consistent state for the rest of the boot process and certainly involves configuring the CPU, memory, and other essential hardware components.

Boot Image Selection: A boot image typically incorporates the kernel and an initial file system (initramfs or initrd). The bootloader provides alternatives for choosing various boot images based on current requirements, such as recovery mode or normal boot.

Kernel Loading: The kernel is the core system element which manages the hardware and other crucial functions. Once the bootloader has picked the boot image, it loads the kernel into memory.

Device Integrity Checks: Bootloaders usually accomplish integrity checks on the loaded kernel and boot image to ensure they have not been tampered with.

Handover to Kernel: The bootloader hands control over to the kernel once loaded into memory, and then it takes charge of initializing the remains of the operating system components

Kernel Initialization

The kernel plays a crucial role in the boot process of an operating system, including Android. Here’s what the kernel does during the boot process.

Hardware Initialization: The kernel is accountable for setting up and controlling the critical hardware elements of the device, such as the CPU, memory, input/output devices, and storage devices. It ensures that the hardware is in the state to be used by OS components and applications.

Memory Management: The kernel manages memory allocation and ensures that memory is unrestricted for the operating system and running applications. It constructs a virtual memory space and maps physical memory. It handles page tables to maintain memory protection and isolation.

Device Driver Initialization: The kernel loads and initializes device drivers for various hardware components, such as the display, network interfaces, audio, and more. These device drivers allow the kernel to intercommunicate with and control these hardware devices.

File System Initialization: The kernel initializes the file system and mounts the root file system, which contains the operating system’s core files and directories. It ensures that file systems are mounted and accessible.

Process Management: The kernel handles various processes during the boot. It creates the first user space process, usually called the init process. The init process is responsible for starting the rest of the system’s user-level process and other services.

Interrupt Handling: The kernel manages hardware interrupts and exceptions. It sets up interrupt handlers to react to events like user input, hardware errors, and system calls.

Initialization of Critical Subsystems: The kernel initializes critical subsystems such as the scheduler, which manages task execution and CPU allocation, and the memory management unit (MMU), which controls memory protection and translation.

User Space Initialization: The kernel starts the user-space environment, in the case of Android, this involves launching the init process, which reads the device’s init.rc configuration and starts the Android runtime environment, system services, and other essential user space components.

Handover to User-space: Once the user-space environment is set up, the kernel transfers control to the init process or the users-pace environment, allowing the Android system to continue booting, initializing system services, and launching apps.

Start INIT Process

The init process, short for “initialization process,” is a crucial component in the boot process of Unix-based operating systems, including Android. Its primary responsibilities during the boot process include.

User Space Initialization: The init process is the first user space program to be executed when the kernel starts. It serves as the gateway to the user space environment, setting up the system’s initial user space components.

Reading Configuration: Init reads configuration files, such as /init.rc in the case of Android, to determine how the system should be initialized. These configuration files specify which programs and services to start, their order, and their dependencies.

Starting System Services: Init is responsible for launching essential system services, daemons, and system-level processes. These services include core components like the Android Package Manager, Activity Manager, and various system daemons.

Process Spawning: Initiates new processes based on the information provided in the configuration files. For example, it spawns the zygote process, which serves as a template for creating new app processes and improving app startup times.

Handling Runlevels: On traditional Unix systems, init can manage different runlevels, allowing the system to boot into various states (e.g., single-user mode, multi-user mode, graphical mode). Android’s init is typically simplified and tailored for the Android environment, but it retains the core responsibility of managing system services.

Monitoring and Restarting: Initiates the state of system services and processes. If a service or process terminates unexpectedly, init can be configured to restart it automatically.

Dependency Resolution: Init ensures that services and processes are started in the correct order, considering dependencies. For instance, some services may need to start before others to ensure a smooth boot process.

Event Handling: Init can respond to specific events or triggers during the boot process. It can execute actions or scripts in response to events like USB device insertion or network connectivity.

Prepare Android Runtime

During the Android boot-up process, the Android Runtime (ART) plays a vital role in executing Android applications. ART is the runtime environment responsible for running Android apps, and it has evolved from its predecessor, Dalvik. Here’s what ART does in the boot-up process.

Loading and AOT Compilation: ART loads and compiles Android app bytecode into native machine code during the boot process. This process is known as Ahead-of-Time (AOT) compilation. Unlike Dalvik, which used Just-In-Time (JIT) compilation, ART’s AOT compilation occurs at installation time or during the device’s boot-up. This results in improved app performance and reduced runtime overhead.

App Execution: After AOT compilation, ART is ready to execute Android apps. When an app is launched by the user, ART loads the precompiled native code, reducing the time required to start the app and execute its functions. This leads to faster app responsiveness.

Runtime Optimization: ART continues to optimize app performance at runtime. It uses profiling and on-device instrumentation to identify areas for further performance improvements. These optimizations are applied without user intervention and help ensure smooth app execution.

Memory Management: ART is responsible for managing the memory used by Android apps. It handles memory allocation and garbage collection, freeing up memory when apps are no longer using it. Proper memory management is essential for maintaining the stability and performance of the Android system.

Security: ART incorporates security features to protect the Android device. For example, it enforces runtime permissions, which restrict app access to sensitive resources, enhancing user privacy and security.

Compatibility and Portability: ART is designed to improve app compatibility and portability across different Android devices and architectures. It achieves this by consistently executing apps, regardless of the underlying hardware.

Zygote Process Initialization

During the boot-up process of an Android device, the Zygote process plays a unique and important role. Zygote is a special parent process that serves as a template for launching Android app processes. Here’s what Zygote does in the boot-up process.

Preloading Common Libraries: Zygote preloads commonly used libraries into memory during the device’s boot process. These libraries include core Android libraries and resources that many apps rely on. By preloading them, Zygote reduces the startup time for new app processes.

Creating the Zygote VM: Zygote initializes its own Virtual Machine (VM), which is a separate runtime environment for Android apps. This VM is a clean and pristine environment, free from any app-specific data or code.

Forking App Processes: When a user launches an Android app, Zygote forks itself to create a new process. The new process inherits the preloaded libraries and resources from Zygote. This forking process is much faster than starting a new process from scratch since the common libraries are already in memory.

App Process Initialization: The new app process, created from Zygote, loads the app’s specific code and data. This includes the app’s bytecode, resources, and assets. The app process then proceeds to execute the app’s main function or entry point.

Improved App Startup Time: Zygote’s preloading of common resources and the forking process significantly reduce the time it takes to start a new app. This optimization enhances the responsiveness of the Android device and the user experience.

Isolation and Security: Each app process created from Zygote runs independently and is isolated from other app processes. This isolation is crucial for security and stability, as it prevents apps from interfering with each other or accessing each other’s data.

System Server Start

SystemServer is a crucial component in the Android boot-up process. It serves various critical tasks during the device’s initialisation.

Initialization of Core System Services: SystemServer is accountable for starting and initializing core system services, such as the Package Manager, Activity Manager, etc. These services are essential to the Android operating system’s functionality.

System Service Registration: SystemServer registers these system services in Android so that the services can be accessible to other parts of the system and applications. For instance, the Activity Manager service is entitled to the management of the Android app lifecycle.

Window Manager Initialization: The Window Manager is responsible for managing windows, user interfaces, and graphical elements on the device’s screen. SystemServer initializes the Window Manager service to handle the display and user interface aspects of Android.

Activity Manager Startup: SystemServer also starts the Activity Manager service, which is crucial for managing the lifecycle and interaction of applications and user interface components. It is responsible for launching and managing app processes and activities.

Content Providers and Other Services: In addition to Package Manager, Activity Manager, and Window Manager, SystemServer initializes various other system services, such as Content Providers, Location Manager, and Notification Manager. These services provide core functionality and resources for apps and the system.

Boot Animation: SystemServer may also manage the boot animation displayed on the screen during startup. This animation provides visual feedback to the user while the system is being initialized.

System Event Handling: It handles various system-level events and ensures that the appropriate services are started or stopped in response to these events. This includes handling device configuration changes and system updates.

Secure Startup: SystemServer may be involved in managing secure boot processes, such as verifying the system’s integrity and ensuring that secure hardware features are properly initialized.

Permission and Security Initialization: It sets up permissions and security policies, ensuring that apps and services run within their designated security contexts and have the appropriate level of access to device resources

Applications Startups

App initialization can be a vast topic because the outcome of the boot-up process is user interaction, which means the app’s interface is available to be used.

Apps are divided mainly into two types System Apps and User Apps.

System apps are known as built-in apps which are typically installed in the system partition of the device during the integration process of the final binary. These apps provide core functionality and services for the Android system. and are responsible for various aspects of the device’s operation.

Example: Launcher, System UI, Settings

System apps are granted special privileges and permissions, allowing them to access system-level resources and services. They are essential for the proper functioning of the device. During the Android boot-up process, system apps are started early, often by the system server (SystemServer). They provide core system functionality, and their initialization is critical to the device’s stability and usability. User apps are not part of the core Android operating system and are not pre-installed on the device. They serve a wide range of purposes, from productivity and entertainment to games and utilities.

Thanks for Reading! If this article was helpful. Please hit the clap!

Follow on medium https://medium.com/@narendra147h

Connect on Linked In: linkedin.com/in/narendraharny

Please Follow & subscribe to Make Android Publication by Narendra K H for prompt updates on Android platform-related blogs.

Thank you!

--

--

Narendra Harny
Make Android

Connect on https://medium.com/make-android | Write On, Android AOSP & Applications | Python | DevOps | Java | C++ | Kotlin | Shell | Linux | Android Auto | IVI