自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
用例
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本文档包含 AVF 的常见用例。
隔离编译
作为软件安全隔区,受保护的虚拟机可提供安全环境来编译安全敏感代码。此环境可实现将 bootclasspath
和系统服务器 JAR(由 APEX 更新触发)的编译从前期启动移至重新启动之前,并显著缩短 APEX 更新后的启动时间。
该实现位于 com.android.compos
APEX 中。此组件是可选的,可以使用 makefile 将其包含在内。
图 1. 在 Mainline 更新上编译 JAR
安全目标是如实编译经过验证的输入并单独生成输出;将 Android 作为不受信任的客户端无法以任何其他方式更改编译输出,除非使编译过程失败(Android 回退到启动时编译)。
仅当整个编译期间没有错误时,虚拟机中的编译服务才会生成签名。Android 可以从虚拟机中检索公钥以进行签名验证。
虚拟机的密钥是通过虚拟机的 DICE 配置文件生成的,该配置文件由装载到虚拟机的 APEX 和 APK 以及其他虚拟机参数(例如可调试性)定义。
为了确定公钥并非来自未知虚拟机,Android 会启动虚拟机以确定密钥是否正确。每次 APEX 更新后,虚拟机都会在前期启动时启动。
借助受保护的虚拟机的“启动时验证”功能,编译服务仅运行经过验证的代码。因此,代码可以决定仅接受满足特定条件的输入,例如,仅接受许可名单中指定了其名称和 fs-verity
摘要的输入文件。
虚拟机中的任何公开 API 都是攻击面。系统会假定所有输入文件和参数都来自不受信任的客户端,且在处理之前必须经过验证和审查。
虚拟机会验证输入/输出文件的完整性,并将文件作为不受信任的文件服务器存储在 Android 上,如下所示:
- 在使用
fs-verity
算法之前,必须先验证输入文件的内容。为使输入文件可在虚拟机中使用,其根哈希必须在构成虚拟机 DICE 配置文件的容器 (APK) 中提供。有了受信任的根哈希,攻击者就无法在不会被检测到的情况下篡改输入文件。
- 必须在虚拟机中维护输出文件的完整性。即使输出文件存储在 Android 上,其生成期间的完整性也会使用相同的
fs-verity
树格式进行维护,但可以进行动态更新。最终输出文件可以使用根哈希进行标识,此文件将在虚拟机中被隔离。虚拟机中的服务通过签名来保护输出文件。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-03。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-03。"],[],[],null,["# Use cases\n\nThis page contains common use cases for AVF.\n\nIsolated compilation\n--------------------\n\nAs a software-secure enclave, a protected virtual machine (VM) provides\na safe environment to compile security-sensitive code.\nThis environment allows moving the compilation\nof `bootclasspath` and system server JARs (triggered by an APEX update) from\nearly boot to before reboot, and significantly reduces the post APEX\nupdate boot time.\n\nThe implementation is in the [`com.android.compos`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Virtualization/build/compos/Android.bp) APEX. This\ncomponent is optional and can be included using a [makefile](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Virtualization/build/apex/product_packages.mk).\n\n\n**Figure 1.** Compiling JARs on Mainline updates. Compiling JARs on Mainline updates\n\n\u003cbr /\u003e\n\nThe security goal is to truthfully compile verified input and produce the output\nin isolation; Android as an untrusted client can't alter the compilation\noutput in any way other than causing it to fail (when Android falls back to boot\ntime compilation).\n\nThe compilation service in the VM generates a signature only if there's no\nerror during the entire compilation. Android can retrieve the public key from\nthe VM for signature verification.\n\nThe VM's key is generated from the VM's DICE profile, defined by the APEXes\nand APKs mounted to the VM, in addition to other VM parameters, such as\ndebuggability.\n\nTo determine if the public key isn't from an unexpected VM, Android boots\nthe VM to determine if the key is correct. The VM is booted at early boot\nafter each APEX update.\n\nWith Protected VM's Verified Boot, the compilation service runs only verified\ncode. As a result the code can therefore determine to accept only inputs that\nsatisfy certain conditions, for example, accept an input file only where its\nname and the `fs-verity` digest are defined in an allowlist.\n\nAny exposed APIs from the VM are attack surfaces. All input files and\nparameters are assumed to be from an untrusted client, and must be verified and\nvetted before processing.\n\nInput and output file integrity is verified by the VM, with the files stored on\nAndroid as an untrusted file server, as follows:\n\n- The content of an input file must be verified before use using the `fs-verity` algorithm. For an input file to become available in the VM, its root hash must be provided in a container (APK) that contributes to the VM's DICE profile. With the trusted root hash, an attacker can't tamper with the input without being detected.\n- The integrity of the output file must be maintained in the VM. Even if an output file is stored on Android, during the generation, the integrity is maintained with the same `fs-verity` tree format but can be dynamically updated. The final output file can be identified with the root hash, which is isolated in the VM. The service in the VM protects the output files by signature.\n\nLinux development environment\n-----------------------------\n\nAndroid has traditionally been the only major operating system\nthat doesn't let users develop apps on the platform itself.\nWith the introduction of the Linux development environment,\nwe aim to provide a Linux-based development environment to Android\nusers who are developers. In the future, we plan to expand the effort\nto make it possible for our partners to implement innovative VM\nuse cases like running graphical user interface apps and even games.\n\nThe Linux development environment is available on select devices and runs\nin a non protected virtual machine.\n\n\n**Figure 2.** Linux development environment use case.\n\n\u003cbr /\u003e\n\nThe high-level flow is as follows:\n\n1. To use the Linux development environment, [enable developer options](https://developer.android.com/about/versions/15/release-notes#linux-development-environment).\n2. After you enable developer options, the Terminal app appears on your home launcher.\n3. Launch the Terminal app from your home launcher.\n4. If required, the Terminal app downloads the OS image from Play.\n5. The Terminal app uses the Android Virtualization Framework (AVF) to create a virtual machine (VM).\n6. AVF then runs the VM with the OS image.\n7. The virtual machine boots the OS from the image.\n8. After the VM boots, the WebView in the Terminal app connects to a web service in the virtual machine. This service provides terminal access over HTTP.\n9. You interact with the terminal by entering commands and viewing the output in the app.\n\nThe high-level components of the Linux VM are as follows:\n\n- **Terminal app:** An Android application providing a terminal interface. It uses a WebView to connect to a web service running in the VM for interaction. This app is disabled by default. Activate it in Developer Settings.\n- **Android Virtualization Framework (AVF):** Android's existing subsystem for VM creation and management. It requires minimal modification to support custom OS images for this feature.\n- **virtual machine:** A VM that AVF generates. It hosts the terminal service, and AVF creates it specifically for the Terminal app's functionality.\n- **OS image:** A slightly modified Debian-based OS image from upstream Debian. The Terminal app downloads this image from an external Google server. It serves as the foundation for the VM's operation.\n- **Guest Agent:** New software in the VM. It reports the OS's state to AVF and provides control of the virtual machine.\n- **ttyd**: Open-source software running in the VM that implements terminal emulation over HTTP. The Terminal app's WebView connects to it.\n- **Tethering Manager:** An existing Android subsystem. It provides network access to the virtual machine by tethering the VM to the Android-powered device.\n\nContent Safety On-Device\n------------------------\n\nContent Safety On-device is a privacy-preserving content safety solution created\nby the Content Safety On-device Team. It performs content safety classification\nfor various Google products on 1P/3P devices, and protects 1B+ users from\nabusive content, without requiring user data being sent back to Google servers.\nIt is designed to adhere to [Private Compute Core (PCC)](https://security.googleblog.com/2022/12/trust-in-transparency-private-compute.html)\nprinciples to verify transparent and privacy-preserving communication between\nthe client, the virtual machine (VM), and preventing any exfiltration of user\ndata. It can be used for things such as enabling abuse detection on devices,\nsuch as [Play Protect live threat detection](https://developers.google.com/android/play-protect).\n\nIn this use case, the system utilizes protected virtual machines to run its\nmodel classification for Play Protect live threat detection which then\nsignificantly enhances the security of its models and protections. This prevents\nreverse engineering and manipulation by attackers, even on rooted devices, by\nverifying only approved code runs and its operations are hidden from external\nprocesses.\n| **Note:** This specific use case is enabled on select devices supporting Play Protect live threat detection and AVF. Play Protect live threat detection will utilize AVF when available.\n\nThe high level flows are as follows:\n\n1. Live threat detection pings Private Compute Services to start the VM. Private Compute Services is a privacy-centric intermediary between the PCC and the cloud server\n2. Private Compute Services starts the VM and gets its public key from the VM\n3. Private Compute Services hands over VM ownership to Play Protect live threat detection\n4. Private Compute Services sends attestation and public key to the server\n5. Server verifies attestation and encrypt protections with VM public key\n6. Server then sends the encrypted protections back to the device\n7. Then, the on-device live threat detection can utilize encrypted protection within the VM. The VM is the only entity with the private key which can decrypt the protections\n\nThe high level component are as follows:\n\n- Server: Encrypt and deliver encrypted protections to the VM\n- Private Compute Services: Used to start the VM and mediate the communication to the VM and show transparency that no user data is going through Astrea to server\n- Play Protect live threat detection:\n - Contains and uses model classifiers provided by Content Safety on-device\n - Accepts ownership of the VM and holds it for classification use\n - Starts and stops the VM as needed.\n\nOEMs\n----\n\nAn OEM can use the AVF for custom use cases.\nFor example, OPPO uses AVF to enable its\n[AI private computing space](https://mp.weixin.qq.com/s/c2x1AdbAJJ0LNQt7PmHahA). This space's first application\nprovides an on-device risk control solution for app clients, running in a\nvirtual machine. The system counters threats from illicit activities,\noffering protection against various hazards."]]