自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
自定义设备开发
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面将介绍您在为自己的设备设置 build 时可能需要执行的几项任务。
创建自定义刷写配置
fastboot 指令在名为 fastboot-info.txt
的制品中定义。如果您构建多个目标,则 $OUT_DIR 中将包含多个 fastboot-info.txt
文件。并且,$ANDROID_PRODUCT_OUT
会指向您构建的最新目标。本页列出了由 fastboot 执行的任务,并且可使用 m fastboot_info
重新生成。您可以通过修改 fastboot-info.txt
文件来引入自定义刷写逻辑。
fastboot-info.txt
文件支持以下命令:
flash %s
:刷写给定的分区。可选参数包括 --slot-other,
filename_path, and
--apply-vbmeta`。
update-super
:更新 super 分区。
if-wipe
:如果指定了 wipe,则有条件地运行一些其他组件。
erase %s
:清除给定的分区(只能与 if-wipe
结合使用 -> 例如 if-wipe erase cache
)。
确定刷写锁定状态
如果您要为设备构建自定义 flashboot 守护程序 (flashbootd),则需要能够获取引导加载程序和引导加载程序锁定状态。getFlashLockState()
@SystemApi
会传输引导加载程序状态,PersistentDataBlockManager.getFlashLockState()
系统 API 会返回兼容设备上引导加载程序的锁定状态。
返回值 |
条件 |
FLASH_LOCK_UNKNOWN |
仅升级到 Android 7.x 或更高版本且符合以下条件的设备会返回此值:设备支持刷写锁定/解锁功能,但之前不支持获取刷写锁定状态所需的引导加载程序变更。
- 运行 Android 7.x 或更高版本的新设备必须处于
FLASH_LOCK_LOCKED 或 FLASH_LOCK_UNLOCKED 状态。
- 升级到 Android 7.x 或更高版本且不支持刷写解锁/锁定功能的设备应返回
FLASH_LOCK_LOCKED 状态。
|
FLASH_LOCK_LOCKED |
不支持刷写锁定/解锁的所有设备(即设备始终处于锁定状态)或支持刷写锁定/解锁且处于锁定状态的所有设备会返回此值。 |
FLASH_LOCK_UNLOCKED |
支持刷写锁定/解锁且处于解锁状态的所有设备会返回此值。 |
制造商应测试由已锁定/解锁引导加载程序的设备返回的值。例如,AOSP 包含一个参考实现,该实现会返回基于 ro.boot.flash.locked
引导属性的值。示例代码位于以下目录中:
frameworks/base/services/core/java/com/android/server/PersistentDataBlockService.java
frameworks/base/core/java/android/service/persistentdata/PersistentDataBlockManager.java
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-04。
[null,null,["最后更新时间 (UTC):2025-04-04。"],[],[],null,["# Custom device development\n\nThis page explains several tasks you might need to perform if you're\nsetting up a build for your own device.\n\nCreate a custom flash configuration\n-----------------------------------\n\nFastboot instructions are defined in an artifact called `fastboot-info.txt`. If\nyou build multiple targets, you'll have multiple `fastboot-info.txt` files in\nthe \u003cvar translate=\"no\"\u003e$OUT_DIR\u003c/var\u003e. And, `$ANDROID_PRODUCT_OUT` points to the\nmost current target you built. This page list the tasks for fastboot to execute\nand can be regenerated using `m fastboot_info`. You can introduce custom\nflashing logic by modifying the `fastboot-info.txt` file.\n\nThe `fastboot-info.txt` file supports these commands:\n\n- `flash %s`: Flashes a given partition. Optional arguments include `--slot-other,`\u003cvar translate=\"no\"\u003efilename_path\u003c/var\u003e`, and`--apply-vbmeta\\`.\n- `update-super`: Updates the super partition.\n- `if-wipe`: Conditionally runs some other component if a wipe is specified.\n- `erase %s`: Erases a given partition (can only be used in conjunction with `if-wipe` -\\\u003e eg. `if-wipe erase cache`).\n\nDetermine flash lock state\n--------------------------\n\nIf you're building a custom flashboot daemon (flashbootd) for a device, you need\nto be able to obtain bootloader and bootloader lock state. The\n`getFlashLockState()` `@SystemApi` transmits the bootloader\nstate and the `PersistentDataBlockManager.getFlashLockState()` system\nAPI returns the bootloader's lock status on compliant devices.\n\n| Return value | Conditions |\n|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `FLASH_LOCK_UNKNOWN` | Returned only by devices upgrading to Android 7.x or higher that didn't previously support the bootloader changes required to get the flash lock status if they supported flashing lock/unlock capability. - New devices running Android 7.x or higher must be in either a `FLASH_LOCK_LOCKED` or `FLASH_LOCK_UNLOCKED` state. - Devices upgrading to Android 7.x or higher that don't support flashing unlock/lock capability should return a `FLASH_LOCK_LOCKED` state. |\n| `FLASH_LOCK_LOCKED` | Returned by any device that doesn't support flashing lock/unlock (that is, the device is always locked), or any device that supports flashing lock/unlock and is in the locked state. |\n| `FLASH_LOCK_UNLOCKED` | Returned by any device that supports flashing lock/unlock and is in the unlocked state. |\n\nManufacturers should test the values returned by devices with locked and\nunlocked bootloaders. For example, AOSP\ncontains a reference implementation that returns a value based on the\n`ro.boot.flash.locked` boot property. Example code is located in the\nfollowing directories:\n\n- `frameworks/base/services/core/java/com/android/server/PersistentDataBlockService.java`\n- `frameworks/base/core/java/android/service/persistentdata/PersistentDataBlockManager.java`"]]