一句话:首次纵向实证刻画 Rust 在 AOSP 的采用轨迹、集成机制与 unsafe 治理,并评估其内存安全成效。
AOSP 支撑着全球最大的移动生态,但其原生组件长期受 C/C++ 手工内存管理导致的内存安全漏洞困扰。自 2021 年起 AOSP 引入具备编译期内存安全保障的 Rust。本文首次对该迁移进行纵向、系统的实证研究:分析 2021 年 1 月至 2024 年 10 月的 16 个季度快照,追踪采用趋势并刻画 Rust 代码在 67 个组件上的分布;将 Android 安全公告(ASB)漏洞与这些组件对齐,比较引入 Rust 前后的内存安全表现,并识别仍待迁移的非 Rust 热点;进而总结平台级集成机制,并通过大量 SAFETY 注释考察 unsafe 代码的治理实践,提炼可操作的最佳实践与反模式。结果厘清了 Rust 在这一安全攸关的移动平台中的采用、集成与治理角色,也为大规模生产系统中的内存安全迁移提供了实证基础与实践指导。
The Android Open Source Project (AOSP) powers the world's largest mobile ecosystem, yet memory-safety vulnerabilities remain prevalent in native components due to the inherent risks of languages like C and C++, which allow manual memory management and unsafe operations. To mitigate these risks, AOSP began adopting Rust, a language with compile-time memory-safety guarantees, in 2021. However, the trajectory, mechanisms, and effectiveness of this transition remain empirically uncharted. We present the first longitudinal and systematic empirical study of Rust in AOSP. By analyzing 16 quarterly snapshots from January 2021 to October 2024, we track adoption trends and map the distribution of Rust code across 67 components. We further align Android Security Bulletin vulnerabilities with these components to assess memory-safety outcomes before and after Rust adoption, while also identifying the remaining non-Rust hotspots that may warrant future migration. In addition, we characterize platform-level integration mechanisms and examine unsafe governance through a large corpus of SAFETY comments, from which we distill actionable best practices and anti-patterns. Taken together, these results clarify Rust's role in AOSP by shedding light on its adoption, integration, and governance in a safety-critical mobile platform. They also provide industry practitioners with an empirical foundation and practical guidance for similar memory-safe migrations in large-scale production systems.