blob: 8d9df31e4324ac510e46d3dd7a80f0eaf0ae0335 [file] [log] [blame]
Yifan Hong3daec812017-02-27 18:49:11 -08001/*
2 * Copyright (C) 2017 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 "VintfObject.h"
18
Yifan Hongd52bf3e2018-01-11 16:56:51 -080019#include <dirent.h>
20
Yifan Hong03ea4282020-03-17 17:58:35 -070021#include <algorithm>
Yifan Hong3daec812017-02-27 18:49:11 -080022#include <functional>
23#include <memory>
24#include <mutex>
25
Yifan Hongd7043972020-03-30 13:27:46 -070026#include <aidl/metadata.h>
Yifan Hong60217032018-01-08 16:19:42 -080027#include <android-base/logging.h>
Yifan Hong6b860852020-03-19 23:12:07 +000028#include <android-base/result.h>
Yifan Hongb02d87d2019-12-19 11:15:27 -080029#include <android-base/strings.h>
Yifan Hongd7924ff2020-03-17 14:09:10 -070030#include <hidl/metadata.h>
Yifan Hong60217032018-01-08 16:19:42 -080031
Yifan Hong12e23c22018-11-05 14:53:30 -080032#include "CompatibilityMatrix.h"
Yifan Hong37535882021-11-29 18:07:21 -080033#include "VintfObjectUtils.h"
Yifan Hongd7043972020-03-30 13:27:46 -070034#include "constants-private.h"
Yifan Hong12e23c22018-11-05 14:53:30 -080035#include "parse_string.h"
36#include "parse_xml.h"
37#include "utils.h"
38
Yifan Hong60217032018-01-08 16:19:42 -080039using std::placeholders::_1;
40using std::placeholders::_2;
Yifan Hongc7a9a292021-02-03 17:27:58 -080041using std::string_literals::operator""s;
Yifan Hong60217032018-01-08 16:19:42 -080042
Yifan Hong3daec812017-02-27 18:49:11 -080043namespace android {
44namespace vintf {
45
Yifan Hong270b5652018-01-18 18:46:01 -080046using namespace details;
47
Yifan Hong9f78c182018-07-12 14:45:52 -070048#ifdef LIBVINTF_TARGET
49static constexpr bool kIsTarget = true;
50#else
51static constexpr bool kIsTarget = false;
52#endif
Yifan Hong1fb004e2017-09-26 15:04:44 -070053
Yifan Hong9f78c182018-07-12 14:45:52 -070054static std::unique_ptr<FileSystem> createDefaultFileSystem() {
55 std::unique_ptr<FileSystem> fileSystem;
56 if (kIsTarget) {
57 fileSystem = std::make_unique<details::FileSystemImpl>();
58 } else {
59 fileSystem = std::make_unique<details::FileSystemNoOp>();
60 }
61 return fileSystem;
62}
63
64static std::unique_ptr<PropertyFetcher> createDefaultPropertyFetcher() {
65 std::unique_ptr<PropertyFetcher> propertyFetcher;
66 if (kIsTarget) {
67 propertyFetcher = std::make_unique<details::PropertyFetcherImpl>();
68 } else {
69 propertyFetcher = std::make_unique<details::PropertyFetcherNoOp>();
70 }
71 return propertyFetcher;
72}
73
Yifan Hong9f78c182018-07-12 14:45:52 -070074std::shared_ptr<VintfObject> VintfObject::GetInstance() {
Steven Morelandc16ff2b2020-02-26 17:03:37 -080075 static details::LockedSharedPtr<VintfObject> sInstance{};
Yifan Hong9f78c182018-07-12 14:45:52 -070076 std::unique_lock<std::mutex> lock(sInstance.mutex);
77 if (sInstance.object == nullptr) {
Yifan Hong78f5b572018-11-27 14:05:03 -080078 sInstance.object = std::shared_ptr<VintfObject>(VintfObject::Builder().build().release());
Yifan Hong9f78c182018-07-12 14:45:52 -070079 }
80 return sInstance.object;
81}
82
Yifan Hong44f611c2020-07-21 11:57:57 -070083std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest() {
84 return GetInstance()->getDeviceHalManifest();
Yifan Hong3daec812017-02-27 18:49:11 -080085}
86
Yifan Hong44f611c2020-07-21 11:57:57 -070087std::shared_ptr<const HalManifest> VintfObject::getDeviceHalManifest() {
88 return Get(__func__, &mDeviceManifest,
Yifan Hong9f78c182018-07-12 14:45:52 -070089 std::bind(&VintfObject::fetchDeviceHalManifest, this, _1, _2));
90}
91
Yifan Hong44f611c2020-07-21 11:57:57 -070092std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest() {
93 return GetInstance()->getFrameworkHalManifest();
Yifan Hong3daec812017-02-27 18:49:11 -080094}
95
Yifan Hong44f611c2020-07-21 11:57:57 -070096std::shared_ptr<const HalManifest> VintfObject::getFrameworkHalManifest() {
97 return Get(__func__, &mFrameworkManifest,
Yifan Hong9f78c182018-07-12 14:45:52 -070098 std::bind(&VintfObject::fetchFrameworkHalManifest, this, _1, _2));
99}
Yifan Hong2272bf82017-04-28 14:37:56 -0700100
Yifan Hong44f611c2020-07-21 11:57:57 -0700101std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix() {
102 return GetInstance()->getDeviceCompatibilityMatrix();
Yifan Hong2272bf82017-04-28 14:37:56 -0700103}
104
Yifan Hong44f611c2020-07-21 11:57:57 -0700105std::shared_ptr<const CompatibilityMatrix> VintfObject::getDeviceCompatibilityMatrix() {
106 return Get(__func__, &mDeviceMatrix, std::bind(&VintfObject::fetchDeviceMatrix, this, _1, _2));
Yifan Hong9f78c182018-07-12 14:45:52 -0700107}
108
Yifan Hong44f611c2020-07-21 11:57:57 -0700109std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix() {
110 return GetInstance()->getFrameworkCompatibilityMatrix();
Yifan Hong9f78c182018-07-12 14:45:52 -0700111}
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800112
Yifan Hong44f611c2020-07-21 11:57:57 -0700113std::shared_ptr<const CompatibilityMatrix> VintfObject::getFrameworkCompatibilityMatrix() {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800114 // To avoid deadlock, get device manifest before any locks.
Yifan Hong9f78c182018-07-12 14:45:52 -0700115 auto deviceManifest = getDeviceHalManifest();
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800116
Yifan Hong507815b2021-05-21 16:48:37 -0700117 std::string error;
118 auto kernelLevel = getKernelLevel(&error);
119 if (kernelLevel == Level::UNSPECIFIED) {
120 LOG(WARNING) << "getKernelLevel: " << error;
121 }
122
Yifan Hong9f78c182018-07-12 14:45:52 -0700123 std::unique_lock<std::mutex> _lock(mFrameworkCompatibilityMatrixMutex);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800124
Yifan Hong507815b2021-05-21 16:48:37 -0700125 auto combined = Get(__func__, &mCombinedFrameworkMatrix,
126 std::bind(&VintfObject::getCombinedFrameworkMatrix, this, deviceManifest,
127 kernelLevel, _1, _2));
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800128 if (combined != nullptr) {
129 return combined;
130 }
131
Yifan Hong44f611c2020-07-21 11:57:57 -0700132 return Get(__func__, &mFrameworkMatrix,
Yifan Hong12e23c22018-11-05 14:53:30 -0800133 std::bind(&CompatibilityMatrix::fetchAllInformation, _1, getFileSystem().get(),
Yifan Hong9f78c182018-07-12 14:45:52 -0700134 kSystemLegacyMatrix, _2));
Yifan Hong2272bf82017-04-28 14:37:56 -0700135}
136
Yifan Hong9f78c182018-07-12 14:45:52 -0700137status_t VintfObject::getCombinedFrameworkMatrix(
Yifan Hong507815b2021-05-21 16:48:37 -0700138 const std::shared_ptr<const HalManifest>& deviceManifest, Level kernelLevel,
139 CompatibilityMatrix* out, std::string* error) {
Yifan Honga83d0e42020-04-13 13:07:31 -0700140 std::vector<CompatibilityMatrix> matrixFragments;
Yifan Hong73bde592019-01-22 13:30:23 -0800141 auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error);
142 if (matrixFragmentsStatus != OK) {
143 return matrixFragmentsStatus;
144 }
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800145 if (matrixFragments.empty()) {
Yifan Hong73bde592019-01-22 13:30:23 -0800146 if (error && error->empty()) {
147 *error = "Cannot get framework matrix for each FCM version for unknown error.";
148 }
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800149 return NAME_NOT_FOUND;
150 }
151
152 Level deviceLevel = Level::UNSPECIFIED;
153
154 if (deviceManifest != nullptr) {
155 deviceLevel = deviceManifest->level();
156 }
157
158 // TODO(b/70628538): Do not infer from Shipping API level.
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800159 if (deviceLevel == Level::UNSPECIFIED) {
Yifan Hong12e23c22018-11-05 14:53:30 -0800160 auto shippingApi = getPropertyFetcher()->getUintProperty("ro.product.first_api_level", 0u);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800161 if (shippingApi != 0u) {
162 deviceLevel = details::convertFromApiLevel(shippingApi);
163 }
164 }
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800165
166 if (deviceLevel == Level::UNSPECIFIED) {
167 // Cannot infer FCM version. Combine all matrices by assuming
168 // Shipping FCM Version == min(all supported FCM Versions in the framework)
Yifan Honga83d0e42020-04-13 13:07:31 -0700169 for (auto&& fragment : matrixFragments) {
170 Level fragmentLevel = fragment.level();
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800171 if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) {
172 deviceLevel = fragmentLevel;
173 }
174 }
175 }
176
177 if (deviceLevel == Level::UNSPECIFIED) {
178 // None of the fragments specify any FCM version. Should never happen except
179 // for inconsistent builds.
180 if (error) {
Yifan Hongc7a9a292021-02-03 17:27:58 -0800181 *error = "No framework compatibility matrix files under "s + kSystemVintfDir +
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800182 " declare FCM version.";
183 }
184 return NAME_NOT_FOUND;
185 }
186
Yifan Hong507815b2021-05-21 16:48:37 -0700187 auto combined = CompatibilityMatrix::combine(deviceLevel, kernelLevel, &matrixFragments, error);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800188 if (combined == nullptr) {
189 return BAD_VALUE;
190 }
191 *out = std::move(*combined);
192 return OK;
193}
194
Steven Morelandeedf2d42018-04-04 16:36:27 -0700195// Load and combine all of the manifests in a directory
Yifan Hong37535882021-11-29 18:07:21 -0800196// If forceSchemaType, all fragment manifests are coerced into manifest->type().
Yifan Hong9f78c182018-07-12 14:45:52 -0700197status_t VintfObject::addDirectoryManifests(const std::string& directory, HalManifest* manifest,
Yifan Hong37535882021-11-29 18:07:21 -0800198 bool forceSchemaType, std::string* error) {
Steven Morelandeedf2d42018-04-04 16:36:27 -0700199 std::vector<std::string> fileNames;
Yifan Hong12e23c22018-11-05 14:53:30 -0800200 status_t err = getFileSystem()->listFiles(directory, &fileNames, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700201 // if the directory isn't there, that's okay
Xin Li12896432021-08-18 08:29:29 +0000202 if (err == NAME_NOT_FOUND) {
203 if (error) {
204 error->clear();
205 }
206 return OK;
207 }
Steven Morelandeedf2d42018-04-04 16:36:27 -0700208 if (err != OK) return err;
209
210 for (const std::string& file : fileNames) {
211 // Only adds HALs because all other things are added by libvintf
212 // itself for now.
213 HalManifest fragmentManifest;
Yifan Hong9f78c182018-07-12 14:45:52 -0700214 err = fetchOneHalManifest(directory + file, &fragmentManifest, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700215 if (err != OK) return err;
216
Yifan Hong37535882021-11-29 18:07:21 -0800217 if (forceSchemaType) {
218 fragmentManifest.setType(manifest->type());
219 }
220
Yifan Hong4c6962d2019-01-30 15:50:46 -0800221 if (!manifest->addAll(&fragmentManifest, error)) {
222 if (error) {
Yifan Hong9f9a3192020-04-13 16:39:45 -0700223 error->insert(0, "Cannot add manifest fragment " + directory + file + ": ");
Yifan Hong4c6962d2019-01-30 15:50:46 -0800224 }
225 return UNKNOWN_ERROR;
226 }
Steven Morelandeedf2d42018-04-04 16:36:27 -0700227 }
228
229 return OK;
230}
231
Yifan Hong5a93bf22018-01-17 18:22:32 -0800232// Priority for loading vendor manifest:
Roopesh Natarajad629d382020-02-26 09:51:38 -0800233// 1. Vendor manifest + device fragments + ODM manifest (optional) + odm fragments
234// 2. Vendor manifest + device fragments
Steven Morelandeedf2d42018-04-04 16:36:27 -0700235// 3. ODM manifest (optional) + odm fragments
236// 4. /vendor/manifest.xml (legacy, no fragments)
Yifan Hong5a93bf22018-01-17 18:22:32 -0800237// where:
Steven Moreland30a532c2018-11-01 08:46:32 -0700238// A + B means unioning <hal> tags from A and B. If B declares an override, then this takes priority
239// over A.
Yifan Hong9f78c182018-07-12 14:45:52 -0700240status_t VintfObject::fetchDeviceHalManifest(HalManifest* out, std::string* error) {
Roopesh Natarajad629d382020-02-26 09:51:38 -0800241 HalManifest vendorManifest;
242 status_t vendorStatus = fetchVendorHalManifest(&vendorManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800243 if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) {
244 return vendorStatus;
245 }
246
Steven Morelandeedf2d42018-04-04 16:36:27 -0700247 if (vendorStatus == OK) {
Roopesh Natarajad629d382020-02-26 09:51:38 -0800248 *out = std::move(vendorManifest);
Yifan Hong37535882021-11-29 18:07:21 -0800249 status_t fragmentStatus = addDirectoryManifests(kVendorManifestFragmentDir, out,
250 false /* forceSchemaType*/, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700251 if (fragmentStatus != OK) {
252 return fragmentStatus;
253 }
254 }
255
Yifan Hong5a93bf22018-01-17 18:22:32 -0800256 HalManifest odmManifest;
Yifan Hong9f78c182018-07-12 14:45:52 -0700257 status_t odmStatus = fetchOdmHalManifest(&odmManifest, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800258 if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
259 return odmStatus;
Yifan Hong5a93bf22018-01-17 18:22:32 -0800260 }
261
Yifan Hong5a93bf22018-01-17 18:22:32 -0800262 if (vendorStatus == OK) {
Yifan Hong12a11ac2018-01-19 13:58:32 -0800263 if (odmStatus == OK) {
Yifan Hong4c6962d2019-01-30 15:50:46 -0800264 if (!out->addAll(&odmManifest, error)) {
265 if (error) {
266 error->insert(0, "Cannot add ODM manifest :");
267 }
268 return UNKNOWN_ERROR;
269 }
Yifan Hong12a11ac2018-01-19 13:58:32 -0800270 }
Yifan Hong37535882021-11-29 18:07:21 -0800271 return addDirectoryManifests(kOdmManifestFragmentDir, out, false /* forceSchemaType */,
272 error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800273 }
274
Yifan Hong12a11ac2018-01-19 13:58:32 -0800275 // vendorStatus != OK, "out" is not changed.
Yifan Hong5a93bf22018-01-17 18:22:32 -0800276 if (odmStatus == OK) {
277 *out = std::move(odmManifest);
Yifan Hong37535882021-11-29 18:07:21 -0800278 return addDirectoryManifests(kOdmManifestFragmentDir, out, false /* forceSchemaType */,
279 error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800280 }
281
282 // Use legacy /vendor/manifest.xml
Yifan Hong12e23c22018-11-05 14:53:30 -0800283 return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800284}
285
Roopesh Natarajad629d382020-02-26 09:51:38 -0800286// Priority:
287// 1. if {vendorSku} is defined, /vendor/etc/vintf/manifest_{vendorSku}.xml
288// 2. /vendor/etc/vintf/manifest.xml
289// where:
290// {vendorSku} is the value of ro.boot.product.vendor.sku
291status_t VintfObject::fetchVendorHalManifest(HalManifest* out, std::string* error) {
292 status_t status;
293
294 std::string vendorSku;
295 vendorSku = getPropertyFetcher()->getProperty("ro.boot.product.vendor.sku", "");
296
297 if (!vendorSku.empty()) {
298 status =
Yifan Hongc7a9a292021-02-03 17:27:58 -0800299 fetchOneHalManifest(kVendorVintfDir + "manifest_"s + vendorSku + ".xml", out, error);
Roopesh Natarajad629d382020-02-26 09:51:38 -0800300 if (status == OK || status != NAME_NOT_FOUND) {
301 return status;
302 }
303 }
304
305 status = fetchOneHalManifest(kVendorManifest, out, error);
306 if (status == OK || status != NAME_NOT_FOUND) {
307 return status;
308 }
309
310 return NAME_NOT_FOUND;
311}
312
Yifan Hong12a11ac2018-01-19 13:58:32 -0800313// "out" is written to iff return status is OK.
314// Priority:
315// 1. if {sku} is defined, /odm/etc/vintf/manifest_{sku}.xml
316// 2. /odm/etc/vintf/manifest.xml
317// 3. if {sku} is defined, /odm/etc/manifest_{sku}.xml
318// 4. /odm/etc/manifest.xml
319// where:
320// {sku} is the value of ro.boot.product.hardware.sku
Yifan Hong9f78c182018-07-12 14:45:52 -0700321status_t VintfObject::fetchOdmHalManifest(HalManifest* out, std::string* error) {
Yifan Hong12a11ac2018-01-19 13:58:32 -0800322 status_t status;
323
Yifan Hong12a11ac2018-01-19 13:58:32 -0800324 std::string productModel;
Yifan Hong12e23c22018-11-05 14:53:30 -0800325 productModel = getPropertyFetcher()->getProperty("ro.boot.product.hardware.sku", "");
Yifan Hong12a11ac2018-01-19 13:58:32 -0800326
327 if (!productModel.empty()) {
328 status =
Yifan Hongc7a9a292021-02-03 17:27:58 -0800329 fetchOneHalManifest(kOdmVintfDir + "manifest_"s + productModel + ".xml", out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800330 if (status == OK || status != NAME_NOT_FOUND) {
331 return status;
332 }
333 }
Yifan Hong12a11ac2018-01-19 13:58:32 -0800334
Yifan Hong9f78c182018-07-12 14:45:52 -0700335 status = fetchOneHalManifest(kOdmManifest, out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800336 if (status == OK || status != NAME_NOT_FOUND) {
337 return status;
338 }
339
Yifan Hong12a11ac2018-01-19 13:58:32 -0800340 if (!productModel.empty()) {
Yifan Hongc7a9a292021-02-03 17:27:58 -0800341 status = fetchOneHalManifest(kOdmLegacyVintfDir + "manifest_"s + productModel + ".xml", out,
Yifan Hong12a11ac2018-01-19 13:58:32 -0800342 error);
343 if (status == OK || status != NAME_NOT_FOUND) {
344 return status;
345 }
346 }
Yifan Hong12a11ac2018-01-19 13:58:32 -0800347
Yifan Hong9f78c182018-07-12 14:45:52 -0700348 status = fetchOneHalManifest(kOdmLegacyManifest, out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800349 if (status == OK || status != NAME_NOT_FOUND) {
350 return status;
351 }
352
353 return NAME_NOT_FOUND;
354}
355
356// Fetch one manifest.xml file. "out" is written to iff return status is OK.
357// Returns NAME_NOT_FOUND if file is missing.
Yifan Hong9f78c182018-07-12 14:45:52 -0700358status_t VintfObject::fetchOneHalManifest(const std::string& path, HalManifest* out,
Yifan Hong12a11ac2018-01-19 13:58:32 -0800359 std::string* error) {
360 HalManifest ret;
Yifan Hong12e23c22018-11-05 14:53:30 -0800361 status_t status = ret.fetchAllInformation(getFileSystem().get(), path, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800362 if (status == OK) {
363 *out = std::move(ret);
364 }
365 return status;
366}
367
Yifan Hong9f78c182018-07-12 14:45:52 -0700368status_t VintfObject::fetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) {
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800369 CompatibilityMatrix etcMatrix;
Yifan Hong12e23c22018-11-05 14:53:30 -0800370 if (etcMatrix.fetchAllInformation(getFileSystem().get(), kVendorMatrix, error) == OK) {
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800371 *out = std::move(etcMatrix);
372 return OK;
373 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800374 return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyMatrix, error);
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800375}
376
Yifan Hong5f4e57e2019-04-23 15:16:25 -0700377// Priority:
378// 1. /system/etc/vintf/manifest.xml
379// + /system/etc/vintf/manifest/*.xml if they exist
380// + /product/etc/vintf/manifest.xml if it exists
381// + /product/etc/vintf/manifest/*.xml if they exist
382// 2. (deprecated) /system/manifest.xml
Yifan Hongc735be92020-10-12 16:25:50 -0700383status_t VintfObject::fetchUnfilteredFrameworkHalManifest(HalManifest* out, std::string* error) {
Yifan Hong5f4e57e2019-04-23 15:16:25 -0700384 auto systemEtcStatus = fetchOneHalManifest(kSystemManifest, out, error);
385 if (systemEtcStatus == OK) {
Yifan Hong37535882021-11-29 18:07:21 -0800386 auto dirStatus = addDirectoryManifests(kSystemManifestFragmentDir, out,
387 false /* forceSchemaType */, error);
Yifan Hong5f4e57e2019-04-23 15:16:25 -0700388 if (dirStatus != OK) {
389 return dirStatus;
390 }
391
Yifan Hongc7a9a292021-02-03 17:27:58 -0800392 std::vector<std::pair<const char*, const char*>> extensions{
Yifan Hong659feac2020-03-19 18:09:54 -0700393 {kProductManifest, kProductManifestFragmentDir},
394 {kSystemExtManifest, kSystemExtManifestFragmentDir},
395 };
396 for (auto&& [manifestPath, frags] : extensions) {
397 HalManifest halManifest;
398 auto status = fetchOneHalManifest(manifestPath, &halManifest, error);
399 if (status != OK && status != NAME_NOT_FOUND) {
400 return status;
401 }
402 if (status == OK) {
403 if (!out->addAll(&halManifest, error)) {
404 if (error) {
Yifan Hongc7a9a292021-02-03 17:27:58 -0800405 error->insert(0, "Cannot add "s + manifestPath + ":");
Yifan Hong659feac2020-03-19 18:09:54 -0700406 }
407 return UNKNOWN_ERROR;
Yifan Hong5f4e57e2019-04-23 15:16:25 -0700408 }
Yifan Hong659feac2020-03-19 18:09:54 -0700409 }
410
Yifan Hong37535882021-11-29 18:07:21 -0800411 auto fragmentStatus =
412 addDirectoryManifests(frags, out, false /* forceSchemaType */, error);
Yifan Hong659feac2020-03-19 18:09:54 -0700413 if (fragmentStatus != OK) {
414 return fragmentStatus;
Yifan Hong5f4e57e2019-04-23 15:16:25 -0700415 }
416 }
Yifan Hongc735be92020-10-12 16:25:50 -0700417
Yifan Hong659feac2020-03-19 18:09:54 -0700418 return OK;
Yifan Hong5f4e57e2019-04-23 15:16:25 -0700419 } else {
420 LOG(WARNING) << "Cannot fetch " << kSystemManifest << ": "
421 << (error ? *error : strerror(-systemEtcStatus));
Yifan Hongde6d00e2018-02-27 17:11:28 -0800422 }
Yifan Hong5f4e57e2019-04-23 15:16:25 -0700423
Yifan Hong12e23c22018-11-05 14:53:30 -0800424 return out->fetchAllInformation(getFileSystem().get(), kSystemLegacyManifest, error);
Yifan Hongde6d00e2018-02-27 17:11:28 -0800425}
426
Yifan Hongc735be92020-10-12 16:25:50 -0700427status_t VintfObject::fetchFrameworkHalManifest(HalManifest* out, std::string* error) {
428 status_t status = fetchUnfilteredFrameworkHalManifest(out, error);
429 if (status != OK) {
430 return status;
431 }
432 filterHalsByDeviceManifestLevel(out);
433 return OK;
434}
435
436void VintfObject::filterHalsByDeviceManifestLevel(HalManifest* out) {
437 auto deviceManifest = getDeviceHalManifest();
438 if (deviceManifest == nullptr) {
439 LOG(WARNING) << "Cannot fetch device manifest to determine target FCM version to "
440 "filter framework manifest HALs.";
441 return;
442 }
443 Level deviceManifestLevel = deviceManifest->level();
444 if (deviceManifestLevel == Level::UNSPECIFIED) {
445 LOG(WARNING)
446 << "Not filtering framework manifest HALs because target FCM version is unspecified.";
447 return;
448 }
449 out->removeHalsIf([deviceManifestLevel](const ManifestHal& hal) {
450 if (hal.getMaxLevel() == Level::UNSPECIFIED) {
451 return false;
452 }
453 return hal.getMaxLevel() < deviceManifestLevel;
454 });
455}
456
Yifan Hong9f8f6562018-11-06 16:26:20 -0800457static void appendLine(std::string* error, const std::string& message) {
458 if (error != nullptr) {
459 if (!error->empty()) *error += "\n";
460 *error += message;
461 }
462}
463
Yifan Honga83d0e42020-04-13 13:07:31 -0700464status_t VintfObject::getOneMatrix(const std::string& path, CompatibilityMatrix* out,
Yifan Hong73bde592019-01-22 13:30:23 -0800465 std::string* error) {
466 std::string content;
467 status_t status = getFileSystem()->fetch(path, &content, error);
468 if (status != OK) {
469 return status;
470 }
Yifan Hong25e2a772021-04-16 18:34:28 -0700471 if (!fromXml(out, content, error)) {
Yifan Hong73bde592019-01-22 13:30:23 -0800472 if (error) {
473 error->insert(0, "Cannot parse " + path + ": ");
474 }
475 return BAD_VALUE;
476 }
Yifan Honga83d0e42020-04-13 13:07:31 -0700477 out->setFileName(path);
Yifan Hong73bde592019-01-22 13:30:23 -0800478 return OK;
479}
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800480
Yifan Honga83d0e42020-04-13 13:07:31 -0700481status_t VintfObject::getAllFrameworkMatrixLevels(std::vector<CompatibilityMatrix>* results,
Yifan Hong73bde592019-01-22 13:30:23 -0800482 std::string* error) {
Yifan Hongb02d87d2019-12-19 11:15:27 -0800483 std::vector<std::string> dirs = {
484 kSystemVintfDir,
Yifan Honga0968e82019-12-19 14:08:13 -0800485 kSystemExtVintfDir,
Yifan Hongb02d87d2019-12-19 11:15:27 -0800486 kProductVintfDir,
487 };
488 for (const auto& dir : dirs) {
489 std::vector<std::string> fileNames;
490 status_t listStatus = getFileSystem()->listFiles(dir, &fileNames, error);
491 if (listStatus == NAME_NOT_FOUND) {
Xin Li12896432021-08-18 08:29:29 +0000492 if (error) {
493 error->clear();
494 }
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800495 continue;
496 }
Yifan Hongb02d87d2019-12-19 11:15:27 -0800497 if (listStatus != OK) {
498 return listStatus;
499 }
500 for (const std::string& fileName : fileNames) {
501 std::string path = dir + fileName;
Yifan Honga83d0e42020-04-13 13:07:31 -0700502 CompatibilityMatrix namedMatrix;
Yifan Hongb02d87d2019-12-19 11:15:27 -0800503 std::string matrixError;
504 status_t matrixStatus = getOneMatrix(path, &namedMatrix, &matrixError);
505 if (matrixStatus != OK) {
506 // Manifests and matrices share the same dir. Client may not have enough
507 // permissions to read system manifests, or may not be able to parse it.
508 auto logLevel = matrixStatus == BAD_VALUE ? base::DEBUG : base::ERROR;
509 LOG(logLevel) << "Framework Matrix: Ignore file " << path << ": " << matrixError;
510 continue;
511 }
512 results->emplace_back(std::move(namedMatrix));
513 }
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800514
Yifan Hongb02d87d2019-12-19 11:15:27 -0800515 if (dir == kSystemVintfDir && results->empty()) {
516 if (error) {
517 *error = "No framework matrices under " + dir + " can be fetched or parsed.\n";
518 }
519 return NAME_NOT_FOUND;
520 }
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800521 }
522
Yifan Hong73bde592019-01-22 13:30:23 -0800523 if (results->empty()) {
524 if (error) {
525 *error =
Yifan Hongb02d87d2019-12-19 11:15:27 -0800526 "No framework matrices can be fetched or parsed. "
527 "The following directories are searched:\n " +
528 android::base::Join(dirs, "\n ");
Yifan Hong73bde592019-01-22 13:30:23 -0800529 }
530 return NAME_NOT_FOUND;
531 }
532 return OK;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800533}
534
Yifan Honga192fa52020-07-21 12:09:20 -0700535std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(RuntimeInfo::FetchFlags flags) {
536 return GetInstance()->getRuntimeInfo(flags);
Yifan Hong9f78c182018-07-12 14:45:52 -0700537}
Yifan Honga192fa52020-07-21 12:09:20 -0700538std::shared_ptr<const RuntimeInfo> VintfObject::getRuntimeInfo(RuntimeInfo::FetchFlags flags) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700539 std::unique_lock<std::mutex> _lock(mDeviceRuntimeInfo.mutex);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700540
Yifan Honga192fa52020-07-21 12:09:20 -0700541 // Skip fetching information that has already been fetched previously.
542 flags &= (~mDeviceRuntimeInfo.fetchedFlags);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700543
Yifan Hong9f78c182018-07-12 14:45:52 -0700544 if (mDeviceRuntimeInfo.object == nullptr) {
Yifan Hong12e23c22018-11-05 14:53:30 -0800545 mDeviceRuntimeInfo.object = getRuntimeInfoFactory()->make_shared();
Yifan Hong1fb004e2017-09-26 15:04:44 -0700546 }
547
Yifan Hong9f78c182018-07-12 14:45:52 -0700548 status_t status = mDeviceRuntimeInfo.object->fetchAllInformation(flags);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700549 if (status != OK) {
Yifan Hong7becb062020-11-13 15:54:58 -0800550 // If only kernel FCM is needed, ignore errors when fetching RuntimeInfo because RuntimeInfo
551 // is not available on host. On host, the kernel level can still be inferred from device
552 // manifest.
553 // If other information is needed, flag the error by returning nullptr.
554 auto allExceptKernelFcm = RuntimeInfo::FetchFlag::ALL & ~RuntimeInfo::FetchFlag::KERNEL_FCM;
555 bool needDeviceRuntimeInfo = flags & allExceptKernelFcm;
556 if (needDeviceRuntimeInfo) {
557 mDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched"
558 return nullptr;
559 }
560 }
561
562 // To support devices without GKI, RuntimeInfo::fetchAllInformation does not report errors
563 // if kernel level cannot be retrieved. If so, fetch kernel FCM version from device HAL
564 // manifest and store it in RuntimeInfo too.
565 if (flags & RuntimeInfo::FetchFlag::KERNEL_FCM) {
566 Level deviceManifestKernelLevel = Level::UNSPECIFIED;
567 auto manifest = getDeviceHalManifest();
568 if (manifest) {
569 deviceManifestKernelLevel = manifest->inferredKernelLevel();
570 }
571 if (deviceManifestKernelLevel != Level::UNSPECIFIED) {
572 Level kernelLevel = mDeviceRuntimeInfo.object->kernelLevel();
573 if (kernelLevel == Level::UNSPECIFIED) {
574 mDeviceRuntimeInfo.object->setKernelLevel(deviceManifestKernelLevel);
575 } else if (kernelLevel != deviceManifestKernelLevel) {
576 LOG(WARNING) << "uname() reports kernel level " << kernelLevel
577 << " but device manifest sets kernel level "
578 << deviceManifestKernelLevel << ". Using kernel level " << kernelLevel;
579 }
580 }
Yifan Hong1fb004e2017-09-26 15:04:44 -0700581 }
582
Yifan Hong9f78c182018-07-12 14:45:52 -0700583 mDeviceRuntimeInfo.fetchedFlags |= flags;
584 return mDeviceRuntimeInfo.object;
Yifan Hong3daec812017-02-27 18:49:11 -0800585}
586
Yifan Hong12e23c22018-11-05 14:53:30 -0800587int32_t VintfObject::checkCompatibility(std::string* error, CheckFlags::Type flags) {
588 status_t status = OK;
589 // null checks for files and runtime info
590 if (getFrameworkHalManifest() == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700591 appendLine(error, "No framework manifest file from device or from update package");
592 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700593 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800594 if (getDeviceHalManifest() == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700595 appendLine(error, "No device manifest file from device or from update package");
596 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700597 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800598 if (getFrameworkCompatibilityMatrix() == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700599 appendLine(error, "No framework matrix file from device or from update package");
600 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700601 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800602 if (getDeviceCompatibilityMatrix() == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700603 appendLine(error, "No device matrix file from device or from update package");
604 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700605 }
Yifan Hong69c1b112018-02-27 17:06:00 -0800606
Yifan Hong072f12d2018-08-08 13:04:51 -0700607 if (flags.isRuntimeInfoEnabled()) {
Yifan Hong12e23c22018-11-05 14:53:30 -0800608 if (getRuntimeInfo() == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700609 appendLine(error, "No runtime info from device");
610 status = NO_INIT;
Yifan Hong69c1b112018-02-27 17:06:00 -0800611 }
Yifan Hong143cfe62017-04-13 20:18:01 -0700612 }
Yifan Hong878556e2018-07-13 13:45:30 -0700613 if (status != OK) return status;
Yifan Hong143cfe62017-04-13 20:18:01 -0700614
615 // compatiblity check.
Yifan Hong12e23c22018-11-05 14:53:30 -0800616 if (!getDeviceHalManifest()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error)) {
Yifan Hongca386fe2018-02-07 11:29:03 -0800617 if (error) {
618 error->insert(0,
619 "Device manifest and framework compatibility matrix are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700620 }
Yifan Hongca386fe2018-02-07 11:29:03 -0800621 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700622 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800623 if (!getFrameworkHalManifest()->checkCompatibility(*getDeviceCompatibilityMatrix(), error)) {
Yifan Hongca386fe2018-02-07 11:29:03 -0800624 if (error) {
625 error->insert(0,
626 "Framework manifest and device compatibility matrix are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700627 }
Yifan Hongca386fe2018-02-07 11:29:03 -0800628 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700629 }
Yifan Hong69c1b112018-02-27 17:06:00 -0800630
Yifan Hong072f12d2018-08-08 13:04:51 -0700631 if (flags.isRuntimeInfoEnabled()) {
Yifan Hong12e23c22018-11-05 14:53:30 -0800632 if (!getRuntimeInfo()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error,
Yifan Hong85e589e2019-12-18 13:12:29 -0800633 flags)) {
Yifan Hong69c1b112018-02-27 17:06:00 -0800634 if (error) {
635 error->insert(0,
636 "Runtime info and framework compatibility matrix are incompatible: ");
637 }
638 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700639 }
640 }
641
642 return COMPATIBLE;
643}
644
Yifan Hong9f78c182018-07-12 14:45:52 -0700645namespace details {
646
Yifan Hong69c1b112018-02-27 17:06:00 -0800647std::vector<std::string> dumpFileList() {
648 return {
Yifan Hong73bde592019-01-22 13:30:23 -0800649 // clang-format off
650 kSystemVintfDir,
651 kVendorVintfDir,
652 kOdmVintfDir,
653 kProductVintfDir,
Yifan Honga0968e82019-12-19 14:08:13 -0800654 kSystemExtVintfDir,
Yifan Hong73bde592019-01-22 13:30:23 -0800655 kOdmLegacyVintfDir,
656 kVendorLegacyManifest,
657 kVendorLegacyMatrix,
658 kSystemLegacyManifest,
659 kSystemLegacyMatrix,
660 // clang-format on
Yifan Hong69c1b112018-02-27 17:06:00 -0800661 };
662}
663
Yifan Hong9f78c182018-07-12 14:45:52 -0700664} // namespace details
Yifan Hong143cfe62017-04-13 20:18:01 -0700665
Yifan Hong9f78c182018-07-12 14:45:52 -0700666bool VintfObject::IsHalDeprecated(const MatrixHal& oldMatrixHal,
Yifan Hongf73ba512018-01-17 15:52:30 -0800667 const CompatibilityMatrix& targetMatrix,
Yifan Hong03ea4282020-03-17 17:58:35 -0700668 const ListInstances& listInstances,
669 const ChildrenMap& childrenMap, std::string* appendedError) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700670 bool isDeprecated = false;
671 oldMatrixHal.forEachInstance([&](const MatrixInstance& oldMatrixInstance) {
Yifan Hong03ea4282020-03-17 17:58:35 -0700672 if (IsInstanceDeprecated(oldMatrixInstance, targetMatrix, listInstances, childrenMap,
673 appendedError)) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700674 isDeprecated = true;
Yifan Hongf73ba512018-01-17 15:52:30 -0800675 }
Yifan Hong03ea4282020-03-17 17:58:35 -0700676 return true; // continue to check next instance
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700677 });
678 return isDeprecated;
Yifan Hongf73ba512018-01-17 15:52:30 -0800679}
680
Yifan Hong03ea4282020-03-17 17:58:35 -0700681// Let oldMatrixInstance = package@x.y-w::interface/instancePattern.
682// If any "@servedVersion::interface/servedInstance" in listInstances(package@x.y::interface)
683// matches instancePattern, return true iff for all child interfaces (from
684// GetListedInstanceInheritance), IsFqInstanceDeprecated returns false.
Yifan Hong9f78c182018-07-12 14:45:52 -0700685bool VintfObject::IsInstanceDeprecated(const MatrixInstance& oldMatrixInstance,
Yifan Hongf73ba512018-01-17 15:52:30 -0800686 const CompatibilityMatrix& targetMatrix,
Yifan Hong03ea4282020-03-17 17:58:35 -0700687 const ListInstances& listInstances,
688 const ChildrenMap& childrenMap, std::string* appendedError) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700689 const std::string& package = oldMatrixInstance.package();
690 const Version& version = oldMatrixInstance.versionRange().minVer();
691 const std::string& interface = oldMatrixInstance.interface();
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700692
Yifan Honga8a8fa92018-03-20 14:42:43 -0700693 std::vector<std::string> instanceHint;
694 if (!oldMatrixInstance.isRegex()) {
695 instanceHint.push_back(oldMatrixInstance.exactInstance());
696 }
697
Yifan Hong03ea4282020-03-17 17:58:35 -0700698 std::vector<std::string> accumulatedErrors;
Yifan Honga8a8fa92018-03-20 14:42:43 -0700699 auto list = listInstances(package, version, interface, instanceHint);
Yifan Hong03ea4282020-03-17 17:58:35 -0700700
Yifan Honga8a8fa92018-03-20 14:42:43 -0700701 for (const auto& pair : list) {
702 const std::string& servedInstance = pair.first;
703 Version servedVersion = pair.second;
Yifan Hong03ea4282020-03-17 17:58:35 -0700704 std::string servedFqInstanceString =
705 toFQNameString(package, servedVersion, interface, servedInstance);
Yifan Honga8a8fa92018-03-20 14:42:43 -0700706 if (!oldMatrixInstance.matchInstance(servedInstance)) {
Yifan Hong03ea4282020-03-17 17:58:35 -0700707 // ignore unrelated instance
Yifan Honga8a8fa92018-03-20 14:42:43 -0700708 continue;
709 }
710
Yifan Hong03ea4282020-03-17 17:58:35 -0700711 auto inheritance = GetListedInstanceInheritance(package, servedVersion, interface,
712 servedInstance, listInstances, childrenMap);
713 if (!inheritance.has_value()) {
714 accumulatedErrors.push_back(inheritance.error().message());
715 continue;
Yifan Hongf73ba512018-01-17 15:52:30 -0800716 }
717
Yifan Hong03ea4282020-03-17 17:58:35 -0700718 std::vector<std::string> errors;
719 for (const auto& fqInstance : *inheritance) {
720 auto result = IsFqInstanceDeprecated(targetMatrix, oldMatrixInstance.format(),
721 fqInstance, listInstances);
722 if (result.ok()) {
723 errors.clear();
Yifan Honga8a8fa92018-03-20 14:42:43 -0700724 break;
725 }
Yifan Hong03ea4282020-03-17 17:58:35 -0700726 errors.push_back(result.error().message());
Yifan Honga8a8fa92018-03-20 14:42:43 -0700727 }
Yifan Hongf73ba512018-01-17 15:52:30 -0800728
Yifan Hong03ea4282020-03-17 17:58:35 -0700729 if (errors.empty()) {
730 continue;
731 }
732 accumulatedErrors.insert(accumulatedErrors.end(), errors.begin(), errors.end());
733 }
734
735 if (accumulatedErrors.empty()) {
736 return false;
737 }
738 appendLine(appendedError, android::base::Join(accumulatedErrors, "\n"));
739 return true;
740}
741
742// Check if fqInstance is listed in |listInstances|.
743bool VintfObject::IsInstanceListed(const ListInstances& listInstances,
744 const FqInstance& fqInstance) {
745 auto list =
746 listInstances(fqInstance.getPackage(), fqInstance.getVersion(), fqInstance.getInterface(),
747 {fqInstance.getInstance()} /* instanceHint*/);
748 return std::any_of(list.begin(), list.end(),
749 [&](const auto& pair) { return pair.first == fqInstance.getInstance(); });
750}
751
752// Return a list of FqInstance, where each element:
753// - is listed in |listInstances|; AND
754// - is, or inherits from, package@version::interface/instance (as specified by |childrenMap|)
755android::base::Result<std::vector<FqInstance>> VintfObject::GetListedInstanceInheritance(
756 const std::string& package, const Version& version, const std::string& interface,
757 const std::string& instance, const ListInstances& listInstances,
758 const ChildrenMap& childrenMap) {
759 FqInstance fqInstance;
760 if (!fqInstance.setTo(package, version.majorVer, version.minorVer, interface, instance)) {
761 return android::base::Error() << toFQNameString(package, version, interface, instance)
762 << " is not a valid FqInstance";
763 }
764
765 if (!IsInstanceListed(listInstances, fqInstance)) {
766 return {};
767 }
768
769 const FQName& fqName = fqInstance.getFqName();
770
771 std::vector<FqInstance> ret;
772 ret.push_back(fqInstance);
773
774 auto childRange = childrenMap.equal_range(fqName.string());
775 for (auto it = childRange.first; it != childRange.second; ++it) {
776 const auto& childFqNameString = it->second;
777 FQName childFqName;
778 if (!childFqName.setTo(childFqNameString)) {
779 return android::base::Error() << "Cannot parse " << childFqNameString << " as FQName";
780 }
781 FqInstance childFqInstance;
782 if (!childFqInstance.setTo(childFqName, fqInstance.getInstance())) {
783 return android::base::Error() << "Cannot merge " << childFqName.string() << "/"
784 << fqInstance.getInstance() << " as FqInstance";
785 continue;
786 }
787 if (!IsInstanceListed(listInstances, childFqInstance)) {
788 continue;
789 }
790 ret.push_back(childFqInstance);
791 }
792 return ret;
793}
794
795// Check if |fqInstance| is in |targetMatrix|; essentially equal to
796// targetMatrix.matchInstance(fqInstance), but provides richer error message. In details:
797// 1. package@x.?::interface/servedInstance is not in targetMatrix; OR
798// 2. package@x.z::interface/servedInstance is in targetMatrix but
799// servedInstance is not in listInstances(package@x.z::interface)
800android::base::Result<void> VintfObject::IsFqInstanceDeprecated(
801 const CompatibilityMatrix& targetMatrix, HalFormat format, const FqInstance& fqInstance,
802 const ListInstances& listInstances) {
803 // Find minimum package@x.? in target matrix, and check if instance is in target matrix.
804 bool foundInstance = false;
805 Version targetMatrixMinVer{SIZE_MAX, SIZE_MAX};
806 targetMatrix.forEachInstanceOfPackage(
807 format, fqInstance.getPackage(), [&](const auto& targetMatrixInstance) {
808 if (targetMatrixInstance.versionRange().majorVer == fqInstance.getMajorVersion() &&
809 targetMatrixInstance.interface() == fqInstance.getInterface() &&
810 targetMatrixInstance.matchInstance(fqInstance.getInstance())) {
811 targetMatrixMinVer =
812 std::min(targetMatrixMinVer, targetMatrixInstance.versionRange().minVer());
813 foundInstance = true;
814 }
Yifan Hongf73ba512018-01-17 15:52:30 -0800815 return true;
Yifan Hong03ea4282020-03-17 17:58:35 -0700816 });
817 if (!foundInstance) {
818 return android::base::Error()
819 << fqInstance.string() << " is deprecated in compatibility matrix at FCM Version "
820 << targetMatrix.level() << "; it should not be served.";
821 }
822
823 // Assuming that targetMatrix requires @x.u-v, require that at least @x.u is served.
824 bool targetVersionServed = false;
825 for (const auto& newPair :
826 listInstances(fqInstance.getPackage(), targetMatrixMinVer, fqInstance.getInterface(),
827 {fqInstance.getInstance()} /* instanceHint */)) {
828 if (newPair.first == fqInstance.getInstance()) {
829 targetVersionServed = true;
830 break;
Yifan Hongf73ba512018-01-17 15:52:30 -0800831 }
832 }
Yifan Honga8a8fa92018-03-20 14:42:43 -0700833
Yifan Hong03ea4282020-03-17 17:58:35 -0700834 if (!targetVersionServed) {
835 return android::base::Error()
836 << fqInstance.string() << " is deprecated; requires at least " << targetMatrixMinVer;
837 }
838 return {};
Yifan Hongf73ba512018-01-17 15:52:30 -0800839}
840
Yifan Hong03ea4282020-03-17 17:58:35 -0700841int32_t VintfObject::checkDeprecation(const ListInstances& listInstances,
842 const std::vector<HidlInterfaceMetadata>& hidlMetadata,
843 std::string* error) {
Yifan Honga83d0e42020-04-13 13:07:31 -0700844 std::vector<CompatibilityMatrix> matrixFragments;
Yifan Hong73bde592019-01-22 13:30:23 -0800845 auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error);
846 if (matrixFragmentsStatus != OK) {
847 return matrixFragmentsStatus;
848 }
Yifan Hongf73ba512018-01-17 15:52:30 -0800849 if (matrixFragments.empty()) {
Yifan Hong73bde592019-01-22 13:30:23 -0800850 if (error && error->empty()) {
Yifan Hongf73ba512018-01-17 15:52:30 -0800851 *error = "Cannot get framework matrix for each FCM version for unknown error.";
Yifan Hong73bde592019-01-22 13:30:23 -0800852 }
Yifan Hongf73ba512018-01-17 15:52:30 -0800853 return NAME_NOT_FOUND;
854 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700855 auto deviceManifest = getDeviceHalManifest();
Yifan Hongf73ba512018-01-17 15:52:30 -0800856 if (deviceManifest == nullptr) {
857 if (error) *error = "No device manifest.";
858 return NAME_NOT_FOUND;
859 }
860 Level deviceLevel = deviceManifest->level();
861 if (deviceLevel == Level::UNSPECIFIED) {
862 if (error) *error = "Device manifest does not specify Shipping FCM Version.";
863 return BAD_VALUE;
864 }
Yifan Hong507815b2021-05-21 16:48:37 -0700865 std::string kernelLevelError;
866 Level kernelLevel = getKernelLevel(&kernelLevelError);
867 if (kernelLevel == Level::UNSPECIFIED) {
868 LOG(WARNING) << kernelLevelError;
869 }
Yifan Hongf73ba512018-01-17 15:52:30 -0800870
Daniel Normanedf80402021-03-29 16:49:22 -0700871 std::vector<CompatibilityMatrix> targetMatrices;
872 // Partition matrixFragments into two groups, where the second group
873 // contains all matrices whose level == deviceLevel.
874 auto targetMatricesPartition = std::partition(
875 matrixFragments.begin(), matrixFragments.end(),
876 [&](const CompatibilityMatrix& matrix) { return matrix.level() != deviceLevel; });
877 // Move these matrices into the targetMatrices vector...
878 std::move(targetMatricesPartition, matrixFragments.end(), std::back_inserter(targetMatrices));
879 if (targetMatrices.empty()) {
Yifan Hongf73ba512018-01-17 15:52:30 -0800880 if (error)
881 *error = "Cannot find framework matrix at FCM version " + to_string(deviceLevel) + ".";
882 return NAME_NOT_FOUND;
883 }
Daniel Normanedf80402021-03-29 16:49:22 -0700884 // so that they can be combined into one matrix for deprecation checking.
Yifan Hong507815b2021-05-21 16:48:37 -0700885 auto targetMatrix =
886 CompatibilityMatrix::combine(deviceLevel, kernelLevel, &targetMatrices, error);
Daniel Normanedf80402021-03-29 16:49:22 -0700887 if (targetMatrix == nullptr) {
888 return BAD_VALUE;
889 }
Yifan Hongf73ba512018-01-17 15:52:30 -0800890
Yifan Hong03ea4282020-03-17 17:58:35 -0700891 std::multimap<std::string, std::string> childrenMap;
892 for (const auto& child : hidlMetadata) {
893 for (const auto& parent : child.inherited) {
894 childrenMap.emplace(parent, child.name);
895 }
896 }
897
898 // Find a list of possibly deprecated HALs by comparing |listInstances| with older matrices.
899 // Matrices with unspecified level are considered "current".
900 bool isDeprecated = false;
Daniel Normanedf80402021-03-29 16:49:22 -0700901 for (auto it = matrixFragments.begin(); it < targetMatricesPartition; ++it) {
902 const auto& namedMatrix = *it;
Yifan Honga83d0e42020-04-13 13:07:31 -0700903 if (namedMatrix.level() == Level::UNSPECIFIED) continue;
Daniel Normanedf80402021-03-29 16:49:22 -0700904 if (namedMatrix.level() > deviceLevel) continue;
Yifan Honga83d0e42020-04-13 13:07:31 -0700905 for (const MatrixHal& hal : namedMatrix.getHals()) {
Yifan Hong03ea4282020-03-17 17:58:35 -0700906 if (IsHalDeprecated(hal, *targetMatrix, listInstances, childrenMap, error)) {
907 isDeprecated = true;
908 }
Yifan Hongf73ba512018-01-17 15:52:30 -0800909 }
910 }
911
Yifan Hong03ea4282020-03-17 17:58:35 -0700912 return isDeprecated ? DEPRECATED : NO_DEPRECATED_HALS;
Yifan Hongf73ba512018-01-17 15:52:30 -0800913}
914
Yifan Hong03ea4282020-03-17 17:58:35 -0700915int32_t VintfObject::checkDeprecation(const std::vector<HidlInterfaceMetadata>& hidlMetadata,
916 std::string* error) {
Yifan Hong2a90ffe2018-03-05 17:45:34 -0800917 using namespace std::placeholders;
Yifan Hong9f78c182018-07-12 14:45:52 -0700918 auto deviceManifest = getDeviceHalManifest();
Yifan Honga8a8fa92018-03-20 14:42:43 -0700919 ListInstances inManifest =
920 [&deviceManifest](const std::string& package, Version version, const std::string& interface,
921 const std::vector<std::string>& /* hintInstances */) {
922 std::vector<std::pair<std::string, Version>> ret;
923 deviceManifest->forEachInstanceOfInterface(
Yifan Hongac621482019-09-10 19:27:20 -0700924 HalFormat::HIDL, package, version, interface,
925 [&ret](const ManifestInstance& manifestInstance) {
Yifan Honga8a8fa92018-03-20 14:42:43 -0700926 ret.push_back(
927 std::make_pair(manifestInstance.instance(), manifestInstance.version()));
928 return true;
929 });
930 return ret;
931 };
Yifan Hong03ea4282020-03-17 17:58:35 -0700932 return checkDeprecation(inManifest, hidlMetadata, error);
Yifan Hongf73ba512018-01-17 15:52:30 -0800933}
Yifan Hong3daec812017-02-27 18:49:11 -0800934
Yifan Hong378c4082019-12-23 13:10:57 -0800935Level VintfObject::getKernelLevel(std::string* error) {
Yifan Hong2d644112020-11-12 16:11:24 -0800936 auto runtimeInfo = getRuntimeInfo(RuntimeInfo::FetchFlag::KERNEL_FCM);
937 if (!runtimeInfo) {
938 if (error) *error = "Cannot retrieve runtime info with kernel level.";
Yifan Hong378c4082019-12-23 13:10:57 -0800939 return Level::UNSPECIFIED;
Yifan Hong1e8febd2019-08-07 16:17:19 -0700940 }
Yifan Hong2d644112020-11-12 16:11:24 -0800941 if (runtimeInfo->kernelLevel() != Level::UNSPECIFIED) {
942 return runtimeInfo->kernelLevel();
Yifan Hong1e8febd2019-08-07 16:17:19 -0700943 }
Yifan Hong2d644112020-11-12 16:11:24 -0800944 if (error) {
945 *error = "Both device manifest and kernel release do not specify kernel FCM version.";
946 }
Yifan Hong378c4082019-12-23 13:10:57 -0800947 return Level::UNSPECIFIED;
Yifan Hong1e8febd2019-08-07 16:17:19 -0700948}
949
Yifan Hong9f78c182018-07-12 14:45:52 -0700950const std::unique_ptr<FileSystem>& VintfObject::getFileSystem() {
951 return mFileSystem;
952}
953
Yifan Hong9f78c182018-07-12 14:45:52 -0700954const std::unique_ptr<PropertyFetcher>& VintfObject::getPropertyFetcher() {
955 return mPropertyFetcher;
956}
957
Yifan Hongd038b2b2018-11-27 13:57:56 -0800958const std::unique_ptr<ObjectFactory<RuntimeInfo>>& VintfObject::getRuntimeInfoFactory() {
Yifan Hong9f78c182018-07-12 14:45:52 -0700959 return mRuntimeInfoFactory;
Yifan Hong10d86222018-04-06 15:41:05 -0700960}
961
Yifan Hong6b860852020-03-19 23:12:07 +0000962android::base::Result<bool> VintfObject::hasFrameworkCompatibilityMatrixExtensions() {
Yifan Honga83d0e42020-04-13 13:07:31 -0700963 std::vector<CompatibilityMatrix> matrixFragments;
Yifan Hong6b860852020-03-19 23:12:07 +0000964 std::string error;
965 status_t status = getAllFrameworkMatrixLevels(&matrixFragments, &error);
966 if (status != OK) {
967 return android::base::Error(-status)
968 << "Cannot get all framework matrix fragments: " << error;
969 }
970 for (const auto& namedMatrix : matrixFragments) {
971 // Returns true if product matrix exists.
Yifan Honga83d0e42020-04-13 13:07:31 -0700972 if (android::base::StartsWith(namedMatrix.fileName(), kProductVintfDir)) {
Yifan Hong6b860852020-03-19 23:12:07 +0000973 return true;
974 }
Yifan Hongf6ff4272020-03-12 22:56:16 -0700975 // Returns true if system_ext matrix exists.
Yifan Honga83d0e42020-04-13 13:07:31 -0700976 if (android::base::StartsWith(namedMatrix.fileName(), kSystemExtVintfDir)) {
Yifan Hongf6ff4272020-03-12 22:56:16 -0700977 return true;
978 }
Yifan Hong6b860852020-03-19 23:12:07 +0000979 // Returns true if device system matrix exists.
Yifan Honga83d0e42020-04-13 13:07:31 -0700980 if (android::base::StartsWith(namedMatrix.fileName(), kSystemVintfDir) &&
981 namedMatrix.level() == Level::UNSPECIFIED && !namedMatrix.getHals().empty()) {
Yifan Hong6b860852020-03-19 23:12:07 +0000982 return true;
983 }
984 }
985 return false;
986}
987
Yifan Hongd7924ff2020-03-17 14:09:10 -0700988android::base::Result<void> VintfObject::checkUnusedHals(
989 const std::vector<HidlInterfaceMetadata>& hidlMetadata) {
Yifan Hong6b860852020-03-19 23:12:07 +0000990 auto matrix = getFrameworkCompatibilityMatrix();
991 if (matrix == nullptr) {
992 return android::base::Error(-NAME_NOT_FOUND) << "Missing framework matrix.";
993 }
994 auto manifest = getDeviceHalManifest();
995 if (manifest == nullptr) {
996 return android::base::Error(-NAME_NOT_FOUND) << "Missing device manifest.";
997 }
Yifan Hongd7924ff2020-03-17 14:09:10 -0700998 auto unused = manifest->checkUnusedHals(*matrix, hidlMetadata);
Yifan Hong6b860852020-03-19 23:12:07 +0000999 if (!unused.empty()) {
1000 return android::base::Error()
1001 << "The following instances are in the device manifest but "
1002 << "not specified in framework compatibility matrix: \n"
1003 << " " << android::base::Join(unused, "\n ") << "\n"
1004 << "Suggested fix:\n"
Yifan Hong5a220b12020-04-07 15:22:24 -07001005 << "1. Update deprecated HALs to the latest version.\n"
1006 << "2. Check for any typos in device manifest or framework compatibility "
Yifan Hong6b860852020-03-19 23:12:07 +00001007 << "matrices with FCM version >= " << matrix->level() << ".\n"
Yifan Hong5a220b12020-04-07 15:22:24 -07001008 << "3. For new platform HALs, add them to any framework compatibility matrix "
1009 << "with FCM version >= " << matrix->level() << " where applicable.\n"
1010 << "4. For device-specific HALs, add to DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE "
Yifan Hong6b860852020-03-19 23:12:07 +00001011 << "or DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE.";
1012 }
1013 return {};
1014}
1015
Yifan Hongd7043972020-03-30 13:27:46 -07001016namespace {
1017
1018// Insert |name| into |ret| if shouldCheck(name).
1019void InsertIf(const std::string& name, const std::function<bool(const std::string&)>& shouldCheck,
1020 std::set<std::string>* ret) {
1021 if (shouldCheck(name)) ret->insert(name);
1022}
1023
1024std::string StripHidlInterface(const std::string& fqNameString) {
1025 FQName fqName;
1026 if (!fqName.setTo(fqNameString)) {
1027 return "";
1028 }
1029 return fqName.getPackageAndVersion().string();
1030}
1031
1032std::string StripAidlType(const std::string& type) {
1033 auto items = android::base::Split(type, ".");
1034 if (items.empty()) {
1035 return "";
1036 }
1037 items.erase(items.end() - 1);
1038 return android::base::Join(items, ".");
1039}
1040
Yifan Hong8c61c752021-02-01 19:21:03 -08001041// android.hardware.foo@1.0
1042std::set<std::string> HidlMetadataToPackagesAndVersions(
Yifan Hongd7043972020-03-30 13:27:46 -07001043 const std::vector<HidlInterfaceMetadata>& hidlMetadata,
1044 const std::function<bool(const std::string&)>& shouldCheck) {
1045 std::set<std::string> ret;
1046 for (const auto& item : hidlMetadata) {
1047 InsertIf(StripHidlInterface(item.name), shouldCheck, &ret);
1048 }
1049 return ret;
1050}
1051
Yifan Hong8c61c752021-02-01 19:21:03 -08001052// android.hardware.foo
1053std::set<std::string> AidlMetadataToPackages(
Yifan Hongd7043972020-03-30 13:27:46 -07001054 const std::vector<AidlInterfaceMetadata>& aidlMetadata,
1055 const std::function<bool(const std::string&)>& shouldCheck) {
1056 std::set<std::string> ret;
1057 for (const auto& item : aidlMetadata) {
1058 for (const auto& type : item.types) {
1059 InsertIf(StripAidlType(type), shouldCheck, &ret);
1060 }
1061 }
1062 return ret;
1063}
1064
Yifan Hong9db8ab12021-02-01 19:21:30 -08001065// android.hardware.foo@1.0::IFoo.
1066// Note that UDTs are not filtered out, so there might be non-interface types.
1067std::set<std::string> HidlMetadataToNames(const std::vector<HidlInterfaceMetadata>& hidlMetadata) {
1068 std::set<std::string> ret;
1069 for (const auto& item : hidlMetadata) {
1070 ret.insert(item.name);
1071 }
1072 return ret;
1073}
1074
1075// android.hardware.foo.IFoo
1076// Note that UDTs are not filtered out, so there might be non-interface types.
1077std::set<std::string> AidlMetadataToNames(const std::vector<AidlInterfaceMetadata>& aidlMetadata) {
1078 std::set<std::string> ret;
1079 for (const auto& item : aidlMetadata) {
1080 for (const auto& type : item.types) {
1081 ret.insert(type);
1082 }
1083 }
1084 return ret;
1085}
1086
Yifan Hongd7043972020-03-30 13:27:46 -07001087} // anonymous namespace
1088
Yifan Hong8c61c752021-02-01 19:21:03 -08001089android::base::Result<std::vector<CompatibilityMatrix>> VintfObject::getAllFrameworkMatrixLevels() {
Yifan Hongd7043972020-03-30 13:27:46 -07001090 // Get all framework matrix fragments instead of the combined framework compatibility matrix
1091 // because the latter may omit interfaces from the latest FCM if device target-level is not
1092 // the latest.
1093 std::vector<CompatibilityMatrix> matrixFragments;
1094 std::string error;
1095 auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, &error);
1096 if (matrixFragmentsStatus != OK) {
1097 return android::base::Error(-matrixFragmentsStatus)
1098 << "Unable to get all framework matrix fragments: " << error;
1099 }
1100 if (matrixFragments.empty()) {
1101 if (error.empty()) {
1102 error = "Cannot get framework matrix for each FCM version for unknown error.";
1103 }
1104 return android::base::Error(-NAME_NOT_FOUND) << error;
1105 }
Yifan Hong8c61c752021-02-01 19:21:03 -08001106 return matrixFragments;
1107}
1108
1109android::base::Result<void> VintfObject::checkMissingHalsInMatrices(
1110 const std::vector<HidlInterfaceMetadata>& hidlMetadata,
1111 const std::vector<AidlInterfaceMetadata>& aidlMetadata,
1112 std::function<bool(const std::string&)> shouldCheck) {
1113 if (!shouldCheck) {
1114 shouldCheck = [](const auto&) { return true; };
1115 }
1116
1117 auto matrixFragments = getAllFrameworkMatrixLevels();
1118 if (!matrixFragments.ok()) return matrixFragments.error();
Yifan Hongd7043972020-03-30 13:27:46 -07001119
1120 // Filter aidlMetadata and hidlMetadata with shouldCheck.
Yifan Hong8c61c752021-02-01 19:21:03 -08001121 auto allAidlPackages = AidlMetadataToPackages(aidlMetadata, shouldCheck);
1122 auto allHidlPackagesAndVersions = HidlMetadataToPackagesAndVersions(hidlMetadata, shouldCheck);
Yifan Hongd7043972020-03-30 13:27:46 -07001123
1124 // Filter out instances in allAidlMetadata and allHidlMetadata that are in the matrices.
1125 std::vector<std::string> errors;
Yifan Hong8c61c752021-02-01 19:21:03 -08001126 for (const auto& matrix : matrixFragments.value()) {
Yifan Hongd7043972020-03-30 13:27:46 -07001127 matrix.forEachInstance([&](const MatrixInstance& matrixInstance) {
1128 switch (matrixInstance.format()) {
1129 case HalFormat::AIDL: {
Yifan Hong8c61c752021-02-01 19:21:03 -08001130 allAidlPackages.erase(matrixInstance.package());
Yifan Hongd7043972020-03-30 13:27:46 -07001131 return true; // continue to next instance
1132 }
1133 case HalFormat::HIDL: {
1134 for (Version v = matrixInstance.versionRange().minVer();
1135 v <= matrixInstance.versionRange().maxVer(); ++v.minorVer) {
Yifan Hong8c61c752021-02-01 19:21:03 -08001136 allHidlPackagesAndVersions.erase(
1137 toFQNameString(matrixInstance.package(), v));
Yifan Hongd7043972020-03-30 13:27:46 -07001138 }
1139 return true; // continue to next instance
1140 }
1141 default: {
1142 if (shouldCheck(matrixInstance.package())) {
1143 errors.push_back("HAL package " + matrixInstance.package() +
1144 " is not allowed to have format " +
1145 to_string(matrixInstance.format()) + ".");
1146 }
1147 return true; // continue to next instance
1148 }
1149 }
1150 });
1151 }
1152
Yifan Hong8c61c752021-02-01 19:21:03 -08001153 if (!allHidlPackagesAndVersions.empty()) {
Yifan Hongd7043972020-03-30 13:27:46 -07001154 errors.push_back(
1155 "The following HIDL packages are not found in any compatibility matrix fragments:\t\n" +
Yifan Hong8c61c752021-02-01 19:21:03 -08001156 android::base::Join(allHidlPackagesAndVersions, "\t\n"));
Yifan Hongd7043972020-03-30 13:27:46 -07001157 }
Yifan Hong8c61c752021-02-01 19:21:03 -08001158 if (!allAidlPackages.empty()) {
Yifan Hongd7043972020-03-30 13:27:46 -07001159 errors.push_back(
1160 "The following AIDL packages are not found in any compatibility matrix fragments:\t\n" +
Yifan Hong8c61c752021-02-01 19:21:03 -08001161 android::base::Join(allAidlPackages, "\t\n"));
Yifan Hongd7043972020-03-30 13:27:46 -07001162 }
1163
1164 if (!errors.empty()) {
1165 return android::base::Error() << android::base::Join(errors, "\n");
1166 }
1167
1168 return {};
1169}
1170
Yifan Hong9db8ab12021-02-01 19:21:30 -08001171android::base::Result<void> VintfObject::checkMatrixHalsHasDefinition(
1172 const std::vector<HidlInterfaceMetadata>& hidlMetadata,
1173 const std::vector<AidlInterfaceMetadata>& aidlMetadata) {
1174 auto matrixFragments = getAllFrameworkMatrixLevels();
1175 if (!matrixFragments.ok()) return matrixFragments.error();
1176
1177 auto allAidlNames = AidlMetadataToNames(aidlMetadata);
1178 auto allHidlNames = HidlMetadataToNames(hidlMetadata);
1179 std::set<std::string> badAidlInterfaces;
1180 std::set<std::string> badHidlInterfaces;
1181
1182 std::vector<std::string> errors;
1183 for (const auto& matrix : matrixFragments.value()) {
1184 if (matrix.level() == Level::UNSPECIFIED) {
1185 LOG(INFO) << "Skip checkMatrixHalsHasDefinition() on " << matrix.fileName()
1186 << " with no level.";
1187 continue;
1188 }
1189
1190 matrix.forEachInstance([&](const MatrixInstance& matrixInstance) {
1191 switch (matrixInstance.format()) {
1192 case HalFormat::AIDL: {
1193 auto matrixInterface =
1194 toAidlFqnameString(matrixInstance.package(), matrixInstance.interface());
1195 if (allAidlNames.find(matrixInterface) == allAidlNames.end()) {
1196 errors.push_back(
1197 "AIDL interface " + matrixInterface + " is referenced in " +
1198 matrix.fileName() +
1199 ", but there is no corresponding .aidl definition associated with an "
1200 "aidl_interface module in this build. Typo?");
1201 }
1202 return true; // continue to next instance
1203 }
1204 case HalFormat::HIDL: {
1205 for (Version v = matrixInstance.versionRange().minVer();
1206 v <= matrixInstance.versionRange().maxVer(); ++v.minorVer) {
1207 auto matrixInterface = matrixInstance.interfaceDescription(v);
1208 if (allHidlNames.find(matrixInterface) == allHidlNames.end()) {
1209 errors.push_back(
1210 "HIDL interface " + matrixInterface + " is referenced in " +
1211 matrix.fileName() +
1212 ", but there is no corresponding .hal definition associated with "
1213 "a hidl_interface module in this build. Typo?");
1214 }
1215 }
1216 return true; // continue to next instance
1217 }
1218 default: {
1219 // We do not have data for native HALs.
1220 return true; // continue to next instance
1221 }
1222 }
1223 });
Yifan Hong3daec812017-02-27 18:49:11 -08001224 }
1225
1226 if (!errors.empty()) {
1227 return android::base::Error() << android::base::Join(errors, "\n");
1228 }
1229
1230 return {};
1231}
1232
1233// make_unique does not work because VintfObject constructor is private.
Yifan Hong9d4c59c2021-11-29 18:37:42 -08001234VintfObject::Builder::Builder()
1235 : VintfObjectBuilder(std::unique_ptr<VintfObject>(new VintfObject())) {}
Yifan Hong3daec812017-02-27 18:49:11 -08001236
Yifan Hong9d4c59c2021-11-29 18:37:42 -08001237namespace details {
1238
1239VintfObjectBuilder::~VintfObjectBuilder() {}
1240
1241VintfObjectBuilder& VintfObjectBuilder::setFileSystem(std::unique_ptr<FileSystem>&& e) {
Yifan Hong3daec812017-02-27 18:49:11 -08001242 mObject->mFileSystem = std::move(e);
1243 return *this;
1244}
1245
Yifan Hong9d4c59c2021-11-29 18:37:42 -08001246VintfObjectBuilder& VintfObjectBuilder::setRuntimeInfoFactory(
Yifan Hong3daec812017-02-27 18:49:11 -08001247 std::unique_ptr<ObjectFactory<RuntimeInfo>>&& e) {
1248 mObject->mRuntimeInfoFactory = std::move(e);
1249 return *this;
1250}
1251
Yifan Hong9d4c59c2021-11-29 18:37:42 -08001252VintfObjectBuilder& VintfObjectBuilder::setPropertyFetcher(std::unique_ptr<PropertyFetcher>&& e) {
Yifan Hong3daec812017-02-27 18:49:11 -08001253 mObject->mPropertyFetcher = std::move(e);
1254 return *this;
1255}
1256
Yifan Hong9d4c59c2021-11-29 18:37:42 -08001257std::unique_ptr<VintfObject> VintfObjectBuilder::buildInternal() {
Yifan Hong3daec812017-02-27 18:49:11 -08001258 if (!mObject->mFileSystem) mObject->mFileSystem = createDefaultFileSystem();
1259 if (!mObject->mRuntimeInfoFactory)
1260 mObject->mRuntimeInfoFactory = std::make_unique<ObjectFactory<RuntimeInfo>>();
1261 if (!mObject->mPropertyFetcher) mObject->mPropertyFetcher = createDefaultPropertyFetcher();
1262 return std::move(mObject);
1263}
1264
Yifan Hong9d4c59c2021-11-29 18:37:42 -08001265} // namespace details
1266
Yifan Hongd7043972020-03-30 13:27:46 -07001267} // namespace vintf
1268} // namespace android