CAP 的實作方式是以 Intel 參數架構為基礎。CAP 是在 Android 6 中推出。參數架構 (PfW) 可讓您以參數來描述系統。透過使用設定 XML 檔案,PfW 會將參數繫結至使用外掛程式的動作,並提供依據目前條件變更參數的規則。
HIDL 中的 CAP 結構
在 HIDL 中,CAP 的所有設定都已在 XML 中指定。詳情請參閱「參數架構」和「使用參數架構進行設定」。使用 XML 檔案指定下列項目:
參數結構的說明 (也就是 PfW 的音訊領域說明)
定義條件
轉送策略規則 (輸入和輸出裝置選取)
磁碟區資料表規格
有了 HIDL,Android 架構就能直接從供應商分區載入這些 XML 檔案。這是因為我們已為這些 XML 檔案定義 XSD 結構定義,做為 HAL API 的一部分。每個 HIDL HAL 的主要版本都有對應的 XSD 結構定義。主要版本不需要回溯相容性。
AIDL 中的 CAP 結構
隨著轉換至 AIDL,HAL API 版本必須維持回溯相容性 (以 HIDL 而言,每個 AIDL HAL 版本都是「次要」更新)。由於沒有可用來定義結構定義回溯相容性更新的確立方法,因此 XSD 結構定義無法再用於 HAL API。因此,先前在 XML 檔案中定義的設定,現在必須由 HAL 使用 AIDL API 提供。為方便這項作業,CAP 設定結構會轉換為 AIDL,類似於 Android 15 的 AIDL Audio HAL 中的 Audio Policy Configuration XML。
[[["容易理解","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"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Configurable Audio Policy support in AIDL HAL\n\nStarting with Android 16, the [AIDL Audio\nHAL](/docs/core/audio/aidl-implement) interface fully supports Configurable\nAudio Policy (CAP).\n\nThis page provides necessary technical background to assist partners and SoC\nvendors in the migration of their audio policy configurations.\n\nThe Parameter Framework\n-----------------------\n\nThe implementation of the CAP is based on the [Intel Parameter\nFramework](https://github.com/intel/parameter-framework). The CAP was introduced\nin Android 6. The Parameter Framework (PfW) allows to describe a system in terms\nof *parameters*. By using a configuration XML file, the PfW binds the parameters\nto actions using plugins, and provides rules for changing the parameters\naccording to the current criteria.\n| **Note:** For audio policy, *parameters* may be current input or output devices, and *criteria* are the current operating conditions, such as the phone communication mode, and available physical input or output devices.\n\nStructure of CAP in HIDL\n------------------------\n\nIn HIDL, all the configuration for the CAP was specified in XML. See [Parameter\nFramework](#pfw), and [Configuration using Parameter Framework](/docs/core/audio/implement-policy#policy_config) for more information.\nXML files were used to specify the following:\n\n- Description of the structure of the parameters (that is, the description of the audio domain for the PfW)\n- Definitions for criteria\n- Rules for routing strategies (input and output device selection)\n- Volume tables specification\n\nWith HIDL, the Android framework was able to load these XML files directly from\nthe vendor partition. This was allowed because an XSD schema was defined, as\npart of the HAL API, for these XML files. Each major release of the HIDL HAL had\na corresponding XSD schema. Major releases didn't require backwards\ncompatibility.\n\nStructure of CAP in AIDL\n------------------------\n\nWith the transition to AIDL, HAL API releases must remain backward-compatible\n(in HIDL terms, each release of the AIDL HAL is a \"minor\" update). XSD schemas\ncan't be used anymore as part of HAL APIs as there is no established way of\ndefining backward-compatible updates to the schemas. Hence, the configuration\nthat was previously defined in XML files now needs to be provided by the HAL\nusing AIDL APIs. To facilitate this, the structure of the CAP configuration is\nconverted to AIDL, similar to Audio Policy Configuration XMLs in [AIDL Audio\nHAL](/docs/core/audio/aidl-implement) for Android 15.\n| **Note:** XML files that define the audio domain for the PfW aren't converted to AIDL as they don't change between devices or products. These XML files have been moved to the system partition from which they can be loaded directly by the PfW engine.\n\nData structures for the CAP are added to [Common stable data\ntypes](/docs/core/audio/aidl-implement#common-data-types-aidl-hal) and\ninclude the following parcelables:\n\n- [`AudioHalCapConfiguration.aidl`](https://cs.android.com/android/platform/superproject/+/android-latest-release:system/hardware/interfaces/media/aidl/android/media/audio/common/AudioHalCapConfiguration.aidl)\n- [`AudioHalCapCriterionV2.aidl`](https://cs.android.com/android/platform/superproject/+/android-latest-release:system/hardware/interfaces/media/aidl/android/media/audio/common/AudioHalCapCriterionV2.aidl)\n- [`AudioHalCapDomain.aidl`](https://cs.android.com/android/platform/superproject/+/android-latest-release:system/hardware/interfaces/media/aidl/android/media/audio/common/AudioHalCapDomain.aidl)\n- [`AudioHalCapParameter.aidl`](https://cs.android.com/android/platform/superproject/+/android-latest-release:system/hardware/interfaces/media/aidl/android/media/audio/common/AudioHalCapParameter.aidl)\n- [`AudioHalCapRule.aidl`](https://cs.android.com/android/platform/superproject/+/android-latest-release:system/hardware/interfaces/media/aidl/android/media/audio/common/AudioHalCapRule.aidl)\n\nThe entry point for the CAP configuration is in the\n[`AudioHalEngineConfig.CapSpecificConfig`](https://cs.android.com/android/platform/superproject/+/android-latest-release:system/hardware/interfaces/media/aidl/android/media/audio/common/AudioHalEngineConfig.aidl)\nstructure. See the comments in\n[`AudioHalCapConfiguration.aidl`](https://cs.android.com/android/platform/superproject/+/android-latest-release:system/hardware/interfaces/media/aidl/android/media/audio/common/AudioHalCapConfiguration.aidl)\nfor a diagram of CAP data structures.\n\nThe [default\nimplementation](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/audio/aidl/default/)\nof the AIDL HAL contains [a helper\nclass](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/audio/aidl/default/include/core-impl/CapEngineConfigXmlConverter.h)\nthat fills out the AIDL parcelables based on the contents of legacy CAP XML\nfiles to simplify migration for partners.\n| **Note:** Technically there is no need for partners to store CAP configuration in XML files anymore. The framework only requires that the configuration is provided using AIDL, whereas the source for the data that ends up in AIDL is irrelevant.\n\nMigration scenarios\n-------------------\n\nPartners may consider options as listed in this section, based on whether it's\nthe first launch of a product that wasn't using CAP before, or migration of an\nexisting product.\n\n### New product\n\nFor a new product which starts using CAP for audio policy implementation, the\nOEM can choose to use XML for storing CAP configuration on the vendor side.\n\nThe benefit of using XML is that there exist a set of [scripting\ntools](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/av/services/audiopolicy/engineconfigurable/tools/)\nthat facilitate generation of the configuration from a high level description.\n\nIf the OEM decides to use XML for storing CAP configuration on the vendor\npartition, then it is recommended to use the default implementation of the XML\nparser for converting the configuration into AIDL.\n\n### Update for existing product\n\nIf the product already uses CAP and thus has the XML configuration, you can\ncontinue using the existing CAP with the AIDL version of the HAL.\n\nThe naming convention for product strategies differs in the HIDL and AIDL\nversions of the CAP configuration. In HIDL the built-in (\"legacy\") strategies\nused lower case short names like `media` whereas in AIDL, built-in strategies\nuse all-caps names prefixed with `STRATEGY_`, for example `STRATEGY_MEDIA`. See\nthe list of built-in strategies in\n[`CapProductStrategies.xml`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/av/services/audiopolicy/engineconfigurable/data/etc/Structure/CapProductStrategies.xml).\nThe same file defines \"pre-allocated\" IDs for OEM-specific strategies which\nfollow the naming pattern of `vx_10xx` with numbers from `1000` to `1039`.\n\n### Legacy product\n\nIf the product which relies on CAP doesn't update its vendor partition and\nremains on HIDL, you can update the system partition to Android\n16. The framework remains compatible with the legacy\nCAP configuration.\n\nExample implementation\n----------------------\n\nTo help partners implement CAP for their platforms, the AOSP has an example of\n\"automotive\" flavor of the Cuttlefish virtual device which uses CAP with AIDL\nHAL. The device-specific configuration is located in\n[device/google/cuttlefish/shared/auto/audio/policy/engine](https://cs.android.com/android/platform/superproject/+/android-latest-release:device/google/cuttlefish/shared/auto/audio/policy/engine/),\nwith the `lunch` target name of `aosp_cf_x86_64_auto`. The `Android.bp` file can\nbe used as a reference for generating the full set of CAP vendor files."]]