自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
实现已签名配置
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
签名配置功能允许在 APK 中嵌入有关非 SDK 接口受限情况的配置,进而可以从屏蔽名单中移除特定非 SDK 接口,以便 AndroidX 安全地使用它们。这让 AndroidX 团队可以在已发布的 Android 版本上添加对新功能的支持。Android 10 及更高版本支持该功能。
适当地支持签名配置可以确保 AndroidX 库在将来推出的设备上正常运行。
该功能无法自定义,在 AOSP 中完全受支持,且无需原始设备制造商 (OEM) 采取任何行动。
示例和来源
功能实现位于系统服务器的以下位置:frameworks/base/services/core/java/com/android/server/signedconfig
。CTS 测试 CtsSignedConfigHostTestCases
包含使用示例,并在 cts/hostsidetests/signedconfig/app/version1_AndroidManifest.xml
中提供了一个配置示例。
实现
支持该功能不需要采取任何行动,也没有具体的硬件要求。
该功能使用两个应用元数据键在 APK 内部嵌入配置和签名。这两个键分别是 android.settings.global
和 android.settings.global.signature
。如果未来 AndroidX 库要求从屏蔽名单中移除非 SDK 接口,则这两个键的值将由 Android 团队发布和/或作为 AndroidX 的一部分来发布。
APK 元数据键 android.settings.global
和 android.settings.global.signature
均包含 base-64 编码数据。键 android.settings.global
的值是以 JSON 编码的配置值,会应用到 SettingsProvider
中的全局设置。键 android.settings.global.signature
的值是 JSON 数据的 ECDSA-p256 签名。该签名用于验证配置数据的来源。
该功能对用户不可见。
自定义
该功能不支持自定义。不建议原始设备制造商 (OEM) 修改该功能,包括替换键。对该功能的任何更改都可能导致 AndroidX 未来在受影响的设备上无法正常运行。
验证
CTS 测试 CtsSignedConfigHostTestCases
可以验证功能实现情况。
此外,您还可以通过安装适当的 APK 和检查 adb logcat
输出来手动测试该功能:
$ adb install CtsSignedConfigTestAppV1.apk
...
$ adb logcat
...
I SignedConfig: Verified config using production key
...
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","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-26。"],[],[],null,["# Implement Signed Config\n\nThe Signed Config feature allows embedding configuration of non-SDK interface restrictions\nin APKs. This allows removing specific non-SDK interfaces from the blacklist, to\nallow AndroidX to safely use them. This allows the AndroidX team to add support\nfor new features on Android versions that have already been released. It is\nsupported in Android 10 and later.\n\nProperly supporting Signed Config ensures that the AndroidX libraries will\nfunction correctly on devices in the future.\n\nNo customization of this feature is possible. It is fully supported in AOSP and\nrequires no OEM effort to support it.\n\nExamples and source\n-------------------\n\nThe feature implementation is in the system server at\n`frameworks/base/services/core/java/com/android/server/signedconfig`. The CTS\ntest `CtsSignedConfigHostTestCases` includes example usage, and an example\nconfiguration in\n`cts/hostsidetests/signedconfig/app/version1_AndroidManifest.xml`.\n\nImplementation\n--------------\n\nNo effort is required to support the feature, and there are no specific hardware\nrequirements.\n\nThe feature uses two application metadata keys to embed configuration and a\nsignature inside APKs. Those keys are `android.settings.global` and\n`android.settings.global.signature`. If or when the AndroidX libraries require\nnon-SDK interfaces to be removed from the blacklist in the future, values for\nthese keys will be published by the Android team and/or as part of AndroidX.\n\nThe APK metadata keys `android.settings.global` and\n`android.settings.global.signature` both contain base-64 encoded data. The value\nfor key `android.settings.global` is JSON-encoded config values to be applied to\nthe global settings in `SettingsProvider`. The value for\n`android.settings.global.signature` is an ECDSA-p256 signature of the JSON data.\nThe signature is used to verify the origin of the configuration data.\n\nThe feature isn't user visible.\n\nCustomization\n-------------\n\nThe feature isn't intended for customization. OEMs are discouraged from\nmodifying the feature, including replacing the keys. Any changes to it are\nlikely to cause AndroidX to not function properly on affected devices in the\nfuture.\n\nValidation\n----------\n\nThe CTS test `CtsSignedConfigHostTestCases` verifies the feature implementation.\n\nYou can also test the feature manually by installing an appropriate APK and\ninspecting the `adb logcat` output: \n\n $ adb install CtsSignedConfigTestAppV1.apk\n ...\n $ adb logcat\n ...\n I SignedConfig: Verified config using production key\n ..."]]