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 "android.hardware.cas.native@1.0",
48 "android.hardware.gnss.visibility_control@1.0",
49 "android.hardware.media.bufferpool@1.0",
50 "android.hardware.media.bufferpool@2.0",
51 "android.hardware.radio.config@1.2",
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 "android.hardware.fastboot@1.0",
56 "android.hardware.fastboot@1.1",
57
58 // Deprecated HALs.
59 // HIDL
60 // TODO(b/171260360) Remove when HAL definition is removed
61 "android.hardware.audio.effect@2.0",
62 "android.hardware.audio@2.0",
63 // Health 1.0 HAL is deprecated. The top level interface are deleted.
64 "android.hardware.health@1.0",
65 // TODO(b/171260670) Remove when HAL definition is removed
66 "android.hardware.nfc@1.0",
67 // TODO(b/171260715) Remove when HAL definition is removed
68 "android.hardware.radio.deprecated@1.0",
69
70 // TODO(b/205175891): File individual bugs for these HALs deprecated in P
71 "android.hardware.audio.effect@4.0",
72 "android.hardware.audio@4.0",
73 "android.hardware.bluetooth.a2dp@1.0",
74 "android.hardware.cas@1.0",
75 "android.hardware.configstore@1.0",
76 "android.hardware.gnss@1.0",
77 "android.hardware.gnss@1.1",
78 "android.hardware.graphics.mapper@2.0",
79 "android.hardware.nfc@1.1",
80 "android.hardware.radio.config@1.0",
81 "android.hardware.radio@1.0",
82 "android.hardware.radio@1.1",
83 "android.hardware.radio@1.3",
84 "android.hardware.thermal@1.0",
85 "android.hardware.thermal@1.1",
86 "android.hardware.wifi.offload@1.0",
87
88 // b/279809679 for HALS deprecated in Q
89 "android.hardware.audio.effect@5.0",
90 "android.hardware.audio@5.0",
91 "android.hardware.boot@1.0",
92 "android.hardware.configstore@1.1",
93 "android.hardware.drm@1.0",
94 "android.hardware.drm@1.1",
95 "android.hardware.drm@1.2",
96 "android.hardware.dumpstate@1.0",
97 "android.hardware.health@2.0",
98 "android.hardware.light@2.0",
99 "android.hardware.power@1.0",
100 "android.hardware.power@1.1",
101 "android.hardware.power@1.2",
102 "android.hardware.power@1.3",
103 "android.hardware.vibrator@1.0",
104 "android.hardware.vibrator@1.1",
105 "android.hardware.vibrator@1.2",
106 "android.hardware.vibrator@1.3",
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.measurement_corrections@",
144 "android.hardware.gnss.visibility_control@",
145 "android.hardware.graphics.common@",
146 "android.hardware.input.common@",
147 "android.hardware.keymaster@",
148 "android.hardware.media.bufferpool2@",
149 "android.hardware.radio@",
150 "android.hardware.uwb.fira_android@",
151 "android.hardware.wifi.common@",
152
153 // Test packages are exempted.
154 "android.hardware.tests.",
155
156 // Fastboot HAL is only used by recovery. Recovery is owned by OEM. Framework
157 // does not depend on this HAL, hence it is not declared in any manifests or matrices.
158 "android.hardware.fastboot@",
159 };
160
161 static std::vector<std::string> excluded_exact{
162 // Packages without top level interfaces (including types-only packages) are exempted.
163
164 // AIDL
165 "android.hardware.audio.core.sounddose@1",
166 "android.hardware.audio.core.sounddose@2",
167
168 // Deprecated HALs.
169 "android.hardware.bluetooth.audio@1",
170 };
171
172 auto package_has_prefix = [&](const std::string& prefix) {
173 return android::base::StartsWith(packageAndVersion, prefix);
174 };
175
176 // Only check packageAndVersions that are in the include list and not in the exclude list.
177 if (!std::any_of(included_prefixes.begin(), included_prefixes.end(), package_has_prefix)) {
178 return false;
179 }
180
181 if (std::find(excluded_exact.begin(), excluded_exact.end(), packageAndVersion) !=
182 excluded_exact.end()) {
183 return false;
184 }
185
186 return !std::any_of(excluded_prefixes.begin(), excluded_prefixes.end(), package_has_prefix);
187 }
188
189 } // namespace android::vintf::details
190