# Android Architecture

### 📌Android Boot Process

The Android boot process involves several key stages, each responsible for setting up different system components. The following diagram illustrates the boot sequence:

<figure><img src="https://4027909796-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwb35XsfjdYzmAOhXx0Kp%2Fuploads%2FBWEqh1KsoO45aMirogrJ%2FandroidArch.png?alt=media" alt=""><figcaption></figcaption></figure>

* When you press the power button on an Android device, the hardware initializes. The CPU receives power, starts up, and communicates with the **ROM** (the Android system installed on the device). The ROM can be either a **stock ROM** (original from the manufacturer) or a **custom ROM** (modified by users/developers).
* The **bootloader** checks the device’s partition table and loads the **kernel** (the core of Android, responsible for hardware-software communication). Manufacturers usually lock the bootloader to prevent tampering, but users can unlock it to install custom systems or dual-boot multiple OS versions.
* The kernel acts as the core of the operating system, managing hardware components like the CPU, RAM, and device drivers. It also starts essential processes such as:
  * **Activity Manager**: Handles app processes.
  * **Power Manager**: Optimizes battery usage.
  * **Zygote**: Preloads app templates to speed up app launch times.

### 📌**Android Architecture**

Android’s software architecture consists of multiple layers, each playing a vital role in system functionality. The following diagram illustrates the Android architecture:

<figure><img src="https://4027909796-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwb35XsfjdYzmAOhXx0Kp%2Fuploads%2FzcBWz3PEuhheZqyA02gw%2Fandroid%20stack_2x.png?alt=media" alt=""><figcaption></figcaption></figure>

### **📍Linux Kernel**

* Foundation of the Android architecture.
* Manages hardware components such as CPU, memory, and device drivers.
* Provides key services including:
  * **Device Drivers**: Support for hardware like Bluetooth, Wi-Fi, USB, and displays.
  * **Binder IPC (Inter-Process Communication)**: Enables secure communication between applications and system services.
  * **Power Management**: Optimizes battery usage.

### **📍Hardware Abstraction Layer (HAL)**

HAL acts as a bridge between the hardware and higher-level software components. It ensures that different manufacturers' hardware components (e.g., camera, sensors, Bluetooth) work without modifying the core Android code.

### **📍Native C/C++ Libraries**

* Libraries provide essential system functions, written in C/C++.
* Include important components like:
  * **OpenGL ES**: Graphics rendering for games and UI elements.
  * **Media Framework**: Supports audio and video playback.
  * **WebKit**: Web browsing engine.
  * **SQLite**: Database management.

### **📍Android Runtime (ART)**

Originally, Android used Dalvik, a runtime with Just-In-Time (JIT) compilation, which executed apps dynamically. Since Android **5.0**, ART (Ahead-Of-Time compilation) replaced Dalvik, pre-compiling apps for improved speed and battery efficiency.

### **📍Java API Framework**

* Provides high-level services and APIs to developers.
* Manages user interface elements and application resources.
* Key components include:
  * **Activity Manager**: Manages app lifecycle and navigation.
  * **Content Provider**: Facilitates data sharing between apps.
  * **Resource Manager**: Access to non-code resources.
  * **Telephony Manager**: Handles phone communication functions.
  * **Notification Manager**: Manages system notifications.
  * **Location Manager**: Handles GPS and location-based services.

### **📍System Apps**

* Contains user-installed apps and pre-installed system apps.
* Runs within the Android Runtime.
* Types of applications:
  * Pre-installed apps (Contacts, Camera, Settings).
  * Third-party apps (Facebook, Twitter).

### �&#xDCCC;_**Security and User Data Encryption**_

During the boot process, Android decrypts user data, including passwords and fingerprints, using encryption keys. This ensures that unauthorized access to sensitive data is prevented. Additionally, sandboxing mechanisms isolate applications to maintain system security.

***
