1 /*
2  * Copyright (C) 2018 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 <system/audio.h>
20 
21 #include <string>
22 #include <vector>
23 #include <utils/Errors.h>
24 
25 struct _xmlNode;
26 struct _xmlDoc;
27 
28 namespace android {
29 namespace engineConfig {
30 
31 /** Default path of audio policy usages configuration file. */
32 constexpr char DEFAULT_PATH[] = "/vendor/etc/audio_policy_engine_configuration.xml";
33 
34 using AttributesVector = std::vector<audio_attributes_t>;
35 using StreamVector = std::vector<audio_stream_type_t>;
36 
37 struct AttributesGroup {
38     std::string name;
39     audio_stream_type_t stream;
40     std::string volumeGroup;
41     AttributesVector attributesVect;
42 };
43 
44 using AttributesGroups = std::vector<AttributesGroup>;
45 
46 struct CurvePoint {
47     int index;
48     int attenuationInMb;
49 };
50 using CurvePoints = std::vector<CurvePoint>;
51 
52 struct VolumeCurve {
53     std::string deviceCategory;
54     CurvePoints curvePoints;
55 };
56 using VolumeCurves = std::vector<VolumeCurve>;
57 
58 struct VolumeGroup {
59     std::string name;
60     int indexMin;
61     int indexMax;
62     VolumeCurves volumeCurves;
63 };
64 using VolumeGroups = std::vector<VolumeGroup>;
65 
66 struct ProductStrategy {
67     std::string name;
68     AttributesGroups attributesGroups;
69 };
70 
71 using ProductStrategies = std::vector<ProductStrategy>;
72 
73 using ValuePair = std::pair<uint32_t, std::string>;
74 using ValuePairs = std::vector<ValuePair>;
75 
76 struct CriterionType
77 {
78     std::string name;
79     bool isInclusive;
80     ValuePairs valuePairs;
81 };
82 
83 using CriterionTypes = std::vector<CriterionType>;
84 
85 struct Criterion
86 {
87     std::string name;
88     std::string typeName;
89     std::string defaultLiteralValue;
90 };
91 
92 using Criteria = std::vector<Criterion>;
93 
94 struct Config {
95     float version;
96     ProductStrategies productStrategies;
97     Criteria criteria;
98     CriterionTypes criterionTypes;
99     VolumeGroups volumeGroups;
100 };
101 
102 /** Result of `parse(const char*)` */
103 struct ParsingResult {
104     /** Parsed config, nullptr if the xml lib could not load the file */
105     std::unique_ptr<Config> parsedConfig;
106     size_t nbSkippedElement; //< Number of skipped invalid product strategies
107 };
108 
109 /** Parses the provided audio policy usage configuration.
110  * @return audio policy usage @see Config
111  */
112 ParsingResult parse(const char* path = DEFAULT_PATH);
113 android::status_t parseLegacyVolumes(VolumeGroups &volumeGroups);
114 
115 } // namespace engineConfig
116 } // namespace android
117