Skip to main content

What happens when you press the power button of an Android device?


When switching off the power of an Android device and switch on it again, this process is known as the Android Booting sequence.

Did you ever think about what happens in between this process🤔?

The boot process, for starters, is nothing but a bunch of fancy images and animations for the end-user. 

This post aims at breaking the boot process down for those very end users. And I promise a thorough read is all you need to understand the process. Nothing is too complicated if explained the right way.



The above Image showing 5 stages of the Booting process for an Android-powered device:
  • 1st Stage is Boot ROM and Boot Loader
  • 2nd Stage is Kernel
  • 3rd Stage is Init
  • 4th Stage is Zygote and DVM
  • 5th Stage is SystemServer and Managers

Boot ROM

The code responsible for the section named “Boot ROM” is executed as soon as the power button is held. The point of origin for the code happens to be a predefined, hardcoded location. The code loads the bootloader into the RAM and executes itself.

Bootloader

The bootloader is a code that is responsible for running different operating systems in any device. Therefore bootloader is not specific for Android only. It comprises several codes which makes the booting process happen from beginning the startup process to set up memory management and security options.

A bootloader consists of two major files: init.s and main.c. Init.s initializes the stacks and BSS segments and the main.c is responsible for start-up hardware parts like keyboards, system clock, console, etc.

Kernel

Well, this is one of the most important parts of booting your Android device. After the process of Bootloader, the Kernel starts its process. It set up a cache memory, load drivers, mount files, start kernel daemons, etc.

Once the work of the kernel is done it looks for the init process to launch the root process. The Kernel allows your software to connect with your hardware. Without Kernel your system won’t even start.

Init.s

The init is the root process or the grandfathering process to boot-up your Android OS. The two main processes of init are:
  1. Mounts directories like /sys, /dev or /proc.
  2. Runs init.rc script
The init process can be accessed at: /init::<android source>/system/core/init.

Init.rc file can be traced at : <android source>/system/core/rootdir/.

Zygote and VM

When an Android OS boots up, the zygote is the first Android-specific process to execute. The Zygote is triggered by the command app_process. At first, a VM is created and then a call is send to Zygote’s main() function.

Zygote preload all the resources of the system and classes used by the Android Framework. It is a virtual machine process that is responsible for the start-up of the booting system.

The Zygote loading process includes:
  • Load Zygote Init class:
<android

source>/frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
  • registerZygoteSocket(): Registers a server socket for the Zygote command.
  • preloadClasses(): A text file containing a list of classes that need to be preloaded. You can locate the file at <android source>/framework/base
  • preloadResources(): With this method, everything included in the android R file will be loaded.

System Service

After the above processes are completed, the system services are being launched by Zygote. The core service provided by Zygote to launch the system services are:

  • Starting power manager.
  • Creating the activity manager.
  • Starting telephony registry
  • Starting package manager.
  • Set activity manager serves as a system process.
  • Starting context manager
  • Starting system contact providers.
  • Starting battery service
  • Starting alarm manager
  • Starting sensor service
  • Starting window manager
  • Starting Bluetooth service
  • Starting mount service

Conclusion

Android Kernel was built mainly focussing on mobile OS platform. Though Android was built on a Linux platform, the android kernel version is very much different from Linux Kernel. Developers made memory management on the Linux kernel OS ( Linux kernel was built for running desktops) and developed Android Kernel.


Throughout the years since it was first introduced, Android has become the leading Operating System for mobile phones. And the OS is getting advanced day by day. I just hope that my article will help you with your urge to learn about Android Internals and Android OS.

Comments