blob: f39b9333d22b1cae6261948db3359719faf59013 [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 Hong143cfe62017-04-13 20:18:01 -070019#include "CompatibilityMatrix.h"
Yifan Hongf73ba512018-01-17 15:52:30 -080020#include "parse_string.h"
Yifan Hong143cfe62017-04-13 20:18:01 -070021#include "parse_xml.h"
Yifan Hong8640cd12017-05-17 12:02:28 -070022#include "utils.h"
Yifan Hong143cfe62017-04-13 20:18:01 -070023
Yifan Hongd52bf3e2018-01-11 16:56:51 -080024#include <dirent.h>
25
Yifan Hong3daec812017-02-27 18:49:11 -080026#include <functional>
27#include <memory>
28#include <mutex>
29
Yifan Hong60217032018-01-08 16:19:42 -080030#include <android-base/logging.h>
31
32using std::placeholders::_1;
33using std::placeholders::_2;
34
Yifan Hong3daec812017-02-27 18:49:11 -080035namespace android {
36namespace vintf {
37
Yifan Hong270b5652018-01-18 18:46:01 -080038using namespace details;
39
Yifan Hong9f78c182018-07-12 14:45:52 -070040#ifdef LIBVINTF_TARGET
41static constexpr bool kIsTarget = true;
42#else
43static constexpr bool kIsTarget = false;
44#endif
Yifan Hong1fb004e2017-09-26 15:04:44 -070045
Yifan Hong3daec812017-02-27 18:49:11 -080046template <typename T, typename F>
Yifan Hongfc73edf2017-08-29 11:39:07 -070047static std::shared_ptr<const T> Get(
48 LockedSharedPtr<T> *ptr,
Yifan Hong143cfe62017-04-13 20:18:01 -070049 bool skipCache,
Yifan Hong3daec812017-02-27 18:49:11 -080050 const F &fetchAllInformation) {
51 std::unique_lock<std::mutex> _lock(ptr->mutex);
Yifan Hong7219ba12018-01-08 16:23:49 -080052 if (skipCache || !ptr->fetchedOnce) {
Yifan Hong3daec812017-02-27 18:49:11 -080053 ptr->object = std::make_unique<T>();
Yifan Hong60217032018-01-08 16:19:42 -080054 std::string error;
55 if (fetchAllInformation(ptr->object.get(), &error) != OK) {
56 LOG(WARNING) << error;
Yifan Hong3daec812017-02-27 18:49:11 -080057 ptr->object = nullptr; // frees the old object
58 }
Yifan Hong7219ba12018-01-08 16:23:49 -080059 ptr->fetchedOnce = true;
Yifan Hong3daec812017-02-27 18:49:11 -080060 }
Yifan Hongfc73edf2017-08-29 11:39:07 -070061 return ptr->object;
Yifan Hong3daec812017-02-27 18:49:11 -080062}
63
Yifan Hong9f78c182018-07-12 14:45:52 -070064static std::unique_ptr<FileSystem> createDefaultFileSystem() {
65 std::unique_ptr<FileSystem> fileSystem;
66 if (kIsTarget) {
67 fileSystem = std::make_unique<details::FileSystemImpl>();
68 } else {
69 fileSystem = std::make_unique<details::FileSystemNoOp>();
70 }
71 return fileSystem;
72}
73
74static std::unique_ptr<PropertyFetcher> createDefaultPropertyFetcher() {
75 std::unique_ptr<PropertyFetcher> propertyFetcher;
76 if (kIsTarget) {
77 propertyFetcher = std::make_unique<details::PropertyFetcherImpl>();
78 } else {
79 propertyFetcher = std::make_unique<details::PropertyFetcherNoOp>();
80 }
81 return propertyFetcher;
82}
83
84VintfObject::VintfObject(std::unique_ptr<FileSystem>&& fileSystem,
Yifan Hong9f78c182018-07-12 14:45:52 -070085 std::unique_ptr<details::ObjectFactory<RuntimeInfo>>&& runtimeInfoFactory,
86 std::unique_ptr<details::PropertyFetcher>&& propertyFetcher)
87 : mFileSystem(fileSystem ? std::move(fileSystem) : createDefaultFileSystem()),
Yifan Hong9f78c182018-07-12 14:45:52 -070088 mRuntimeInfoFactory(runtimeInfoFactory
89 ? std::move(runtimeInfoFactory)
90 : std::make_unique<details::ObjectFactory<RuntimeInfo>>()),
91 mPropertyFetcher(propertyFetcher ? std::move(propertyFetcher)
92 : createDefaultPropertyFetcher()) {}
93
94details::LockedSharedPtr<VintfObject> VintfObject::sInstance{};
95std::shared_ptr<VintfObject> VintfObject::GetInstance() {
96 std::unique_lock<std::mutex> lock(sInstance.mutex);
97 if (sInstance.object == nullptr) {
98 sInstance.object = std::make_shared<VintfObject>();
99 }
100 return sInstance.object;
101}
102
Yifan Hongfc73edf2017-08-29 11:39:07 -0700103std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700104 return GetInstance()->getDeviceHalManifest(skipCache);
Yifan Hong3daec812017-02-27 18:49:11 -0800105}
106
Yifan Hong9f78c182018-07-12 14:45:52 -0700107std::shared_ptr<const HalManifest> VintfObject::getDeviceHalManifest(bool skipCache) {
108 return Get(&mDeviceManifest, skipCache,
109 std::bind(&VintfObject::fetchDeviceHalManifest, this, _1, _2));
110}
111
Yifan Hongfc73edf2017-08-29 11:39:07 -0700112std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700113 return GetInstance()->getFrameworkHalManifest(skipCache);
Yifan Hong3daec812017-02-27 18:49:11 -0800114}
115
Yifan Hong9f78c182018-07-12 14:45:52 -0700116std::shared_ptr<const HalManifest> VintfObject::getFrameworkHalManifest(bool skipCache) {
117 return Get(&mFrameworkManifest, skipCache,
118 std::bind(&VintfObject::fetchFrameworkHalManifest, this, _1, _2));
119}
Yifan Hong2272bf82017-04-28 14:37:56 -0700120
Yifan Hongfc73edf2017-08-29 11:39:07 -0700121std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700122 return GetInstance()->getDeviceCompatibilityMatrix(skipCache);
Yifan Hong2272bf82017-04-28 14:37:56 -0700123}
124
Yifan Hong9f78c182018-07-12 14:45:52 -0700125std::shared_ptr<const CompatibilityMatrix> VintfObject::getDeviceCompatibilityMatrix(
126 bool skipCache) {
127 return Get(&mDeviceMatrix, skipCache, std::bind(&VintfObject::fetchDeviceMatrix, this, _1, _2));
128}
129
Yifan Hongfc73edf2017-08-29 11:39:07 -0700130std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700131 return GetInstance()->getFrameworkCompatibilityMatrix(skipCache);
132}
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800133
Yifan Hong9f78c182018-07-12 14:45:52 -0700134std::shared_ptr<const CompatibilityMatrix> VintfObject::getFrameworkCompatibilityMatrix(
135 bool skipCache) {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800136 // To avoid deadlock, get device manifest before any locks.
Yifan Hong9f78c182018-07-12 14:45:52 -0700137 auto deviceManifest = getDeviceHalManifest();
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800138
Yifan Hong9f78c182018-07-12 14:45:52 -0700139 std::unique_lock<std::mutex> _lock(mFrameworkCompatibilityMatrixMutex);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800140
141 auto combined =
Yifan Hong9f78c182018-07-12 14:45:52 -0700142 Get(&mCombinedFrameworkMatrix, skipCache,
143 std::bind(&VintfObject::getCombinedFrameworkMatrix, this, deviceManifest, _1, _2));
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800144 if (combined != nullptr) {
145 return combined;
146 }
147
Yifan Hong9f78c182018-07-12 14:45:52 -0700148 return Get(&mFrameworkMatrix, skipCache,
149 std::bind(&CompatibilityMatrix::fetchAllInformation, _1, mFileSystem.get(),
150 kSystemLegacyMatrix, _2));
Yifan Hong2272bf82017-04-28 14:37:56 -0700151}
152
Yifan Hong9f78c182018-07-12 14:45:52 -0700153status_t VintfObject::getCombinedFrameworkMatrix(
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800154 const std::shared_ptr<const HalManifest>& deviceManifest, CompatibilityMatrix* out,
155 std::string* error) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700156 auto matrixFragments = getAllFrameworkMatrixLevels(error);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800157 if (matrixFragments.empty()) {
158 return NAME_NOT_FOUND;
159 }
160
161 Level deviceLevel = Level::UNSPECIFIED;
162
163 if (deviceManifest != nullptr) {
164 deviceLevel = deviceManifest->level();
165 }
166
167 // TODO(b/70628538): Do not infer from Shipping API level.
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800168 if (deviceLevel == Level::UNSPECIFIED) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700169 auto shippingApi = mPropertyFetcher->getUintProperty("ro.product.first_api_level", 0u);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800170 if (shippingApi != 0u) {
171 deviceLevel = details::convertFromApiLevel(shippingApi);
172 }
173 }
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800174
175 if (deviceLevel == Level::UNSPECIFIED) {
176 // Cannot infer FCM version. Combine all matrices by assuming
177 // Shipping FCM Version == min(all supported FCM Versions in the framework)
178 for (auto&& pair : matrixFragments) {
179 Level fragmentLevel = pair.object.level();
180 if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) {
181 deviceLevel = fragmentLevel;
182 }
183 }
184 }
185
186 if (deviceLevel == Level::UNSPECIFIED) {
187 // None of the fragments specify any FCM version. Should never happen except
188 // for inconsistent builds.
189 if (error) {
Yifan Hong270b5652018-01-18 18:46:01 -0800190 *error = "No framework compatibility matrix files under " + kSystemVintfDir +
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800191 " declare FCM version.";
192 }
193 return NAME_NOT_FOUND;
194 }
195
Yifan Honge7837b12018-10-11 10:38:57 -0700196 auto combined = CompatibilityMatrix::combine(deviceLevel, &matrixFragments, error);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800197 if (combined == nullptr) {
198 return BAD_VALUE;
199 }
200 *out = std::move(*combined);
201 return OK;
202}
203
Steven Morelandeedf2d42018-04-04 16:36:27 -0700204// Load and combine all of the manifests in a directory
Yifan Hong9f78c182018-07-12 14:45:52 -0700205status_t VintfObject::addDirectoryManifests(const std::string& directory, HalManifest* manifest,
Steven Morelandeedf2d42018-04-04 16:36:27 -0700206 std::string* error) {
207 std::vector<std::string> fileNames;
Yifan Hong9f78c182018-07-12 14:45:52 -0700208 status_t err = mFileSystem->listFiles(directory, &fileNames, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700209 // if the directory isn't there, that's okay
210 if (err == NAME_NOT_FOUND) return OK;
211 if (err != OK) return err;
212
213 for (const std::string& file : fileNames) {
214 // Only adds HALs because all other things are added by libvintf
215 // itself for now.
216 HalManifest fragmentManifest;
Yifan Hong9f78c182018-07-12 14:45:52 -0700217 err = fetchOneHalManifest(directory + file, &fragmentManifest, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700218 if (err != OK) return err;
219
220 manifest->addAllHals(&fragmentManifest);
221 }
222
223 return OK;
224}
225
Yifan Hong5a93bf22018-01-17 18:22:32 -0800226// Priority for loading vendor manifest:
Steven Morelandeedf2d42018-04-04 16:36:27 -0700227// 1. /vendor/etc/vintf/manifest.xml + device fragments + ODM manifest (optional) + odm fragments
228// 2. /vendor/etc/vintf/manifest.xml + device fragments
229// 3. ODM manifest (optional) + odm fragments
230// 4. /vendor/manifest.xml (legacy, no fragments)
Yifan Hong5a93bf22018-01-17 18:22:32 -0800231// where:
Steven Moreland30a532c2018-11-01 08:46:32 -0700232// A + B means unioning <hal> tags from A and B. If B declares an override, then this takes priority
233// over A.
Yifan Hong9f78c182018-07-12 14:45:52 -0700234status_t VintfObject::fetchDeviceHalManifest(HalManifest* out, std::string* error) {
235 status_t vendorStatus = fetchOneHalManifest(kVendorManifest, out, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800236 if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) {
237 return vendorStatus;
238 }
239
Steven Morelandeedf2d42018-04-04 16:36:27 -0700240 if (vendorStatus == OK) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700241 status_t fragmentStatus = addDirectoryManifests(kVendorManifestFragmentDir, out, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700242 if (fragmentStatus != OK) {
243 return fragmentStatus;
244 }
245 }
246
Yifan Hong5a93bf22018-01-17 18:22:32 -0800247 HalManifest odmManifest;
Yifan Hong9f78c182018-07-12 14:45:52 -0700248 status_t odmStatus = fetchOdmHalManifest(&odmManifest, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800249 if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
250 return odmStatus;
Yifan Hong5a93bf22018-01-17 18:22:32 -0800251 }
252
Yifan Hong5a93bf22018-01-17 18:22:32 -0800253 if (vendorStatus == OK) {
Yifan Hong12a11ac2018-01-19 13:58:32 -0800254 if (odmStatus == OK) {
255 out->addAllHals(&odmManifest);
256 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700257 return addDirectoryManifests(kOdmManifestFragmentDir, out, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800258 }
259
Yifan Hong12a11ac2018-01-19 13:58:32 -0800260 // vendorStatus != OK, "out" is not changed.
Yifan Hong5a93bf22018-01-17 18:22:32 -0800261 if (odmStatus == OK) {
262 *out = std::move(odmManifest);
Yifan Hong9f78c182018-07-12 14:45:52 -0700263 return addDirectoryManifests(kOdmManifestFragmentDir, out, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800264 }
265
266 // Use legacy /vendor/manifest.xml
Yifan Hong9f78c182018-07-12 14:45:52 -0700267 return out->fetchAllInformation(mFileSystem.get(), kVendorLegacyManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800268}
269
Yifan Hong12a11ac2018-01-19 13:58:32 -0800270// "out" is written to iff return status is OK.
271// Priority:
272// 1. if {sku} is defined, /odm/etc/vintf/manifest_{sku}.xml
273// 2. /odm/etc/vintf/manifest.xml
274// 3. if {sku} is defined, /odm/etc/manifest_{sku}.xml
275// 4. /odm/etc/manifest.xml
276// where:
277// {sku} is the value of ro.boot.product.hardware.sku
Yifan Hong9f78c182018-07-12 14:45:52 -0700278status_t VintfObject::fetchOdmHalManifest(HalManifest* out, std::string* error) {
Yifan Hong12a11ac2018-01-19 13:58:32 -0800279 status_t status;
280
Yifan Hong12a11ac2018-01-19 13:58:32 -0800281 std::string productModel;
Yifan Hong9f78c182018-07-12 14:45:52 -0700282 productModel = mPropertyFetcher->getProperty("ro.boot.product.hardware.sku", "");
Yifan Hong12a11ac2018-01-19 13:58:32 -0800283
284 if (!productModel.empty()) {
285 status =
Yifan Hong9f78c182018-07-12 14:45:52 -0700286 fetchOneHalManifest(kOdmVintfDir + "manifest_" + productModel + ".xml", out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800287 if (status == OK || status != NAME_NOT_FOUND) {
288 return status;
289 }
290 }
Yifan Hong12a11ac2018-01-19 13:58:32 -0800291
Yifan Hong9f78c182018-07-12 14:45:52 -0700292 status = fetchOneHalManifest(kOdmManifest, out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800293 if (status == OK || status != NAME_NOT_FOUND) {
294 return status;
295 }
296
Yifan Hong12a11ac2018-01-19 13:58:32 -0800297 if (!productModel.empty()) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700298 status = fetchOneHalManifest(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", out,
Yifan Hong12a11ac2018-01-19 13:58:32 -0800299 error);
300 if (status == OK || status != NAME_NOT_FOUND) {
301 return status;
302 }
303 }
Yifan Hong12a11ac2018-01-19 13:58:32 -0800304
Yifan Hong9f78c182018-07-12 14:45:52 -0700305 status = fetchOneHalManifest(kOdmLegacyManifest, out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800306 if (status == OK || status != NAME_NOT_FOUND) {
307 return status;
308 }
309
310 return NAME_NOT_FOUND;
311}
312
313// Fetch one manifest.xml file. "out" is written to iff return status is OK.
314// Returns NAME_NOT_FOUND if file is missing.
Yifan Hong9f78c182018-07-12 14:45:52 -0700315status_t VintfObject::fetchOneHalManifest(const std::string& path, HalManifest* out,
Yifan Hong12a11ac2018-01-19 13:58:32 -0800316 std::string* error) {
317 HalManifest ret;
Yifan Hong9f78c182018-07-12 14:45:52 -0700318 status_t status = ret.fetchAllInformation(mFileSystem.get(), path, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800319 if (status == OK) {
320 *out = std::move(ret);
321 }
322 return status;
323}
324
Yifan Hong9f78c182018-07-12 14:45:52 -0700325status_t VintfObject::fetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) {
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800326 CompatibilityMatrix etcMatrix;
Yifan Hong9f78c182018-07-12 14:45:52 -0700327 if (etcMatrix.fetchAllInformation(mFileSystem.get(), kVendorMatrix, error) == OK) {
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800328 *out = std::move(etcMatrix);
329 return OK;
330 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700331 return out->fetchAllInformation(mFileSystem.get(), kVendorLegacyMatrix, error);
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800332}
333
Yifan Hong9f78c182018-07-12 14:45:52 -0700334status_t VintfObject::fetchFrameworkHalManifest(HalManifest* out, std::string* error) {
Yifan Hongde6d00e2018-02-27 17:11:28 -0800335 HalManifest etcManifest;
Yifan Hong9f78c182018-07-12 14:45:52 -0700336 if (etcManifest.fetchAllInformation(mFileSystem.get(), kSystemManifest, error) == OK) {
Yifan Hongde6d00e2018-02-27 17:11:28 -0800337 *out = std::move(etcManifest);
Yifan Hong9f78c182018-07-12 14:45:52 -0700338 return addDirectoryManifests(kSystemManifestFragmentDir, out, error);
Yifan Hongde6d00e2018-02-27 17:11:28 -0800339 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700340 return out->fetchAllInformation(mFileSystem.get(), kSystemLegacyManifest, error);
Yifan Hongde6d00e2018-02-27 17:11:28 -0800341}
342
Yifan Hong9f8f6562018-11-06 16:26:20 -0800343static void appendLine(std::string* error, const std::string& message) {
344 if (error != nullptr) {
345 if (!error->empty()) *error += "\n";
346 *error += message;
347 }
348}
349
Yifan Hong9f78c182018-07-12 14:45:52 -0700350std::vector<Named<CompatibilityMatrix>> VintfObject::getAllFrameworkMatrixLevels(
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800351 std::string* error) {
352 std::vector<std::string> fileNames;
353 std::vector<Named<CompatibilityMatrix>> results;
354
Yifan Hong9f78c182018-07-12 14:45:52 -0700355 if (mFileSystem->listFiles(kSystemVintfDir, &fileNames, error) != OK) {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800356 return {};
357 }
358 for (const std::string& fileName : fileNames) {
Yifan Hong270b5652018-01-18 18:46:01 -0800359 std::string path = kSystemVintfDir + fileName;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800360
361 std::string content;
362 std::string fetchError;
Yifan Hong9f78c182018-07-12 14:45:52 -0700363 status_t status = mFileSystem->fetch(path, &content, &fetchError);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800364 if (status != OK) {
Yifan Hong9f8f6562018-11-06 16:26:20 -0800365 appendLine(error, "Framework Matrix: Ignore file " + path + ": " + fetchError);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800366 continue;
367 }
368
369 auto it = results.emplace(results.end());
Yifan Hong9f8f6562018-11-06 16:26:20 -0800370 std::string parseError;
371 if (!gCompatibilityMatrixConverter(&it->object, content, &parseError)) {
372 appendLine(error, "Framework Matrix: Ignore file " + path + ": " + parseError);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800373 results.erase(it);
374 continue;
375 }
376 }
377
378 if (results.empty()) {
379 if (error) {
Yifan Hong9f8f6562018-11-06 16:26:20 -0800380 error->insert(0, "No framework matrices under " + kSystemVintfDir +
381 " can be fetched or parsed.\n");
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800382 }
383 } else {
384 if (error && !error->empty()) {
385 LOG(WARNING) << *error;
386 *error = "";
387 }
388 }
389
390 return results;
391}
392
Yifan Hong1fb004e2017-09-26 15:04:44 -0700393std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache,
394 RuntimeInfo::FetchFlags flags) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700395 return GetInstance()->getRuntimeInfo(skipCache, flags);
396}
397std::shared_ptr<const RuntimeInfo> VintfObject::getRuntimeInfo(bool skipCache,
398 RuntimeInfo::FetchFlags flags) {
399 std::unique_lock<std::mutex> _lock(mDeviceRuntimeInfo.mutex);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700400
401 if (!skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700402 flags &= (~mDeviceRuntimeInfo.fetchedFlags);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700403 }
404
Yifan Hong9f78c182018-07-12 14:45:52 -0700405 if (mDeviceRuntimeInfo.object == nullptr) {
406 mDeviceRuntimeInfo.object = mRuntimeInfoFactory->make_shared();
Yifan Hong1fb004e2017-09-26 15:04:44 -0700407 }
408
Yifan Hong9f78c182018-07-12 14:45:52 -0700409 status_t status = mDeviceRuntimeInfo.object->fetchAllInformation(flags);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700410 if (status != OK) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700411 mDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched"
Yifan Hong1fb004e2017-09-26 15:04:44 -0700412 return nullptr;
413 }
414
Yifan Hong9f78c182018-07-12 14:45:52 -0700415 mDeviceRuntimeInfo.fetchedFlags |= flags;
416 return mDeviceRuntimeInfo.object;
Yifan Hong3daec812017-02-27 18:49:11 -0800417}
418
Yifan Hong143cfe62017-04-13 20:18:01 -0700419namespace details {
420
Yifan Hong143cfe62017-04-13 20:18:01 -0700421enum class ParseStatus {
422 OK,
423 PARSE_ERROR,
424 DUPLICATED_FWK_ENTRY,
425 DUPLICATED_DEV_ENTRY,
426};
427
Yifan Hong9532bd22017-04-14 15:30:52 -0700428static std::string toString(ParseStatus status) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700429 switch(status) {
430 case ParseStatus::OK: return "OK";
431 case ParseStatus::PARSE_ERROR: return "parse error";
432 case ParseStatus::DUPLICATED_FWK_ENTRY: return "duplicated framework";
433 case ParseStatus::DUPLICATED_DEV_ENTRY: return "duplicated device";
434 }
435 return "";
436}
437
438template<typename T>
Yifan Hong9532bd22017-04-14 15:30:52 -0700439static ParseStatus tryParse(const std::string &xml, const XmlConverter<T> &parse,
Yifan Hongfc73edf2017-08-29 11:39:07 -0700440 std::shared_ptr<T> *fwk, std::shared_ptr<T> *dev) {
441 std::shared_ptr<T> ret = std::make_shared<T>();
Yifan Hong94757062018-02-09 16:36:31 -0800442 if (!parse(ret.get(), xml, nullptr /* error */)) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700443 return ParseStatus::PARSE_ERROR;
444 }
445 if (ret->type() == SchemaType::FRAMEWORK) {
446 if (fwk->get() != nullptr) {
447 return ParseStatus::DUPLICATED_FWK_ENTRY;
448 }
449 *fwk = std::move(ret);
450 } else if (ret->type() == SchemaType::DEVICE) {
451 if (dev->get() != nullptr) {
452 return ParseStatus::DUPLICATED_DEV_ENTRY;
453 }
454 *dev = std::move(ret);
455 }
456 return ParseStatus::OK;
457}
458
Yifan Hong878556e2018-07-13 13:45:30 -0700459template <typename T, typename GetFunction>
Yifan Hongaf3713e2018-11-05 13:59:18 -0800460static status_t getMissing(const std::shared_ptr<T>& pkg, std::shared_ptr<const T>* updated,
461 GetFunction getFunction) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700462 if (pkg != nullptr) {
463 *updated = pkg;
464 } else {
Yifan Hong143cfe62017-04-13 20:18:01 -0700465 *updated = getFunction();
466 }
467 return OK;
468}
469
Yifan Hong143cfe62017-04-13 20:18:01 -0700470struct PackageInfo {
471 struct Pair {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700472 std::shared_ptr<HalManifest> manifest;
473 std::shared_ptr<CompatibilityMatrix> matrix;
Yifan Hong143cfe62017-04-13 20:18:01 -0700474 };
475 Pair dev;
476 Pair fwk;
477};
478
479struct UpdatedInfo {
480 struct Pair {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700481 std::shared_ptr<const HalManifest> manifest;
482 std::shared_ptr<const CompatibilityMatrix> matrix;
Yifan Hong143cfe62017-04-13 20:18:01 -0700483 };
484 Pair dev;
485 Pair fwk;
Yifan Hongfc73edf2017-08-29 11:39:07 -0700486 std::shared_ptr<const RuntimeInfo> runtimeInfo;
Yifan Hong143cfe62017-04-13 20:18:01 -0700487};
488
Yifan Hong9f78c182018-07-12 14:45:52 -0700489} // namespace details
490
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700491// Checks given compatibility info against info on the device. If no
492// compatability info is given then the device info will be checked against
493// itself.
Yifan Hongaf3713e2018-11-05 13:59:18 -0800494int32_t VintfObject::checkCompatibility(const std::vector<std::string>& xmls, std::string* error,
495 CheckFlags::Type flags) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700496 status_t status;
497 ParseStatus parseStatus;
498 PackageInfo pkg; // All information from package.
499 UpdatedInfo updated; // All files and runtime info after the update.
500
Yifan Hong143cfe62017-04-13 20:18:01 -0700501 // parse all information from package
502 for (const auto &xml : xmls) {
503 parseStatus = tryParse(xml, gHalManifestConverter, &pkg.fwk.manifest, &pkg.dev.manifest);
504 if (parseStatus == ParseStatus::OK) {
505 continue; // work on next one
506 }
507 if (parseStatus != ParseStatus::PARSE_ERROR) {
Yifan Hong878556e2018-07-13 13:45:30 -0700508 appendLine(error, toString(parseStatus) + " manifest");
Yifan Hong143cfe62017-04-13 20:18:01 -0700509 return ALREADY_EXISTS;
510 }
511 parseStatus = tryParse(xml, gCompatibilityMatrixConverter, &pkg.fwk.matrix, &pkg.dev.matrix);
512 if (parseStatus == ParseStatus::OK) {
513 continue; // work on next one
514 }
515 if (parseStatus != ParseStatus::PARSE_ERROR) {
Yifan Hong878556e2018-07-13 13:45:30 -0700516 appendLine(error, toString(parseStatus) + " matrix");
Yifan Hong143cfe62017-04-13 20:18:01 -0700517 return ALREADY_EXISTS;
518 }
Yifan Hong878556e2018-07-13 13:45:30 -0700519 appendLine(error, toString(parseStatus)); // parse error
Yifan Hong143cfe62017-04-13 20:18:01 -0700520 return BAD_VALUE;
521 }
522
523 // get missing info from device
Yifan Hong8640cd12017-05-17 12:02:28 -0700524 if ((status = getMissing(
Yifan Hongaf3713e2018-11-05 13:59:18 -0800525 pkg.fwk.manifest, &updated.fwk.manifest,
526 std::bind(&VintfObject::getFrameworkHalManifest, this, true /* skipCache */))) != OK) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700527 return status;
528 }
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700529 if ((status = getMissing(
Yifan Hongaf3713e2018-11-05 13:59:18 -0800530 pkg.dev.manifest, &updated.dev.manifest,
531 std::bind(&VintfObject::getDeviceHalManifest, this, true /* skipCache */))) != OK) {
Yifan Hong8640cd12017-05-17 12:02:28 -0700532 return status;
533 }
Yifan Hongaf3713e2018-11-05 13:59:18 -0800534 if ((status = getMissing(pkg.fwk.matrix, &updated.fwk.matrix,
535 std::bind(&VintfObject::getFrameworkCompatibilityMatrix, this,
536 true /* skipCache */))) != OK) {
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700537 return status;
538 }
Yifan Hongaf3713e2018-11-05 13:59:18 -0800539 if ((status = getMissing(pkg.dev.matrix, &updated.dev.matrix,
540 std::bind(&VintfObject::getDeviceCompatibilityMatrix, this,
541 true /* skipCache */))) != OK) {
542 return status;
Yifan Hong8640cd12017-05-17 12:02:28 -0700543 }
544
Yifan Hong072f12d2018-08-08 13:04:51 -0700545 if (flags.isRuntimeInfoEnabled()) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700546 updated.runtimeInfo = getRuntimeInfo(true /* skipCache */);
Yifan Hong69c1b112018-02-27 17:06:00 -0800547 }
Yifan Hong143cfe62017-04-13 20:18:01 -0700548
549 // null checks for files and runtime info after the update
Yifan Hong143cfe62017-04-13 20:18:01 -0700550 if (updated.fwk.manifest == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700551 appendLine(error, "No framework manifest file from device or from update package");
552 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700553 }
554 if (updated.dev.manifest == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700555 appendLine(error, "No device manifest file from device or from update package");
556 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700557 }
558 if (updated.fwk.matrix == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700559 appendLine(error, "No framework matrix file from device or from update package");
560 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700561 }
562 if (updated.dev.matrix == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700563 appendLine(error, "No device matrix file from device or from update package");
564 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700565 }
Yifan Hong69c1b112018-02-27 17:06:00 -0800566
Yifan Hong072f12d2018-08-08 13:04:51 -0700567 if (flags.isRuntimeInfoEnabled()) {
Yifan Hong69c1b112018-02-27 17:06:00 -0800568 if (updated.runtimeInfo == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700569 appendLine(error, "No runtime info from device");
570 status = NO_INIT;
Yifan Hong69c1b112018-02-27 17:06:00 -0800571 }
Yifan Hong143cfe62017-04-13 20:18:01 -0700572 }
Yifan Hong878556e2018-07-13 13:45:30 -0700573 if (status != OK) return status;
Yifan Hong143cfe62017-04-13 20:18:01 -0700574
575 // compatiblity check.
Yifan Hongca386fe2018-02-07 11:29:03 -0800576 if (!updated.dev.manifest->checkCompatibility(*updated.fwk.matrix, error)) {
577 if (error) {
578 error->insert(0,
579 "Device manifest and framework compatibility matrix are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700580 }
Yifan Hongca386fe2018-02-07 11:29:03 -0800581 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700582 }
Yifan Hongca386fe2018-02-07 11:29:03 -0800583 if (!updated.fwk.manifest->checkCompatibility(*updated.dev.matrix, error)) {
584 if (error) {
585 error->insert(0,
586 "Framework manifest and device compatibility matrix are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700587 }
Yifan Hongca386fe2018-02-07 11:29:03 -0800588 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700589 }
Yifan Hong69c1b112018-02-27 17:06:00 -0800590
Yifan Hong072f12d2018-08-08 13:04:51 -0700591 if (flags.isRuntimeInfoEnabled()) {
592 if (!updated.runtimeInfo->checkCompatibility(*updated.fwk.matrix, error, flags)) {
Yifan Hong69c1b112018-02-27 17:06:00 -0800593 if (error) {
594 error->insert(0,
595 "Runtime info and framework compatibility matrix are incompatible: ");
596 }
597 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700598 }
599 }
600
601 return COMPATIBLE;
602}
603
Yifan Hong9f78c182018-07-12 14:45:52 -0700604namespace details {
605
Yifan Hong270b5652018-01-18 18:46:01 -0800606const std::string kSystemVintfDir = "/system/etc/vintf/";
Yifan Hongccbea052018-01-18 18:48:46 -0800607const std::string kVendorVintfDir = "/vendor/etc/vintf/";
Yifan Hong12a11ac2018-01-19 13:58:32 -0800608const std::string kOdmVintfDir = "/odm/etc/vintf/";
Yifan Hong270b5652018-01-18 18:46:01 -0800609
610const std::string kVendorManifest = kVendorVintfDir + "manifest.xml";
Yifan Honga5ddddf2018-01-18 18:50:13 -0800611const std::string kSystemManifest = kSystemVintfDir + "manifest.xml";
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800612const std::string kVendorMatrix = kVendorVintfDir + "compatibility_matrix.xml";
Yifan Hong12a11ac2018-01-19 13:58:32 -0800613const std::string kOdmManifest = kOdmVintfDir + "manifest.xml";
Yifan Hong270b5652018-01-18 18:46:01 -0800614
Steven Morelandeedf2d42018-04-04 16:36:27 -0700615const std::string kVendorManifestFragmentDir = kVendorVintfDir + "manifest/";
616const std::string kSystemManifestFragmentDir = kSystemVintfDir + "manifest/";
617const std::string kOdmManifestFragmentDir = kOdmVintfDir + "manifest/";
618
Yifan Hong270b5652018-01-18 18:46:01 -0800619const std::string kVendorLegacyManifest = "/vendor/manifest.xml";
620const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml";
Yifan Hongde6d00e2018-02-27 17:11:28 -0800621const std::string kSystemLegacyManifest = "/system/manifest.xml";
Yifan Hong270b5652018-01-18 18:46:01 -0800622const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml";
623const std::string kOdmLegacyVintfDir = "/odm/etc/";
624const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml";
625
Yifan Hong69c1b112018-02-27 17:06:00 -0800626std::vector<std::string> dumpFileList() {
627 return {
628 kSystemVintfDir, kVendorVintfDir, kOdmVintfDir, kOdmLegacyVintfDir,
629
630 kVendorLegacyManifest, kVendorLegacyMatrix, kSystemLegacyManifest, kSystemLegacyMatrix,
631 };
632}
633
Yifan Hong9f78c182018-07-12 14:45:52 -0700634} // namespace details
Yifan Hong143cfe62017-04-13 20:18:01 -0700635
Yifan Hongdb6423e2017-09-11 14:38:46 -0700636int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error,
Yifan Hong072f12d2018-08-08 13:04:51 -0700637 CheckFlags::Type flags) {
638 return GetInstance()->checkCompatibility(xmls, error, flags);
Yifan Hongfbbf0472017-04-07 18:14:18 -0700639}
640
Yifan Hong9f78c182018-07-12 14:45:52 -0700641bool VintfObject::IsHalDeprecated(const MatrixHal& oldMatrixHal,
Yifan Hongf73ba512018-01-17 15:52:30 -0800642 const CompatibilityMatrix& targetMatrix,
Yifan Honga8a8fa92018-03-20 14:42:43 -0700643 const ListInstances& listInstances, std::string* error) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700644 bool isDeprecated = false;
645 oldMatrixHal.forEachInstance([&](const MatrixInstance& oldMatrixInstance) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700646 if (IsInstanceDeprecated(oldMatrixInstance, targetMatrix, listInstances, error)) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700647 isDeprecated = true;
Yifan Hongf73ba512018-01-17 15:52:30 -0800648 }
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700649 return !isDeprecated; // continue if no deprecated instance is found.
650 });
651 return isDeprecated;
Yifan Hongf73ba512018-01-17 15:52:30 -0800652}
653
Yifan Honga8a8fa92018-03-20 14:42:43 -0700654// Let oldMatrixInstance = package@x.y-w::interface with instancePattern.
655// If any "servedInstance" in listInstances(package@x.y::interface) matches instancePattern, return
656// true iff:
657// 1. package@x.?::interface/servedInstance is not in targetMatrix; OR
658// 2. package@x.z::interface/servedInstance is in targetMatrix but
659// servedInstance is not in listInstances(package@x.z::interface)
Yifan Hong9f78c182018-07-12 14:45:52 -0700660bool VintfObject::IsInstanceDeprecated(const MatrixInstance& oldMatrixInstance,
Yifan Hongf73ba512018-01-17 15:52:30 -0800661 const CompatibilityMatrix& targetMatrix,
Yifan Honga8a8fa92018-03-20 14:42:43 -0700662 const ListInstances& listInstances, std::string* error) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700663 const std::string& package = oldMatrixInstance.package();
664 const Version& version = oldMatrixInstance.versionRange().minVer();
665 const std::string& interface = oldMatrixInstance.interface();
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700666
Yifan Honga8a8fa92018-03-20 14:42:43 -0700667 std::vector<std::string> instanceHint;
668 if (!oldMatrixInstance.isRegex()) {
669 instanceHint.push_back(oldMatrixInstance.exactInstance());
670 }
671
672 auto list = listInstances(package, version, interface, instanceHint);
673 for (const auto& pair : list) {
674 const std::string& servedInstance = pair.first;
675 Version servedVersion = pair.second;
676 if (!oldMatrixInstance.matchInstance(servedInstance)) {
677 continue;
678 }
679
Yifan Hongf73ba512018-01-17 15:52:30 -0800680 // Find any package@x.? in target matrix, and check if instance is in target matrix.
Yifan Hong217f47e2018-03-15 12:34:05 -0700681 bool foundInstance = false;
682 Version targetMatrixMinVer;
683 targetMatrix.forEachInstanceOfPackage(package, [&](const auto& targetMatrixInstance) {
684 if (targetMatrixInstance.versionRange().majorVer == version.majorVer &&
685 targetMatrixInstance.interface() == interface &&
Yifan Honga8a8fa92018-03-20 14:42:43 -0700686 targetMatrixInstance.matchInstance(servedInstance)) {
Yifan Hong217f47e2018-03-15 12:34:05 -0700687 targetMatrixMinVer = targetMatrixInstance.versionRange().minVer();
688 foundInstance = true;
689 }
690 return !foundInstance; // continue if not found
691 });
692 if (!foundInstance) {
Yifan Hongf73ba512018-01-17 15:52:30 -0800693 if (error) {
Yifan Honga8a8fa92018-03-20 14:42:43 -0700694 *error = toFQNameString(package, servedVersion, interface, servedInstance) +
Steven Morelanda1b984c2018-03-09 13:09:15 -0800695 " is deprecated in compatibility matrix at FCM Version " +
Yifan Hongf73ba512018-01-17 15:52:30 -0800696 to_string(targetMatrix.level()) + "; it should not be served.";
697 }
698 return true;
699 }
700
Yifan Hongf73ba512018-01-17 15:52:30 -0800701 // Assuming that targetMatrix requires @x.u-v, require that at least @x.u is served.
Yifan Honga8a8fa92018-03-20 14:42:43 -0700702 bool targetVersionServed = false;
703 for (const auto& newPair :
704 listInstances(package, targetMatrixMinVer, interface, instanceHint)) {
705 if (newPair.first == servedInstance) {
706 targetVersionServed = true;
707 break;
708 }
709 }
Yifan Hongf73ba512018-01-17 15:52:30 -0800710
711 if (!targetVersionServed) {
Yifan Hong9f8f6562018-11-06 16:26:20 -0800712 appendLine(error, toFQNameString(package, servedVersion, interface, servedInstance) +
713 " is deprecated; requires at least " +
714 to_string(targetMatrixMinVer));
Yifan Hongf73ba512018-01-17 15:52:30 -0800715 return true;
716 }
717 }
Yifan Honga8a8fa92018-03-20 14:42:43 -0700718
Yifan Hongf73ba512018-01-17 15:52:30 -0800719 return false;
720}
721
Yifan Honga8a8fa92018-03-20 14:42:43 -0700722int32_t VintfObject::CheckDeprecation(const ListInstances& listInstances, std::string* error) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700723 return GetInstance()->checkDeprecation(listInstances, error);
724}
725int32_t VintfObject::checkDeprecation(const ListInstances& listInstances, std::string* error) {
726 auto matrixFragments = getAllFrameworkMatrixLevels(error);
Yifan Hongf73ba512018-01-17 15:52:30 -0800727 if (matrixFragments.empty()) {
728 if (error && error->empty())
729 *error = "Cannot get framework matrix for each FCM version for unknown error.";
730 return NAME_NOT_FOUND;
731 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700732 auto deviceManifest = getDeviceHalManifest();
Yifan Hongf73ba512018-01-17 15:52:30 -0800733 if (deviceManifest == nullptr) {
734 if (error) *error = "No device manifest.";
735 return NAME_NOT_FOUND;
736 }
737 Level deviceLevel = deviceManifest->level();
738 if (deviceLevel == Level::UNSPECIFIED) {
739 if (error) *error = "Device manifest does not specify Shipping FCM Version.";
740 return BAD_VALUE;
741 }
742
743 const CompatibilityMatrix* targetMatrix = nullptr;
744 for (const auto& namedMatrix : matrixFragments) {
745 if (namedMatrix.object.level() == deviceLevel) {
746 targetMatrix = &namedMatrix.object;
747 }
748 }
749 if (targetMatrix == nullptr) {
750 if (error)
751 *error = "Cannot find framework matrix at FCM version " + to_string(deviceLevel) + ".";
752 return NAME_NOT_FOUND;
753 }
754
755 bool hasDeprecatedHals = false;
756 for (const auto& namedMatrix : matrixFragments) {
757 if (namedMatrix.object.level() == Level::UNSPECIFIED) continue;
758 if (namedMatrix.object.level() >= deviceLevel) continue;
759
760 const auto& oldMatrix = namedMatrix.object;
761 for (const MatrixHal& hal : oldMatrix.getHals()) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700762 hasDeprecatedHals |= IsHalDeprecated(hal, *targetMatrix, listInstances, error);
Yifan Hongf73ba512018-01-17 15:52:30 -0800763 }
764 }
765
766 return hasDeprecatedHals ? DEPRECATED : NO_DEPRECATED_HALS;
767}
768
769int32_t VintfObject::CheckDeprecation(std::string* error) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700770 return GetInstance()->checkDeprecation(error);
771}
772int32_t VintfObject::checkDeprecation(std::string* error) {
Yifan Hong2a90ffe2018-03-05 17:45:34 -0800773 using namespace std::placeholders;
Yifan Hong9f78c182018-07-12 14:45:52 -0700774 auto deviceManifest = getDeviceHalManifest();
Yifan Honga8a8fa92018-03-20 14:42:43 -0700775 ListInstances inManifest =
776 [&deviceManifest](const std::string& package, Version version, const std::string& interface,
777 const std::vector<std::string>& /* hintInstances */) {
778 std::vector<std::pair<std::string, Version>> ret;
779 deviceManifest->forEachInstanceOfInterface(
780 package, version, interface, [&ret](const ManifestInstance& manifestInstance) {
781 ret.push_back(
782 std::make_pair(manifestInstance.instance(), manifestInstance.version()));
783 return true;
784 });
785 return ret;
786 };
Yifan Hong9f78c182018-07-12 14:45:52 -0700787 return checkDeprecation(inManifest, error);
Yifan Hongf73ba512018-01-17 15:52:30 -0800788}
Yifan Hong3daec812017-02-27 18:49:11 -0800789
Yifan Hong9f78c182018-07-12 14:45:52 -0700790const std::unique_ptr<FileSystem>& VintfObject::getFileSystem() {
791 return mFileSystem;
792}
793
Yifan Hong9f78c182018-07-12 14:45:52 -0700794const std::unique_ptr<PropertyFetcher>& VintfObject::getPropertyFetcher() {
795 return mPropertyFetcher;
796}
797
798const std::unique_ptr<details::ObjectFactory<RuntimeInfo>>& VintfObject::getRuntimeInfoFactory() {
799 return mRuntimeInfoFactory;
Yifan Hong10d86222018-04-06 15:41:05 -0700800}
801
Yifan Hong3daec812017-02-27 18:49:11 -0800802} // namespace vintf
803} // namespace android