File system
Android devices typically have a partitioned storage system, where the storage is divided into different partitions, each serving a specific purpose.
-
/system: This directory contains the Android operating system and system applications. It is read-only to ensure the integrity of the system. Modifying files in this directory could potentially harm the device.
- /app: prebundled apps from Google, as well as any vendor or carrier-installed apps
- /bin: various daemons, as well as shell commands contain
bootanimation,dalvikvm, adb,
etc. - /etc: Miscellaneous configuration files
- /framework: contained in .jar files, with their executable dex files optimized alongside them in .odex .
- /lib: native ELF shared object (.so) files. This directory serves the same role as /lib in vanilla Linux.
- /media: Alarm, notification, ringtone and UI-effect audio files in .ogg format,and the system boot animation
- /usr: Support files, such as unicode mappings (icudt511.dat), key layout files for keyboards and devices, etc.
- /vendor: Vendor specific files
-
/data: This directory stores user data, settings, and application data. It includes subdirectories for individual apps, each identified by its package name. User-generated data, app preferences, and other user-specific information are stored here.
- /anr: Used by EVNQTUBUF to record stack traces of non-responsive Android Apps.
- /app: User-installed applications. Downloaded .apk files can be found here.
- /data: Data directories for installed applications Each application gets its own subdirectory, in reverse DNS format example
com.android.providers.calendar
-
/cache: This directory is used for storing temporary files, such as cached data from applications. Clearing the cache can help free up storage space, but it won’t delete essential app data.
-
/mnt or /storage: These directories are used for mounting external storage devices like SD cards or USB drives. The actual path may vary across devices and Android versions.
-
/sdcard or /storage/emulated/0: This is the default directory for the primary external storage on the device. It’s often used to store user-accessible files such as photos, videos, and downloaded content. Note that on many modern devices, the “sdcard” directory might actually be part of the internal storage and not necessarily refer to an external SD card.
-
/proc: This virtual directory contains information about system processes. It provides a way to access real-time information about the system and running processes.
-
/dev: This directory contains device files representing hardware components and peripheral devices. It allows communication between the kernel and these devices.
-
/sbin and /bin: These directories contain essential system binaries and executable files needed for the device’s basic functionality.
-
/etc: This directory contains configuration files used by the system and various applications.
-
/lib: This directory contains shared libraries needed by the system and apps. These libraries provide essential functions and services.
-
/vendor: This directory contains files related to the device’s hardware, including proprietary drivers and firmware.
Android Partitions and Filesystems
- Apps are sandboxed, installed under
/data
Partition | Mount Point | What it Stores |
---|---|---|
boot | N/A | Linux kernel + initramfs (ramdisk) |
recovery | N/A | Alternate boot image (TWRP, stock recovery) for flashing, factory reset, etc. |
system | /system | Core Android OS (frameworks, preinstalled apps, shared libraries) |
vendor | /vendor | Hardware-specific code (HALs, drivers) |
product | /product | Optional: manufacturer or AOSP components (split from /system ) |
data | /data | App APKs, databases, user settings, internal app storage |
metadata | N/A | Encryption keys and metadata |
misc | N/A | Bootloader settings, crash logs, hardware configs |
cache | /cache | OTA updates, logs, temporary files |
odm | /odm | Optional Device Manufacturer partition for vendor override configs |
sdcard | /sdcard , /storage/emulated/0 | User files (images, downloads, WhatsApp backups) |
boot process
- Bootloader (Boot ROM):
- When you power on the Android device, the Boot ROM (Read-Only Memory) or bootloader is the first piece of code that runs.
- The bootloader is responsible for initializing hardware components, checking for the connected peripherals, and loading the next stage of the boot process.
- Bootloader Stage 2:
- The second stage of the bootloader is often responsible for loading the Android kernel into memory.
- It may also initialize the root file system and prepare for the transition to the Linux kernel.
- Linux Kernel Initialization:
- Android is built on the Linux kernel. Once the bootloader hands control over, the Linux kernel is loaded into memory.
- The kernel initializes the device’s hardware, such as the CPU, memory, display, input devices, and various peripherals.
- Init Process:
- The init process is the first user-space process started by the Linux kernel. It has process ID 1 and is responsible for initializing the Android system.
- The init process reads the
init.rc
file, which contains instructions for initializing various system properties and starting essential system services.
- Zygote and System Server:
- The Zygote process is a special system process that serves as a template for creating new application processes. It helps to speed up the launch of apps by preloading some common resources.
- The system server is started by the init process and manages core system services like the package manager, window manager, and telephony services.
- Android Runtime (ART or Dalvik):
- The Android Runtime (ART) or Dalvik (in older versions) is responsible for running Android applications. ART is the default runtime as of Android 5.0 (Lollipop).
- The runtime loads and executes the bytecode of Android apps.
- System Services and User Interface:
- As the system server starts, it initiates various system services that are essential for the functioning of the Android operating system.
- The user interface components, including the home screen and launcher, are also started during this phase.
- App Launch:
- Finally, the Android device is ready for use, and the user can interact with the system. Apps can be launched, and the user interface becomes responsive.
Android Debug bridge
CMD line tool it allows developers to communicate with and control Android devices over a USB connection or a TCP/IP network connection. ADB is a versatile tool that provides a wide range of functionalities for debugging, installing and uninstalling apps, copying files, and more.
adb is a client-server tool that includes three main components:
- a client that runs on your development machine and sends commands. You can execute it from a command line by running an adb command.
- a daemon (adbd) that runs as a background process on each device and executes commands on a device.
- a server that manages communication between the client and the daemon, it runs as a background process on your development machine.
How to connect
- Install adb pkg in linux by
sudo apt install adb
- From Android 5.0 (Lollipop) onward, Dalvik was replaced by ART (Android Runtime).
The FastBoot Protocol
How app run
Java applications are typically compiled from .java
files into .class
files, which contain JVM bytecode. These are executed by the Java Virtual Machine (JVM), a stack-based virtual processor that interprets the bytecode instructions.
Android, however, uses a different approach. Although it starts similarly by compiling .java
into .class
files, it then uses a tool called dx
to convert all .class
files into a single classes.dex
file. This file contains bytecode for the Dalvik virtual machine, which is register-based rather than stack-based. This allows for better performance and smaller file sizes.
The classes.dex
file, along with other resources, is packaged into an APK (Android Package). When an APK is installed on an Android device, the classes.dex
file is extracted and compiled into native machine code. This native code is stored in the /data/dalvik-cache
directory and used for subsequent app launches to improve performance.
To optimize startup speed, Android uses a process called Zygote. Zygote is a pre-initialized process that quickly forks to start new app processes, significantly reducing the time needed to launch an app.
Android’s Message Queue System
Android apps run on a main thread (also known as the UI thread). This thread is crucial because it’s responsible for updating the UI, handling user interactions, and processing other events (such as network responses or sensor data). Every operation that modifies the UI must go through the main thread.
Message Queue:
- When you make a call like
textView.setText()
, Android doesn’t immediately update the UI. Instead, it places a message in the message queue of the main thread. - The main thread will process this queue sequentially, one message at a time. This is part of a system called Looper (the main thread is constantly running a Looper, which processes this queue).
The Looper reads messages from the queue, processes them, and updates the UI accordingly.
UI Thread (Main Thread) and Its Importance
The UI thread (also called the Main Thread) is the heart of Android’s interaction with the user. It’s the thread that Android uses to handle user input, update the UI, and communicate with the operating system. It’s where most of your code will execute, including your onCreate()
, onClick()
, onResume()
, and other lifecycle callbacks.
-
UI thread is single-threaded: This means that it can only perform one task at a time. If you’re performing a long-running operation (such as downloading data, performing complex calculations, or accessing the network) on the UI thread, it will block the thread. This results in UI freezes and unresponsiveness, which is a poor user experience.
-
Message Queue on the UI Thread: Every interaction with the UI, like
textView.setText("Hello")
, is placed in the message queue. When the UI thread is free to process a message (after handling the current task), it updates the screen.
Tool
-
https://www.charlesproxy.com/ → to proxy the network request