Power on and system startup
When we switch on our android mobile, Boot ROM code starts its execution from a pre-specified location which is hardwired on Reading Only Memory. It loads Bootloader into Random Access Memory and starts execution.
The bootloader is one type of small program. An Android operating system run after bootloader process. The bootloader is the first process to run. There are many popular bootloaders are available. The manufacturer can use readymade bootloaders like redboot, uboot etc or they can develop own bootloaders. The bootloader is not a part of an android operating system.
There are two stages of bootloader,
- Bootloader detects external Random Access Memory (RAM) and loads a program which will be helpful in the second stage.
- Bootloader setup network, memory etc. which requires running kernel.
Location of bootloader : <Android Source>\bootable\bootloader\legacy\usbloader
Linux kernel starting process and android kernel starting the process are similar. This process will setup cache, protected memory, scheduling, and loads drivers. When kernel completed the system setup it looks for “init” in the system files and launches startup process or first process of the system.
This is the first process, or in other words, it is a boss of all processes. There is two responsibility of init process.
- mount directories like /sys, /dev, /proc
- run init.rc script.
Location of init process: <android source>/system/core/init
Location of init.rc file: <android source>/system/core/rootdir/init.rc
Zygote and Dalvik Virtual Machine
We know that in java there is Java Virtual Machine (JVM), but in the android virtual machine must be run as fast as possible. Suppose you have three apps running simultaneously, and it needs three Dalvik virtual machines, but it consumes lots of memory and time. As a solution to this problem, android has a facility named Zygote. The Zygote enables code sharing across the Dalvik Virtual Machine. The zygote is a process wich starts at the time of system boot. Zygote preloads and initializes core library classes.
Zygote loading process:
- Load ZygoteInit class,
- registerZygoteSocket() – It registers a server socket for zygote command connections.
- preloadClasses() – Is a simple text file that contains a list of classes that need to be preloaded, you can find the file at <android source>/framework/base
- preloadResources() – Everything that is included in the android.R file will be loaded with this method (themes and layouts).
At this time, boot animation will be displayed.
- Starting Power Manager
- Creating Activity Manager
- Starting Telephony Registry
- Starting Package Manager
- Set Activity Manager Service as System Process
- Starting Context Manager
- Starting System Context Providers
- Starting Battery Service
- Starting Alarm Manager
- Starting Sensor Service
- Starting Window Manager
- Starting Bluetooth Service
- Starting Mount Service
- Starting Status Bar Service
- Starting Hardware Service
- Starting NetStat Service
- Starting Connectivity Service
- Starting Notification Manager
- Starting DeviceStorageMonitor Service
- Starting Location Manager
- Starting Search Service
- Starting Clipboard Service
- Starting Checkin Service
- Starting Wallpaper Service
- Starting Audio Service
- Starting HeadsetObserver
- Starting AdbSettingsObserver
When all system services running in memory, android has completed the booting process.