• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package android.media.audio.common;
18 
19 import android.media.audio.common.AudioHalCapCriterionV2;
20 
21 /**
22  * AudioHalCapRule defines the Configurable Audio Policy (CAP) rules for a given configuration.
23  *
24  * Rule may be compounded using a logical operator "ALL" (aka "AND") and "ANY' (aka "OR").
25  * Compounded rule can be nested.
26  * Rules on criterion is made of:
27  *      -type of criterion:
28  *              -inclusive -> match rules are "Includes" or "Excludes"
29  *              -exclusive -> match rules are "Is" or "IsNot" aka equal or different
30  *      -Name of the criterion must match the provided name in AudioHalCapCriterionV2
31  *      -Value of the criterion must match the provided list of literal values from
32  *         associated AudioHalCapCriterionV2 values
33  * Example of rule:
34  *      ALL
35  *          ANY
36  *              ALL
37  *                  CriterionRule1
38  *                  CriterionRule2
39  *              CriterionRule3
40  *          CriterionRule4
41  *
42  * It will correspond to
43  *      ALL
44  *          nestedRule1
45  *          CriterionRule4
46  *
47  * where nestedRule1 is
48  *            ANY
49  *              nestedRule2
50  *              CriterionRule3
51  * and nestedRule2 is
52  *              ALL
53  *                  CriterionRule1
54  *                  CriterionRule2
55  *
56  * Translated into:
57  *     { .compoundRule = CompoundRule::ALL, .nestedRule[0] =
58  *         { .compoundRule = CompoundRule::ANY, .nestedRule[0] =
59  *             { .compoundRule = CompoundRule::ALL, .criterionRules =
60  *                  { CriterionRule1, CriterionRule2 }},
61  *           .criterionRules = { CriterionRule3 },
62  *         },
63  *       .criterionRules = { CriterionRule4 }}
64  *
65  * {@hide}
66  */
67 @JavaDerive(equals=true, toString=true)
68 @VintfStability
69 parcelable AudioHalCapRule {
70     @VintfStability
71     enum CompoundRule {
72         INVALID = 0,
73         /*
74          * OR'ed rules
75          */
76         ANY,
77         /*
78          * AND'ed rules
79          */
80         ALL,
81     }
82 
83     @VintfStability
84     enum MatchingRule {
85         INVALID = -1,
86         /*
87          * Matching rule on exclusive criterion type.
88          */
89         IS = 0,
90         /*
91          * Exclusion rule on exclusive criterion type.
92          */
93         IS_NOT,
94         /*
95          * Matching rule on inclusive criterion type (aka bitfield type).
96          */
97         INCLUDES,
98         /*
99          * Exclusion rule on inclusive criterion type (aka bitfield type).
100          */
101         EXCLUDES,
102     }
103 
104     @VintfStability
105     parcelable CriterionRule {
106         MatchingRule matchingRule = MatchingRule.INVALID;
107         /*
108          * Must be one of the names defined by {@see AudioHalCapCriterionV2}.
109          * By convention, when AudioHalCapCriterionV2 is used as a rule, the rule uses
110          * the first element of the 'values' field which must be a non-empty array.
111          */
112         AudioHalCapCriterionV2 criterionAndValue;
113     }
114     /*
115      * Defines the AND or OR'ed logcal rule between provided criterion rules if any and provided
116      * nested rule if any.
117      * Even if no rules or nestedRule are provided, a compound is expected with ALL rule to set the
118      * rule of the {@see AudioHalConfiguration} as "always applicable".
119      */
120     CompoundRule compoundRule = CompoundRule.INVALID;
121     /*
122      * An AudioHalCapRule may contain 0..n CriterionRules.
123      */
124     CriterionRule[] criterionRules;
125     /*
126      * An AudioHalCapRule may be nested with 0..n AudioHalCapRules.
127      */
128     AudioHalCapRule[] nestedRules;
129 }
130