1 /*
2 * Copyright (C) 2020 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 #include <functional>
18 #include <string>
19 #include <vector>
20
21 #include <android-base/strings.h>
22 #include <vintf/fcm_exclude.h>
23
24 namespace android::vintf::details {
25
26 // The predicate to VintfObject::checkMissingHalsInMatrices.
ShouldCheckMissingHidlHalsInFcm(const std::string & packageAndVersion)27 bool ShouldCheckMissingHidlHalsInFcm(const std::string& packageAndVersion) {
28 static std::vector<std::string> included_prefixes{
29 // Other AOSP HALs (e.g. android.frameworks.*) are not added because only framework
30 // matrix is checked.
31 "android.hardware.",
32 };
33
34 static std::vector<std::string> excluded_prefixes{
35 // Packages without top level interfaces (including types-only packages) are exempted.
36 "android.hardware.camera.device@",
37 "android.hardware.gnss.measurement_corrections@1.",
38 "android.hardware.graphics.bufferqueue@",
39
40 // Test packages are exempted.
41 "android.hardware.tests.",
42 };
43
44 static std::vector<std::string> excluded_exact{
45 // Packages without top level interfaces (including types-only packages) are exempted.
46 // HIDL
47 "[email protected]",
48 "[email protected]",
49 "[email protected]",
50 "[email protected]",
51 "[email protected]",
52
53 // Fastboot HAL is only used by recovery. Recovery is owned by OEM. Framework
54 // does not depend on this HAL, hence it is not declared in any manifests or matrices.
55 "[email protected]",
56 "[email protected]",
57
58 // Deprecated HALs.
59 // HIDL
60 // TODO(b/171260360) Remove when HAL definition is removed
61 "[email protected]",
62 "[email protected]",
63 // Health 1.0 HAL is deprecated. The top level interface are deleted.
64 "[email protected]",
65 // TODO(b/171260670) Remove when HAL definition is removed
66 "[email protected]",
67 // TODO(b/171260715) Remove when HAL definition is removed
68 "[email protected]",
69
70 // TODO(b/205175891): File individual bugs for these HALs deprecated in P
71 "[email protected]",
72 "[email protected]",
73 "[email protected]",
74 "[email protected]",
75 "[email protected]",
76 "[email protected]",
77 "[email protected]",
78 "[email protected]",
79 "[email protected]",
80 "[email protected]",
81 "[email protected]",
82 "[email protected]",
83 "[email protected]",
84 "[email protected]",
85 "[email protected]",
86 "[email protected]",
87
88 // b/279809679 for HALS deprecated in Q
89 "[email protected]",
90 "[email protected]",
91 "[email protected]",
92 "[email protected]",
93 "[email protected]",
94 "[email protected]",
95 "[email protected]",
96 "[email protected]",
97 "[email protected]",
98 "[email protected]",
99 "[email protected]",
100 "[email protected]",
101 "[email protected]",
102 "[email protected]",
103 "[email protected]",
104 "[email protected]",
105 "[email protected]",
106 "[email protected]",
107 };
108
109 auto package_has_prefix = [&](const std::string& prefix) {
110 return android::base::StartsWith(packageAndVersion, prefix);
111 };
112
113 // Only check packageAndVersions that are in the include list and not in the exclude list.
114 if (!std::any_of(included_prefixes.begin(), included_prefixes.end(), package_has_prefix)) {
115 return false;
116 }
117
118 if (std::find(excluded_exact.begin(), excluded_exact.end(), packageAndVersion) !=
119 excluded_exact.end()) {
120 return false;
121 }
122
123 return !std::any_of(excluded_prefixes.begin(), excluded_prefixes.end(), package_has_prefix);
124 }
125
126 // The predicate to VintfObject::checkMissingHalsInMatrices.
ShouldCheckMissingAidlHalsInFcm(const std::string & packageAndVersion)127 bool ShouldCheckMissingAidlHalsInFcm(const std::string& packageAndVersion) {
128 static std::vector<std::string> included_prefixes{
129 // Other AOSP HALs (e.g. android.frameworks.*) are not added because only framework
130 // matrix is checked.
131 "android.hardware.",
132 };
133
134 static std::vector<std::string> excluded_prefixes{
135 // Packages without top level interfaces (including types-only packages) are exempted.
136 "android.hardware.audio.common@",
137 "android.hardware.biometrics.common@",
138 "android.hardware.camera.metadata@",
139 "android.hardware.camera.device@",
140 "android.hardware.camera.common@",
141 "android.hardware.common@",
142 "android.hardware.common.fmq@",
143 "android.hardware.gnss.gnss_assistance@",
144 "android.hardware.gnss.measurement_corrections@",
145 "android.hardware.gnss.visibility_control@",
146 "android.hardware.graphics.common@",
147 "android.hardware.input.common@",
148 "android.hardware.keymaster@",
149 "android.hardware.media.bufferpool2@",
150 "android.hardware.radio@",
151 "android.hardware.uwb.fira_android@",
152 "android.hardware.wifi.common@",
153 "android.hardware.biometrics.fingerprint.virtualhal@",
154
155 // Test packages are exempted.
156 "android.hardware.tests.",
157
158 // Fastboot HAL is only used by recovery. Recovery is owned by OEM. Framework
159 // does not depend on this HAL, hence it is not declared in any manifests or matrices.
160 "android.hardware.fastboot@",
161 "android.hardware.security.see.hwcrypto.types",
162 "android.hardware.security.see.storage",
163 };
164
165 static std::vector<std::string> excluded_exact{
166 // Packages without top level interfaces (including types-only packages) are exempted.
167
168 // AIDL
169 "android.hardware.audio.core.sounddose@1",
170 "android.hardware.audio.core.sounddose@2",
171 "android.hardware.audio.core.sounddose@3",
172 // This is only used by a trusty VM
173 "android.hardware.security.see.authmgr@1",
174 "android.hardware.security.see.hdcp@1",
175
176 // Deprecated HALs.
177 "android.hardware.audio.sounddose@3",
178 "android.hardware.bluetooth.audio@1",
179 };
180
181 auto package_has_prefix = [&](const std::string& prefix) {
182 return android::base::StartsWith(packageAndVersion, prefix);
183 };
184
185 // Only check packageAndVersions that are in the include list and not in the exclude list.
186 if (!std::any_of(included_prefixes.begin(), included_prefixes.end(), package_has_prefix)) {
187 return false;
188 }
189
190 if (std::find(excluded_exact.begin(), excluded_exact.end(), packageAndVersion) !=
191 excluded_exact.end()) {
192 return false;
193 }
194
195 return !std::any_of(excluded_prefixes.begin(), excluded_prefixes.end(), package_has_prefix);
196 }
197
198 } // namespace android::vintf::details
199