Hey All! We all are mostly busy in building Android applications with best practices and with fancy libraries which abstract most of the things for us and often don’t make time to understand thoroughly behind the scenes.
Sometimes we go into the documentation and see that also, but then very rarely we care what all happens when the phone becomes alive for the first time or when it reboots.

PC: Official android source code

I am presenting you this journey of system boot on a high level till the time you open your own app, so you have a clear idea about the sequence of the process happening during this time.

  1. Power On and Boot Sequence: When you turn on your Android device, the first thing that happens is the power-on self-test (POST) to check the hardware’s basic functionality. Then, the bootloader is activated, which is a small program that initializes the device’s hardware and prepares it for loading the operating system. (Abstracting bootloader initialization with Boot ROM)
  2. BootLoader and Kernel Loading: The bootloader’s main task is to load the Linux kernel, which is the core of the operating system. The kernel initializes hardware components, manages memory, and provides essential services. Once the kernel is loaded into memory, it is executed, and the device transitions from the bootloader phase to the kernel phase.
  3. Init Process and System Services: The kernel starts the init process, which is the first user space process. Init is responsible for starting the system services, daemons, and other processes that are crucial for the operating system’s functioning. These processes include the SurfaceFlinger (for handling graphics and UI), Zygote (for managing app processes), and various hardware-specific services.
  4. System Server Initialization: The system server is a critical component that manages various high-level system services, such as the Package Manager (manages apps and their data), Activity Manager (manages app lifecycle), and WindowManager (manages window placement and UI hierarchy). These services work together to create the overall user experience.
  5. Zygote and App Process Creation: When you launch you own app, the Zygote process, which is a template for new app processes, is forked. This process serves as the basis for the new app’s runtime environment, enabling faster app launch times through a technique called process forking.
  6. App Initialization and UI Rendering: The new app process initializes and its Application class’s onCreate method is called. This is where the app sets up its initial state. You can initialize the components you want to use and can make lazy initializations if they ain’t required until their first use.
  7. App Components and Lifecycle: Android apps are built using various components, such as Activities, Services, Broadcast Receivers, and Content Providers. Activities represent the UI, Services perform background tasks, Broadcast Receivers listen for system-wide events, and Content Providers enable data sharing between apps. These components interact following the Android lifecycle.
  8. App Launch and UI Interaction: When you open an app, its main activity is started by the system’s Activity Manager. The app’s UI elements are displayed on the screen, and you can interact with them through touch or other input methods.
  9. App Execution and Functionality: The app performs its intended functionality, such as displaying information, processing user input, and interacting with various system services and APIs. This can involve network requests, data processing, and more.
  10. App Termination or Background Execution: The user can close the app by navigating away from it or pressing the device’s home or recent apps button. At this point, the app might enter the background or be terminated, depending on the system’s resource management and the app’s lifecycle state.

That’s a simplified overview of the journey from a phone reboot to opening a non-system application on the Android operating system. Keep in mind that Android is a complex ecosystem with many layers of interaction, so there are more details and intricacies involved in each step. I’ll cover the application launch process in more detail in another article as in how various resources are gathered, bytecode compilation happens, Manifest file is read to locate and load the app components to eventually turn into what you see as the first screen in your app; Main Activity.

A daemon is a type of background process that runs on a computer or operating system, typically without direct user interaction. They are often started during system boot and continue to run in the background, waiting for specific events or requests to perform their designated tasks.

Here are some key characteristics and examples of daemons:

  1. Background Process: Daemons operate behind the scenes, without requiring direct user input or interaction. They handle tasks that are necessary for the system’s operation or to provide specific services.
  2. Autostart on Boot: Daemons are usually configured to start automatically when the operating system boots up. They are part of the system’s startup process and remain active throughout the system’s uptime.
  3. Independence: Daemons are independent processes that can run separately from user sessions. They continue running even if no user is actively logged into the system.
  4. Specialized Tasks and Services: Daemons are responsible for various system services, such as managing network connections, handling print jobs, monitoring hardware events, managing system logs, and more.

That’s all what I had to share. I’ve explored this from various sources and based on the work experience I had in one of my companies where I got to explore a bit about AOSP. You can find all the related classes and their interaction in Android Open Source Code (AOSP).


The above discuss is mere high-level and for the sake of understanding the components involved in the process and their interaction with each other. Please make time to google any of the components which are alien in this article because they are the key ones for Android so good to have this knowledge in depth. Feel free to improve the article by putting your comments so I’ll try to improvise/correct/more comprehensive if need be.

Happy Learning, Happy Sharing!!

Your claps on the article will motivate for future articles for sure!

Github: https://github.com/kanch231004/
Linked in https://www.linkedin.com/in/kanchan-pal-44ba35106/

Let’s connect on medium to stay tuned for more such articles in future.


Source link