1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <EngineConfig.h> 20 21 #include <android/media/audio/common/AudioHalEngineConfig.h> 22 #include <system/audio_policy.h> 23 #include <string> 24 #include <vector> 25 26 namespace android { 27 namespace capEngineConfig { 28 29 static const char *const gCriterionTypeSuffix = "Type"; 30 static const char *const gInputDeviceCriterionName = "AvailableInputDevices"; 31 static const char *const gOutputDeviceCriterionName = "AvailableOutputDevices"; 32 static const char *const gPhoneStateCriterionName = "TelephonyMode"; 33 static const char *const gOutputDeviceAddressCriterionName = "AvailableOutputDevicesAddresses"; 34 static const char *const gInputDeviceAddressCriterionName = "AvailableInputDevicesAddresses"; 35 36 /** 37 * Order MUST be aligned with definition of audio_policy_force_use_t within audio_policy.h 38 */ 39 static const char *const gForceUseCriterionTag[AUDIO_POLICY_FORCE_USE_CNT] = 40 { 41 [AUDIO_POLICY_FORCE_FOR_COMMUNICATION] = "ForceUseForCommunication", 42 [AUDIO_POLICY_FORCE_FOR_MEDIA] = "ForceUseForMedia", 43 [AUDIO_POLICY_FORCE_FOR_RECORD] = "ForceUseForRecord", 44 [AUDIO_POLICY_FORCE_FOR_DOCK] = "ForceUseForDock", 45 [AUDIO_POLICY_FORCE_FOR_SYSTEM] = "ForceUseForSystem", 46 [AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO] = "ForceUseForHdmiSystemAudio", 47 [AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND] = "ForceUseForEncodedSurround", 48 [AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING] = "ForceUseForVibrateRinging" 49 }; 50 51 using ParameterValues = std::vector<std::string>; 52 53 struct ConfigurableElement { 54 std::string path; 55 }; 56 57 struct ConfigurableElementValue { 58 ConfigurableElement configurableElement; 59 std::string value; 60 }; 61 using ConfigurableElementValues = std::vector<ConfigurableElementValue>; 62 63 struct CapSetting { 64 std::string configurationName; 65 ConfigurableElementValues configurableElementValues; 66 }; 67 using CapSettings = std::vector<CapSetting>; 68 69 struct CapConfiguration { 70 std::string name; 71 std::string rule; 72 }; 73 74 using ConfigurableElementPaths = std::vector<std::string>; 75 using CapConfigurations = std::vector<CapConfiguration>; 76 77 struct CapConfigurableDomain { 78 std::string name; 79 CapConfigurations configurations; 80 CapSettings settings; 81 }; 82 83 struct CapCriterion { 84 engineConfig::Criterion criterion; 85 engineConfig::CriterionType criterionType; 86 }; 87 88 using CapCriteria = std::vector<CapCriterion>; 89 using CapConfigurableDomains = std::vector<CapConfigurableDomain>; 90 91 struct CapConfig { 92 CapCriteria capCriteria; 93 CapConfigurableDomains capConfigurableDomains; 94 }; 95 96 /** Result of `parse(const char*)` */ 97 struct ParsingResult { 98 /** Parsed config, nullptr if the xml lib could not load the file */ 99 std::unique_ptr<CapConfig> parsedConfig; 100 size_t nbSkippedElement; //< Number of skipped invalid product strategies 101 }; 102 103 /** Convert the provided Cap Settings configuration. 104 * @return audio policy usage @see Config 105 */ 106 ParsingResult convert(const ::android::media::audio::common::AudioHalEngineConfig& aidlConfig); 107 108 } 109 } 110