Systeam for A
The Android operating system, built on the Linux kernel, employs a hierarchical file system structure with distinct partitions and directories that handle critical system functions, user data, and hardware interactions. Below is an in-depth exploration of its core architecture, system files, and advanced features, supplemented with technical details and real-world examples:
Root Directory Structure
The root directory (/) serves as the foundation, containing essential partitions and directories:
/system: Houses the core Android OS files, including system apps, libraries, and frameworks. Subdirectories include:/system/app: Pre-installed non-privileged apps (e.g., Calculator)./system/priv-app: Privileged system apps with elevated permissions (e.g., Settings, Phone) ./system/liband/system/lib64: Native libraries (e.g.,libc.so,libart.so) for system services and app compatibility./system/framework: Framework APIs (e.g.,framework-res.apk,services.jar) used by apps./system/etc: Configuration files (e.g.,init.rc,hosts)./system/usr: User interface resources like fonts (/system/usr/fonts) and input methods .
/data: Stores user-specific data, including:/data/app: Installed apps' APKs and Dalvik/ART bytecode./data/data: Private app data (e.g., databases, preferences)./data/media: User-generated content (photos, videos).
/cache: Temporary files (e.g., app caches, downloaded updates) to optimize performance./sdcard(or/storage/emulated/0): User-accessible storage for media and files./vendor: Manufacturer-specific drivers, firmware, and customizations./procand/sys: Virtual filesystems providing kernel and hardware information.
Key Partitions
/boot: Contains the Linux kernel and initial RAM disk (initramfs) for system boot . The kernel image (Image) anddtb(device tree blob) are critical for hardware initialization./recovery: Recovery mode environment for system repairs and updates. Accessible viaadb reboot recovery, it supports tasks like flashing custom ROMs and wiping data ./misc: Miscellaneous settings (e.g., USB configuration, carrier IDs) ./metadata: Stores filesystem metadata, including encryption keys and disk usage statistics.
File System Permissions
Android enforces strict permissions to isolate apps and protect system integrity:
- Linux UID/GID: Each app runs under a unique user ID (UID) to prevent unauthorized access .
- SELinux: Mandatory access control (MAC) system that restricts processes' actions (e.g., network access, file writes) .
- Targeted Policy: Focuses on system services and apps, preventing privilege escalation.
- MLS (Multi-Level Security): Extends Targeted Policy with sensitivity labels for high-security environments.
- AppOps: Runtime permissions (e.g., camera, location) introduced in Android 6.0, managed via Settings.
Core System Files
/system/bin: Essential binaries (e.g.,adb,am,pm)./system/etc/init.rc: Initialization script that starts system services (e.g., Zygote, logd) ./system/bin/app_process: Launches the Zygote process, the parent of all Android app processes ./system/etc/preloaded-classes: Classes preloaded by Zygote to speed up app startup ./system/build.prop: Stores system properties (e.g.,ro.product.model,ro.build.version.sdk)./system/etc/security/sepolicy: SELinux policy rules defining process permissions.
Advanced Features
- A/B Partitions (Seamless Updates): Two identical partitions (
system_a,system_b) allow OTA updates without downtime. The device boots from one partition while the other is updated .- Virtual A/B (Android 11+): Uses snapshots to minimize storage overhead for updates.
- Compressed Snapshots (Android 12+): Reduces update size by compressing data changes.
- Dynamic Partitions (Android 10+): Allows system partitions (e.g.,
/system,/vendor) to resize dynamically, optimizing storage usage. - Project Treble: Separates Android OS components from hardware-specific code, enabling faster updates .
File System Types
- Ext4: Default filesystem for
/system,/data, and/cache. - F2FS: Optimized for flash storage, used on modern devices. Benchmarks show 300x faster random writes than Ext4 .
- VFAT: Used for
/sdcardto ensure cross-platform compatibility. - SquashFS: Read-only compressed filesystem for system images, reducing storage footprint.
Security Mechanisms
- Verified Boot: Ensures the bootloader, kernel, and system partitions are unmodified using cryptographic signatures .
- dm-verity: Verifies the integrity of system partitions using a hash tree, preventing rootkits .
- File-Based Encryption (FBE): Encrypts user data at the file level, introduced in Android 7.0.
Accessing System Files
- Root Access: Required to modify
/systemor/datapartitions. Use tools like Root Explorer or Solid Explorer . - ADB: Debug bridge for command-line access (e.g.,
adb shellto explore files). - Termux: A terminal emulator providing a Linux-like environment for advanced users.
System Boot Process
- Bootloader: Verifies the kernel signature and loads it into memory.
- Kernel Initialization: Sets up hardware drivers and starts the
initprocess. - Init Process: Parses
init.rcto launch system services (e.g., Zygote). - Zygote: Forks to create the first app process, starting the
System Server. - System Server: Initializes core services (e.g., Activity Manager, Package Manager).
Modular System Components
- HAL (Hardware Abstraction Layer): Separates hardware drivers from the OS, enabling vendor-specific optimizations.
- ART (Android Runtime): Compiles apps to native code for better performance, replacing Dalvik in Android 5.0.
Security Considerations
- System File Modifications: Altering
/systemfiles without expertise can brick the device. - Permissions: Avoid granting unnecessary permissions to apps (e.g.,
WRITE_EXTERNAL_STORAGE). - SELinux: Run in
enforcingmode by default to block unauthorized access .
1. Enhanced Root Directory Architecture
/system Extensions
-
/system/app_asar (Android 13+)
Android’s new App-Specific Adaptive Resources directory for dynamic app resource loading optimized for device capabilities (e.g., loading 8K textures only on supported GPUs). -
/system/apex (Android 10+)
APEX (Android Pony EXpress) containers for modular system components. Examples:-
com.android.media.swcodec.apex: Media codec updates -
com.android.tzdata.apex: Time zone data
Uses dm-verity for integrity checks and supports atomic updates.
-
-
/system/dynamic_partitions
Stores metadata for dynamic partition management, including partition group definitions (e.g.,group_basic: system vendor product) and size calculators.
/data Specializations
-
/data/misc_ce/<user_id>
Per-user encrypted credential storage using AES-256-XTS tied to hardware-backed keystores. -
/data/anr
StrictMode violation logs and ANR (Application Not Responding) traces with stack dumps tagged with process importance scores (ADJ levels). -
/data/system/package_cache
ART-generated AOT profiles for app optimization (e.g.,base.odex,base.vdex).
2. Advanced Partitioning Schemes
Dynamic Partitions (Android 10+)
-
Super Partition Layout
-
Logical partitions (LP) managed via
lpmake:bash
复制
下载
lpmake --device-size 4294967296 \ --partition system:readonly:2684354560:default \ --partition vendor:readonly:1610612736:default \ --output super.img -
Uses
dm-linearto map virtual partitions during boot.
-
-
Retrofit Dynamic Partitions
Backward-compatible implementation for legacy devices using OTA payloads withbrillo_update_payload.
Virtual A/B with Snapshots (Android 11+)
-
COW (Copy-on-Write) Snapshots
-
Userdata snapshots stored in
/metadata/otausinglibsnapshot. -
Differential updates via
xz -9compression and `bsdiff** binary patching.
-
-
Snapshot Merge States
-
snapshot-mergesystemd service handles background merging. -
Fallback mechanisms using
rollback-indicatorin bootctrl HAL.
-
3. Security Subsystems Deep Dive
Enhanced SELinux Policies
-
Neverallow Rules
Policy constraints preventing domains from accessing sensitive resources:sepolicy
neverallow { appdomain -bluetooth } self:capability net_admin; neverallow zygote tmpfs:file execute; -
Macro-Based Policies
Modular policy definitions in/system/sepolicy/public:sepolicy
define(`app_domain', ` typeattribute $1 appdomain; allow $1 self:process execmem; ')
Hardware-Backed Security
-
Trusty TEE Integration
-
Secure world OS running parallel to Linux.
-
Key attestation via
android.security.keystoreusing ECDSA P-256 keys.
-
-
StrongBox Keymaster (Android 9+)
Dedicated secure element meeting CC EAL5+ requirements. Verified via:java
KeyGenParameterSpec.Builder().setIsStrongBoxBacked(true);
4. Next-Gen File Systems & Optimization
F2FS Advanced Features
-
Atomic Write Support
Guarantees write atomicity for SQLite transactions usingF2FS_IOC_START_ATOMIC_WRITE. -
Compression (Android 13+)
LZ4 & LZO in-kernel compression with adaptive algorithms:bash
tune2fs -O compression /dev/block/by-name/userdata
EROFS (Enhanced Read-Only File System)
-
Linux 5.4+ Backport
-
Fixed-output compression (4K clusters, LZ4) for
/systemand/vendor. -
30% space savings vs. SquashFS in GKI (Generic Kernel Image) deployments.
-
5. Advanced Boot & Init Systems
Bootloader Enhancements
-
A/B Boot Control (ABBC)
Vendor-specific implementations usingboot_control HAL:cpp
struct boot_control_module { getNumberSlots() → int; markBootSuccessful() → int; }; -
Verified Boot 2.0
-
Chain of trust from PBL (Primary Bootloader) to Android OS using RSA-4096/SHA-256.
-
AVB (Android Verified Boot) footer structure:
struct AvbFooter { char magic[4]; // 'AVB0' uint64_t original_image_size; uint64_t vbmeta_offset; };
-
Init System Upgrades
-
First Stage Init (Android 12+)
-
Minimal init in
ramdiskmounting/systemviamount_all --early. -
SELinux policy loading via
/system/etc/selinux/plat_sepolicy.cil.
-
-
Action Triggers
Event-driven init.rc rules:rc
on property:sys.boot_completed=1 start services exec /system/bin/trim_cache
6. Performance & Optimization Engines
ART Runtime Innovations
-
Cloud Profile Guided Optimization
Downloading profile data from Google Play to precompile critical code paths:bash
adb shell cmd package compile -m speed-profile -f com.example.app
-
JVM TI Support (Android 11+)
Debugging interface for profiling tools:java
Environment.setJVMTIEnabled(true);
Thermal Management
-
HAL 2.0 Thermal Mitigation
Dynamic CPU/GPU throttling via/vendor/etc/thermal-engine.conf:xml
<Temperature threshold="50" throttle="50%"/> <Temperature threshold="60" throttle="30%"/>
7. Cutting-Edge Hardware Integration
UWB (Ultra-Wideband) Stack
-
FiRa Consortium Standards
-
Secure ranging using IEEE 802.15.4z HRP.
-
/vendor/uwb/calibration_data.binfor antenna calibration.
-
-
HIDL Interface
IUwbChip.getRangingParameters() → (int status, RangingParams params);
5G Modem Integration
-
RIL (Radio Interface Layer) Enhancements
-
NSA (Non-Standalone) mode configuration in
/vendor/rild/libsec-ril.so. -
Dynamic SIM provisioning via EuiccManager (GSMA SGP.22).
-
8. Developer Tools & APIs
Android Studio Enhancements
-
Dynamic System Updates (DSU)
Side-loading GSI (Generic System Image) without flashing:bash
adb shell pm create-user -f DSU adb sideload gsi.zip
-
Perfetto Deep Tracing
System-wide tracing with GPU counters & kernel ftrace:proto
data_source_config { name: "linux.ftrace" ftrace_config { ftrace_events: "sched/sched_switch" } }
Kotlin Multiplatform
-
NDK Integration
Kotlin/Native for writing performant HAL modules:kotlin
@ThreadLocal external fun sensorRead(): FloatArray
9. Enterprise & IoT Extensions
Android for Cars
-
Vehicle HAL (VHAL)
Property-based control system:cpp
VehicleProperty{ INFO_VIN = 0x11100100, HVAC_FAN_SPEED = 0x21400500, } -
Android Automotive OS
Dedicated/carpartition with vehicle network service (CAN bus access viaSocketCAN).
Zero-Touch Enrollment
-
DPM (Device Policy Manager) APIs
Automated enterprise provisioning using QR code scanning:java
Intent intent = new Intent(ACTION_PROVISION_MANAGED_PROFILE); intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, "com.example.dpc");
10. Future Directions (Android 14+)
-
Privacy Sandbox
FLoC (Federated Learning of Cohorts) replacement for third-party cookies. -
Gemini ML Framework
On-device model training with hardware acceleration via NPU.
This expanded architecture showcases Android's evolution into a highly modular, security-hardened OS supporting heterogeneous computing, while maintaining backward compatibility through rigorous HAL abstraction and Linux kernel upstreaming efforts.
posted on 2025-05-04 21:14 gamethinker 阅读(13) 评论(0) 收藏 举报 来源
浙公网安备 33010602011771号