blob: c34f0bb51970bcb6ae46b6a586f3262f2546fd6c [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,
85 std::unique_ptr<details::PartitionMounter>&& partitionMounter,
86 std::unique_ptr<details::ObjectFactory<RuntimeInfo>>&& runtimeInfoFactory,
87 std::unique_ptr<details::PropertyFetcher>&& propertyFetcher)
88 : mFileSystem(fileSystem ? std::move(fileSystem) : createDefaultFileSystem()),
89 mPartitionMounter(partitionMounter ? std::move(partitionMounter)
90 : std::make_unique<details::PartitionMounter>()),
91 mRuntimeInfoFactory(runtimeInfoFactory
92 ? std::move(runtimeInfoFactory)
93 : std::make_unique<details::ObjectFactory<RuntimeInfo>>()),
94 mPropertyFetcher(propertyFetcher ? std::move(propertyFetcher)
95 : createDefaultPropertyFetcher()) {}
96
97details::LockedSharedPtr<VintfObject> VintfObject::sInstance{};
98std::shared_ptr<VintfObject> VintfObject::GetInstance() {
99 std::unique_lock<std::mutex> lock(sInstance.mutex);
100 if (sInstance.object == nullptr) {
101 sInstance.object = std::make_shared<VintfObject>();
102 }
103 return sInstance.object;
104}
105
Yifan Hongfc73edf2017-08-29 11:39:07 -0700106std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700107 return GetInstance()->getDeviceHalManifest(skipCache);
Yifan Hong3daec812017-02-27 18:49:11 -0800108}
109
Yifan Hong9f78c182018-07-12 14:45:52 -0700110std::shared_ptr<const HalManifest> VintfObject::getDeviceHalManifest(bool skipCache) {
111 return Get(&mDeviceManifest, skipCache,
112 std::bind(&VintfObject::fetchDeviceHalManifest, this, _1, _2));
113}
114
Yifan Hongfc73edf2017-08-29 11:39:07 -0700115std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700116 return GetInstance()->getFrameworkHalManifest(skipCache);
Yifan Hong3daec812017-02-27 18:49:11 -0800117}
118
Yifan Hong9f78c182018-07-12 14:45:52 -0700119std::shared_ptr<const HalManifest> VintfObject::getFrameworkHalManifest(bool skipCache) {
120 return Get(&mFrameworkManifest, skipCache,
121 std::bind(&VintfObject::fetchFrameworkHalManifest, this, _1, _2));
122}
Yifan Hong2272bf82017-04-28 14:37:56 -0700123
Yifan Hongfc73edf2017-08-29 11:39:07 -0700124std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700125 return GetInstance()->getDeviceCompatibilityMatrix(skipCache);
Yifan Hong2272bf82017-04-28 14:37:56 -0700126}
127
Yifan Hong9f78c182018-07-12 14:45:52 -0700128std::shared_ptr<const CompatibilityMatrix> VintfObject::getDeviceCompatibilityMatrix(
129 bool skipCache) {
130 return Get(&mDeviceMatrix, skipCache, std::bind(&VintfObject::fetchDeviceMatrix, this, _1, _2));
131}
132
Yifan Hongfc73edf2017-08-29 11:39:07 -0700133std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700134 return GetInstance()->getFrameworkCompatibilityMatrix(skipCache);
135}
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800136
Yifan Hong9f78c182018-07-12 14:45:52 -0700137std::shared_ptr<const CompatibilityMatrix> VintfObject::getFrameworkCompatibilityMatrix(
138 bool skipCache) {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800139 // To avoid deadlock, get device manifest before any locks.
Yifan Hong9f78c182018-07-12 14:45:52 -0700140 auto deviceManifest = getDeviceHalManifest();
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800141
Yifan Hong9f78c182018-07-12 14:45:52 -0700142 std::unique_lock<std::mutex> _lock(mFrameworkCompatibilityMatrixMutex);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800143
144 auto combined =
Yifan Hong9f78c182018-07-12 14:45:52 -0700145 Get(&mCombinedFrameworkMatrix, skipCache,
146 std::bind(&VintfObject::getCombinedFrameworkMatrix, this, deviceManifest, _1, _2));
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800147 if (combined != nullptr) {
148 return combined;
149 }
150
Yifan Hong9f78c182018-07-12 14:45:52 -0700151 return Get(&mFrameworkMatrix, skipCache,
152 std::bind(&CompatibilityMatrix::fetchAllInformation, _1, mFileSystem.get(),
153 kSystemLegacyMatrix, _2));
Yifan Hong2272bf82017-04-28 14:37:56 -0700154}
155
Yifan Hong9f78c182018-07-12 14:45:52 -0700156status_t VintfObject::getCombinedFrameworkMatrix(
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800157 const std::shared_ptr<const HalManifest>& deviceManifest, CompatibilityMatrix* out,
158 std::string* error) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700159 auto matrixFragments = getAllFrameworkMatrixLevels(error);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800160 if (matrixFragments.empty()) {
161 return NAME_NOT_FOUND;
162 }
163
164 Level deviceLevel = Level::UNSPECIFIED;
165
166 if (deviceManifest != nullptr) {
167 deviceLevel = deviceManifest->level();
168 }
169
170 // TODO(b/70628538): Do not infer from Shipping API level.
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800171 if (deviceLevel == Level::UNSPECIFIED) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700172 auto shippingApi = mPropertyFetcher->getUintProperty("ro.product.first_api_level", 0u);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800173 if (shippingApi != 0u) {
174 deviceLevel = details::convertFromApiLevel(shippingApi);
175 }
176 }
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800177
178 if (deviceLevel == Level::UNSPECIFIED) {
179 // Cannot infer FCM version. Combine all matrices by assuming
180 // Shipping FCM Version == min(all supported FCM Versions in the framework)
181 for (auto&& pair : matrixFragments) {
182 Level fragmentLevel = pair.object.level();
183 if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) {
184 deviceLevel = fragmentLevel;
185 }
186 }
187 }
188
189 if (deviceLevel == Level::UNSPECIFIED) {
190 // None of the fragments specify any FCM version. Should never happen except
191 // for inconsistent builds.
192 if (error) {
Yifan Hong270b5652018-01-18 18:46:01 -0800193 *error = "No framework compatibility matrix files under " + kSystemVintfDir +
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800194 " declare FCM version.";
195 }
196 return NAME_NOT_FOUND;
197 }
198
199 CompatibilityMatrix* combined =
200 CompatibilityMatrix::combine(deviceLevel, &matrixFragments, error);
201 if (combined == nullptr) {
202 return BAD_VALUE;
203 }
204 *out = std::move(*combined);
205 return OK;
206}
207
Steven Morelandeedf2d42018-04-04 16:36:27 -0700208// Load and combine all of the manifests in a directory
Yifan Hong9f78c182018-07-12 14:45:52 -0700209status_t VintfObject::addDirectoryManifests(const std::string& directory, HalManifest* manifest,
Steven Morelandeedf2d42018-04-04 16:36:27 -0700210 std::string* error) {
211 std::vector<std::string> fileNames;
Yifan Hong9f78c182018-07-12 14:45:52 -0700212 status_t err = mFileSystem->listFiles(directory, &fileNames, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700213 // if the directory isn't there, that's okay
214 if (err == NAME_NOT_FOUND) return OK;
215 if (err != OK) return err;
216
217 for (const std::string& file : fileNames) {
218 // Only adds HALs because all other things are added by libvintf
219 // itself for now.
220 HalManifest fragmentManifest;
Yifan Hong9f78c182018-07-12 14:45:52 -0700221 err = fetchOneHalManifest(directory + file, &fragmentManifest, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700222 if (err != OK) return err;
223
224 manifest->addAllHals(&fragmentManifest);
225 }
226
227 return OK;
228}
229
Yifan Hong5a93bf22018-01-17 18:22:32 -0800230// Priority for loading vendor manifest:
Steven Morelandeedf2d42018-04-04 16:36:27 -0700231// 1. /vendor/etc/vintf/manifest.xml + device fragments + ODM manifest (optional) + odm fragments
232// 2. /vendor/etc/vintf/manifest.xml + device fragments
233// 3. ODM manifest (optional) + odm fragments
234// 4. /vendor/manifest.xml (legacy, no fragments)
Yifan Hong5a93bf22018-01-17 18:22:32 -0800235// where:
Yifan Hong5a93bf22018-01-17 18:22:32 -0800236// A + B means adding <hal> tags from B to A (so that <hal>s from B can override A)
Yifan Hong9f78c182018-07-12 14:45:52 -0700237status_t VintfObject::fetchDeviceHalManifest(HalManifest* out, std::string* error) {
238 status_t vendorStatus = fetchOneHalManifest(kVendorManifest, out, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800239 if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) {
240 return vendorStatus;
241 }
242
Steven Morelandeedf2d42018-04-04 16:36:27 -0700243 if (vendorStatus == OK) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700244 status_t fragmentStatus = addDirectoryManifests(kVendorManifestFragmentDir, out, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700245 if (fragmentStatus != OK) {
246 return fragmentStatus;
247 }
248 }
249
Yifan Hong5a93bf22018-01-17 18:22:32 -0800250 HalManifest odmManifest;
Yifan Hong9f78c182018-07-12 14:45:52 -0700251 status_t odmStatus = fetchOdmHalManifest(&odmManifest, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800252 if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
253 return odmStatus;
Yifan Hong5a93bf22018-01-17 18:22:32 -0800254 }
255
Yifan Hong5a93bf22018-01-17 18:22:32 -0800256 if (vendorStatus == OK) {
Yifan Hong12a11ac2018-01-19 13:58:32 -0800257 if (odmStatus == OK) {
258 out->addAllHals(&odmManifest);
259 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700260 return addDirectoryManifests(kOdmManifestFragmentDir, out, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800261 }
262
Yifan Hong12a11ac2018-01-19 13:58:32 -0800263 // vendorStatus != OK, "out" is not changed.
Yifan Hong5a93bf22018-01-17 18:22:32 -0800264 if (odmStatus == OK) {
265 *out = std::move(odmManifest);
Yifan Hong9f78c182018-07-12 14:45:52 -0700266 return addDirectoryManifests(kOdmManifestFragmentDir, out, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800267 }
268
269 // Use legacy /vendor/manifest.xml
Yifan Hong9f78c182018-07-12 14:45:52 -0700270 return out->fetchAllInformation(mFileSystem.get(), kVendorLegacyManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800271}
272
Yifan Hong12a11ac2018-01-19 13:58:32 -0800273// "out" is written to iff return status is OK.
274// Priority:
275// 1. if {sku} is defined, /odm/etc/vintf/manifest_{sku}.xml
276// 2. /odm/etc/vintf/manifest.xml
277// 3. if {sku} is defined, /odm/etc/manifest_{sku}.xml
278// 4. /odm/etc/manifest.xml
279// where:
280// {sku} is the value of ro.boot.product.hardware.sku
Yifan Hong9f78c182018-07-12 14:45:52 -0700281status_t VintfObject::fetchOdmHalManifest(HalManifest* out, std::string* error) {
Yifan Hong12a11ac2018-01-19 13:58:32 -0800282 status_t status;
283
Yifan Hong12a11ac2018-01-19 13:58:32 -0800284 std::string productModel;
Yifan Hong9f78c182018-07-12 14:45:52 -0700285 productModel = mPropertyFetcher->getProperty("ro.boot.product.hardware.sku", "");
Yifan Hong12a11ac2018-01-19 13:58:32 -0800286
287 if (!productModel.empty()) {
288 status =
Yifan Hong9f78c182018-07-12 14:45:52 -0700289 fetchOneHalManifest(kOdmVintfDir + "manifest_" + productModel + ".xml", out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800290 if (status == OK || status != NAME_NOT_FOUND) {
291 return status;
292 }
293 }
Yifan Hong12a11ac2018-01-19 13:58:32 -0800294
Yifan Hong9f78c182018-07-12 14:45:52 -0700295 status = fetchOneHalManifest(kOdmManifest, out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800296 if (status == OK || status != NAME_NOT_FOUND) {
297 return status;
298 }
299
Yifan Hong12a11ac2018-01-19 13:58:32 -0800300 if (!productModel.empty()) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700301 status = fetchOneHalManifest(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", out,
Yifan Hong12a11ac2018-01-19 13:58:32 -0800302 error);
303 if (status == OK || status != NAME_NOT_FOUND) {
304 return status;
305 }
306 }
Yifan Hong12a11ac2018-01-19 13:58:32 -0800307
Yifan Hong9f78c182018-07-12 14:45:52 -0700308 status = fetchOneHalManifest(kOdmLegacyManifest, out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800309 if (status == OK || status != NAME_NOT_FOUND) {
310 return status;
311 }
312
313 return NAME_NOT_FOUND;
314}
315
316// Fetch one manifest.xml file. "out" is written to iff return status is OK.
317// Returns NAME_NOT_FOUND if file is missing.
Yifan Hong9f78c182018-07-12 14:45:52 -0700318status_t VintfObject::fetchOneHalManifest(const std::string& path, HalManifest* out,
Yifan Hong12a11ac2018-01-19 13:58:32 -0800319 std::string* error) {
320 HalManifest ret;
Yifan Hong9f78c182018-07-12 14:45:52 -0700321 status_t status = ret.fetchAllInformation(mFileSystem.get(), path, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800322 if (status == OK) {
323 *out = std::move(ret);
324 }
325 return status;
326}
327
Yifan Hong9f78c182018-07-12 14:45:52 -0700328status_t VintfObject::fetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) {
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800329 CompatibilityMatrix etcMatrix;
Yifan Hong9f78c182018-07-12 14:45:52 -0700330 if (etcMatrix.fetchAllInformation(mFileSystem.get(), kVendorMatrix, error) == OK) {
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800331 *out = std::move(etcMatrix);
332 return OK;
333 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700334 return out->fetchAllInformation(mFileSystem.get(), kVendorLegacyMatrix, error);
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800335}
336
Yifan Hong9f78c182018-07-12 14:45:52 -0700337status_t VintfObject::fetchFrameworkHalManifest(HalManifest* out, std::string* error) {
Yifan Hongde6d00e2018-02-27 17:11:28 -0800338 HalManifest etcManifest;
Yifan Hong9f78c182018-07-12 14:45:52 -0700339 if (etcManifest.fetchAllInformation(mFileSystem.get(), kSystemManifest, error) == OK) {
Yifan Hongde6d00e2018-02-27 17:11:28 -0800340 *out = std::move(etcManifest);
Yifan Hong9f78c182018-07-12 14:45:52 -0700341 return addDirectoryManifests(kSystemManifestFragmentDir, out, error);
Yifan Hongde6d00e2018-02-27 17:11:28 -0800342 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700343 return out->fetchAllInformation(mFileSystem.get(), kSystemLegacyManifest, error);
Yifan Hongde6d00e2018-02-27 17:11:28 -0800344}
345
Yifan Hong9f78c182018-07-12 14:45:52 -0700346std::vector<Named<CompatibilityMatrix>> VintfObject::getAllFrameworkMatrixLevels(
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800347 std::string* error) {
348 std::vector<std::string> fileNames;
349 std::vector<Named<CompatibilityMatrix>> results;
350
Yifan Hong9f78c182018-07-12 14:45:52 -0700351 if (mFileSystem->listFiles(kSystemVintfDir, &fileNames, error) != OK) {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800352 return {};
353 }
354 for (const std::string& fileName : fileNames) {
Yifan Hong270b5652018-01-18 18:46:01 -0800355 std::string path = kSystemVintfDir + fileName;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800356
357 std::string content;
358 std::string fetchError;
Yifan Hong9f78c182018-07-12 14:45:52 -0700359 status_t status = mFileSystem->fetch(path, &content, &fetchError);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800360 if (status != OK) {
361 if (error) {
Yifan Hong69c1b112018-02-27 17:06:00 -0800362 *error += "Framework Matrix: Ignore file " + path + ": " + fetchError + "\n";
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800363 }
364 continue;
365 }
366
367 auto it = results.emplace(results.end());
Yifan Hong94757062018-02-09 16:36:31 -0800368 if (!gCompatibilityMatrixConverter(&it->object, content, error)) {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800369 if (error) {
Yifan Hong69c1b112018-02-27 17:06:00 -0800370 *error += "Framework Matrix: Ignore file " + path + ": " + *error + "\n";
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800371 }
372 results.erase(it);
373 continue;
374 }
375 }
376
377 if (results.empty()) {
378 if (error) {
Yifan Hong270b5652018-01-18 18:46:01 -0800379 *error = "No framework matrices under " + kSystemVintfDir +
380 " can be fetched or parsed.\n" + *error;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800381 }
382 } else {
383 if (error && !error->empty()) {
384 LOG(WARNING) << *error;
385 *error = "";
386 }
387 }
388
389 return results;
390}
391
Yifan Hong1fb004e2017-09-26 15:04:44 -0700392std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache,
393 RuntimeInfo::FetchFlags flags) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700394 return GetInstance()->getRuntimeInfo(skipCache, flags);
395}
396std::shared_ptr<const RuntimeInfo> VintfObject::getRuntimeInfo(bool skipCache,
397 RuntimeInfo::FetchFlags flags) {
398 std::unique_lock<std::mutex> _lock(mDeviceRuntimeInfo.mutex);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700399
400 if (!skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700401 flags &= (~mDeviceRuntimeInfo.fetchedFlags);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700402 }
403
Yifan Hong9f78c182018-07-12 14:45:52 -0700404 if (mDeviceRuntimeInfo.object == nullptr) {
405 mDeviceRuntimeInfo.object = mRuntimeInfoFactory->make_shared();
Yifan Hong1fb004e2017-09-26 15:04:44 -0700406 }
407
Yifan Hong9f78c182018-07-12 14:45:52 -0700408 status_t status = mDeviceRuntimeInfo.object->fetchAllInformation(flags);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700409 if (status != OK) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700410 mDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched"
Yifan Hong1fb004e2017-09-26 15:04:44 -0700411 return nullptr;
412 }
413
Yifan Hong9f78c182018-07-12 14:45:52 -0700414 mDeviceRuntimeInfo.fetchedFlags |= flags;
415 return mDeviceRuntimeInfo.object;
Yifan Hong3daec812017-02-27 18:49:11 -0800416}
417
Yifan Hong143cfe62017-04-13 20:18:01 -0700418namespace details {
419
Yifan Hong143cfe62017-04-13 20:18:01 -0700420enum class ParseStatus {
421 OK,
422 PARSE_ERROR,
423 DUPLICATED_FWK_ENTRY,
424 DUPLICATED_DEV_ENTRY,
425};
426
Yifan Hong9532bd22017-04-14 15:30:52 -0700427static std::string toString(ParseStatus status) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700428 switch(status) {
429 case ParseStatus::OK: return "OK";
430 case ParseStatus::PARSE_ERROR: return "parse error";
431 case ParseStatus::DUPLICATED_FWK_ENTRY: return "duplicated framework";
432 case ParseStatus::DUPLICATED_DEV_ENTRY: return "duplicated device";
433 }
434 return "";
435}
436
437template<typename T>
Yifan Hong9532bd22017-04-14 15:30:52 -0700438static ParseStatus tryParse(const std::string &xml, const XmlConverter<T> &parse,
Yifan Hongfc73edf2017-08-29 11:39:07 -0700439 std::shared_ptr<T> *fwk, std::shared_ptr<T> *dev) {
440 std::shared_ptr<T> ret = std::make_shared<T>();
Yifan Hong94757062018-02-09 16:36:31 -0800441 if (!parse(ret.get(), xml, nullptr /* error */)) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700442 return ParseStatus::PARSE_ERROR;
443 }
444 if (ret->type() == SchemaType::FRAMEWORK) {
445 if (fwk->get() != nullptr) {
446 return ParseStatus::DUPLICATED_FWK_ENTRY;
447 }
448 *fwk = std::move(ret);
449 } else if (ret->type() == SchemaType::DEVICE) {
450 if (dev->get() != nullptr) {
451 return ParseStatus::DUPLICATED_DEV_ENTRY;
452 }
453 *dev = std::move(ret);
454 }
455 return ParseStatus::OK;
456}
457
458template<typename T, typename GetFunction>
Yifan Hongfc73edf2017-08-29 11:39:07 -0700459static status_t getMissing(const std::shared_ptr<T>& pkg, bool mount,
Yifan Hong143cfe62017-04-13 20:18:01 -0700460 std::function<status_t(void)> mountFunction,
Yifan Hongfc73edf2017-08-29 11:39:07 -0700461 std::shared_ptr<const T>* updated,
Yifan Hong143cfe62017-04-13 20:18:01 -0700462 GetFunction getFunction) {
463 if (pkg != nullptr) {
464 *updated = pkg;
465 } else {
466 if (mount) {
467 (void)mountFunction(); // ignore mount errors
468 }
469 *updated = getFunction();
470 }
471 return OK;
472}
473
474#define ADD_MESSAGE(__error__) \
475 if (error != nullptr) { \
476 *error += (__error__); \
477 } \
478
479struct PackageInfo {
480 struct Pair {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700481 std::shared_ptr<HalManifest> manifest;
482 std::shared_ptr<CompatibilityMatrix> matrix;
Yifan Hong143cfe62017-04-13 20:18:01 -0700483 };
484 Pair dev;
485 Pair fwk;
486};
487
488struct UpdatedInfo {
489 struct Pair {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700490 std::shared_ptr<const HalManifest> manifest;
491 std::shared_ptr<const CompatibilityMatrix> matrix;
Yifan Hong143cfe62017-04-13 20:18:01 -0700492 };
493 Pair dev;
494 Pair fwk;
Yifan Hongfc73edf2017-08-29 11:39:07 -0700495 std::shared_ptr<const RuntimeInfo> runtimeInfo;
Yifan Hong143cfe62017-04-13 20:18:01 -0700496};
497
Yifan Hong9f78c182018-07-12 14:45:52 -0700498} // namespace details
499
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700500// Checks given compatibility info against info on the device. If no
501// compatability info is given then the device info will be checked against
502// itself.
Yifan Hong9f78c182018-07-12 14:45:52 -0700503int32_t VintfObject::checkCompatibility(const std::vector<std::string>& xmls, bool mount,
504 std::string* error, DisabledChecks disabledChecks) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700505 status_t status;
506 ParseStatus parseStatus;
507 PackageInfo pkg; // All information from package.
508 UpdatedInfo updated; // All files and runtime info after the update.
509
Yifan Hong143cfe62017-04-13 20:18:01 -0700510 // parse all information from package
511 for (const auto &xml : xmls) {
512 parseStatus = tryParse(xml, gHalManifestConverter, &pkg.fwk.manifest, &pkg.dev.manifest);
513 if (parseStatus == ParseStatus::OK) {
514 continue; // work on next one
515 }
516 if (parseStatus != ParseStatus::PARSE_ERROR) {
517 ADD_MESSAGE(toString(parseStatus) + " manifest");
518 return ALREADY_EXISTS;
519 }
520 parseStatus = tryParse(xml, gCompatibilityMatrixConverter, &pkg.fwk.matrix, &pkg.dev.matrix);
521 if (parseStatus == ParseStatus::OK) {
522 continue; // work on next one
523 }
524 if (parseStatus != ParseStatus::PARSE_ERROR) {
525 ADD_MESSAGE(toString(parseStatus) + " matrix");
526 return ALREADY_EXISTS;
527 }
528 ADD_MESSAGE(toString(parseStatus)); // parse error
529 return BAD_VALUE;
530 }
531
532 // get missing info from device
Yifan Hong8640cd12017-05-17 12:02:28 -0700533 // use functions instead of std::bind because std::bind doesn't work well with mock objects
Yifan Hong9f78c182018-07-12 14:45:52 -0700534 auto mountSystem = [this] { return this->mPartitionMounter->mountSystem(); };
535 auto mountVendor = [this] { return this->mPartitionMounter->mountVendor(); };
Yifan Hong8640cd12017-05-17 12:02:28 -0700536 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700537 pkg.fwk.manifest, mount, mountSystem, &updated.fwk.manifest,
Yifan Hong9f78c182018-07-12 14:45:52 -0700538 std::bind(&VintfObject::getFrameworkHalManifest, this, true /* skipCache */))) != OK) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700539 return status;
540 }
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700541 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700542 pkg.dev.manifest, mount, mountVendor, &updated.dev.manifest,
Yifan Hong9f78c182018-07-12 14:45:52 -0700543 std::bind(&VintfObject::getDeviceHalManifest, this, true /* skipCache */))) != OK) {
Yifan Hong8640cd12017-05-17 12:02:28 -0700544 return status;
545 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700546 if ((status = getMissing(pkg.fwk.matrix, mount, mountSystem, &updated.fwk.matrix,
547 std::bind(&VintfObject::getFrameworkCompatibilityMatrix, this,
548 true /* skipCache */))) != OK) {
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700549 return status;
550 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700551 if ((status = getMissing(pkg.dev.matrix, mount, mountVendor, &updated.dev.matrix,
552 std::bind(&VintfObject::getDeviceCompatibilityMatrix, this,
553 true /* skipCache */))) != OK) {
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700554 return status;
555 }
Yifan Hong8640cd12017-05-17 12:02:28 -0700556
557 if (mount) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700558 (void)mPartitionMounter->umountSystem(); // ignore errors
559 (void)mPartitionMounter->umountVendor(); // ignore errors
Yifan Hong8640cd12017-05-17 12:02:28 -0700560 }
561
Yifan Hong69c1b112018-02-27 17:06:00 -0800562 if ((disabledChecks & DISABLE_RUNTIME_INFO) == 0) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700563 updated.runtimeInfo = getRuntimeInfo(true /* skipCache */);
Yifan Hong69c1b112018-02-27 17:06:00 -0800564 }
Yifan Hong143cfe62017-04-13 20:18:01 -0700565
566 // null checks for files and runtime info after the update
Yifan Hong143cfe62017-04-13 20:18:01 -0700567 if (updated.fwk.manifest == nullptr) {
568 ADD_MESSAGE("No framework manifest file from device or from update package");
569 return NO_INIT;
570 }
571 if (updated.dev.manifest == nullptr) {
572 ADD_MESSAGE("No device manifest file from device or from update package");
573 return NO_INIT;
574 }
575 if (updated.fwk.matrix == nullptr) {
Yifan Hongca386fe2018-02-07 11:29:03 -0800576 ADD_MESSAGE("No framework matrix file from device or from update package");
577 return NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700578 }
579 if (updated.dev.matrix == nullptr) {
Yifan Hongca386fe2018-02-07 11:29:03 -0800580 ADD_MESSAGE("No device matrix file from device or from update package");
581 return NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700582 }
Yifan Hong69c1b112018-02-27 17:06:00 -0800583
584 if ((disabledChecks & DISABLE_RUNTIME_INFO) == 0) {
585 if (updated.runtimeInfo == nullptr) {
586 ADD_MESSAGE("No runtime info from device");
587 return NO_INIT;
588 }
Yifan Hong143cfe62017-04-13 20:18:01 -0700589 }
590
591 // compatiblity check.
Yifan Hongca386fe2018-02-07 11:29:03 -0800592 if (!updated.dev.manifest->checkCompatibility(*updated.fwk.matrix, error)) {
593 if (error) {
594 error->insert(0,
595 "Device manifest and framework compatibility matrix are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700596 }
Yifan Hongca386fe2018-02-07 11:29:03 -0800597 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700598 }
Yifan Hongca386fe2018-02-07 11:29:03 -0800599 if (!updated.fwk.manifest->checkCompatibility(*updated.dev.matrix, error)) {
600 if (error) {
601 error->insert(0,
602 "Framework manifest and device compatibility matrix are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700603 }
Yifan Hongca386fe2018-02-07 11:29:03 -0800604 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700605 }
Yifan Hong69c1b112018-02-27 17:06:00 -0800606
607 if ((disabledChecks & DISABLE_RUNTIME_INFO) == 0) {
608 if (!updated.runtimeInfo->checkCompatibility(*updated.fwk.matrix, error, disabledChecks)) {
609 if (error) {
610 error->insert(0,
611 "Runtime info and framework compatibility matrix are incompatible: ");
612 }
613 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700614 }
615 }
616
617 return COMPATIBLE;
618}
619
Yifan Hong9f78c182018-07-12 14:45:52 -0700620namespace details {
621
Yifan Hong270b5652018-01-18 18:46:01 -0800622const std::string kSystemVintfDir = "/system/etc/vintf/";
Yifan Hongccbea052018-01-18 18:48:46 -0800623const std::string kVendorVintfDir = "/vendor/etc/vintf/";
Yifan Hong12a11ac2018-01-19 13:58:32 -0800624const std::string kOdmVintfDir = "/odm/etc/vintf/";
Yifan Hong270b5652018-01-18 18:46:01 -0800625
626const std::string kVendorManifest = kVendorVintfDir + "manifest.xml";
Yifan Honga5ddddf2018-01-18 18:50:13 -0800627const std::string kSystemManifest = kSystemVintfDir + "manifest.xml";
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800628const std::string kVendorMatrix = kVendorVintfDir + "compatibility_matrix.xml";
Yifan Hong12a11ac2018-01-19 13:58:32 -0800629const std::string kOdmManifest = kOdmVintfDir + "manifest.xml";
Yifan Hong270b5652018-01-18 18:46:01 -0800630
Steven Morelandeedf2d42018-04-04 16:36:27 -0700631const std::string kVendorManifestFragmentDir = kVendorVintfDir + "manifest/";
632const std::string kSystemManifestFragmentDir = kSystemVintfDir + "manifest/";
633const std::string kOdmManifestFragmentDir = kOdmVintfDir + "manifest/";
634
Yifan Hong270b5652018-01-18 18:46:01 -0800635const std::string kVendorLegacyManifest = "/vendor/manifest.xml";
636const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml";
Yifan Hongde6d00e2018-02-27 17:11:28 -0800637const std::string kSystemLegacyManifest = "/system/manifest.xml";
Yifan Hong270b5652018-01-18 18:46:01 -0800638const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml";
639const std::string kOdmLegacyVintfDir = "/odm/etc/";
640const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml";
641
Yifan Hong69c1b112018-02-27 17:06:00 -0800642std::vector<std::string> dumpFileList() {
643 return {
644 kSystemVintfDir, kVendorVintfDir, kOdmVintfDir, kOdmLegacyVintfDir,
645
646 kVendorLegacyManifest, kVendorLegacyMatrix, kSystemLegacyManifest, kSystemLegacyMatrix,
647 };
648}
649
Yifan Hong9f78c182018-07-12 14:45:52 -0700650} // namespace details
Yifan Hong143cfe62017-04-13 20:18:01 -0700651
Yifan Hongdb6423e2017-09-11 14:38:46 -0700652int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error,
653 DisabledChecks disabledChecks) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700654 return GetInstance()->checkCompatibility(xmls, error, disabledChecks);
Yifan Hongfbbf0472017-04-07 18:14:18 -0700655}
656
Yifan Hong9f78c182018-07-12 14:45:52 -0700657int32_t VintfObject::checkCompatibility(const std::vector<std::string>& xmls, std::string* error,
658 DisabledChecks disabledChecks) {
659 return checkCompatibility(xmls, false /* mount */, error, disabledChecks);
660}
661
662bool VintfObject::IsHalDeprecated(const MatrixHal& oldMatrixHal,
Yifan Hongf73ba512018-01-17 15:52:30 -0800663 const CompatibilityMatrix& targetMatrix,
Yifan Honga8a8fa92018-03-20 14:42:43 -0700664 const ListInstances& listInstances, std::string* error) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700665 bool isDeprecated = false;
666 oldMatrixHal.forEachInstance([&](const MatrixInstance& oldMatrixInstance) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700667 if (IsInstanceDeprecated(oldMatrixInstance, targetMatrix, listInstances, error)) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700668 isDeprecated = true;
Yifan Hongf73ba512018-01-17 15:52:30 -0800669 }
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700670 return !isDeprecated; // continue if no deprecated instance is found.
671 });
672 return isDeprecated;
Yifan Hongf73ba512018-01-17 15:52:30 -0800673}
674
Yifan Honga8a8fa92018-03-20 14:42:43 -0700675// Let oldMatrixInstance = package@x.y-w::interface with instancePattern.
676// If any "servedInstance" in listInstances(package@x.y::interface) matches instancePattern, return
677// true iff:
678// 1. package@x.?::interface/servedInstance is not in targetMatrix; OR
679// 2. package@x.z::interface/servedInstance is in targetMatrix but
680// servedInstance is not in listInstances(package@x.z::interface)
Yifan Hong9f78c182018-07-12 14:45:52 -0700681bool VintfObject::IsInstanceDeprecated(const MatrixInstance& oldMatrixInstance,
Yifan Hongf73ba512018-01-17 15:52:30 -0800682 const CompatibilityMatrix& targetMatrix,
Yifan Honga8a8fa92018-03-20 14:42:43 -0700683 const ListInstances& listInstances, std::string* error) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700684 const std::string& package = oldMatrixInstance.package();
685 const Version& version = oldMatrixInstance.versionRange().minVer();
686 const std::string& interface = oldMatrixInstance.interface();
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700687
Yifan Honga8a8fa92018-03-20 14:42:43 -0700688 std::vector<std::string> instanceHint;
689 if (!oldMatrixInstance.isRegex()) {
690 instanceHint.push_back(oldMatrixInstance.exactInstance());
691 }
692
693 auto list = listInstances(package, version, interface, instanceHint);
694 for (const auto& pair : list) {
695 const std::string& servedInstance = pair.first;
696 Version servedVersion = pair.second;
697 if (!oldMatrixInstance.matchInstance(servedInstance)) {
698 continue;
699 }
700
Yifan Hongf73ba512018-01-17 15:52:30 -0800701 // Find any package@x.? in target matrix, and check if instance is in target matrix.
Yifan Hong217f47e2018-03-15 12:34:05 -0700702 bool foundInstance = false;
703 Version targetMatrixMinVer;
704 targetMatrix.forEachInstanceOfPackage(package, [&](const auto& targetMatrixInstance) {
705 if (targetMatrixInstance.versionRange().majorVer == version.majorVer &&
706 targetMatrixInstance.interface() == interface &&
Yifan Honga8a8fa92018-03-20 14:42:43 -0700707 targetMatrixInstance.matchInstance(servedInstance)) {
Yifan Hong217f47e2018-03-15 12:34:05 -0700708 targetMatrixMinVer = targetMatrixInstance.versionRange().minVer();
709 foundInstance = true;
710 }
711 return !foundInstance; // continue if not found
712 });
713 if (!foundInstance) {
Yifan Hongf73ba512018-01-17 15:52:30 -0800714 if (error) {
Yifan Honga8a8fa92018-03-20 14:42:43 -0700715 *error = toFQNameString(package, servedVersion, interface, servedInstance) +
Steven Morelanda1b984c2018-03-09 13:09:15 -0800716 " is deprecated in compatibility matrix at FCM Version " +
Yifan Hongf73ba512018-01-17 15:52:30 -0800717 to_string(targetMatrix.level()) + "; it should not be served.";
718 }
719 return true;
720 }
721
Yifan Hongf73ba512018-01-17 15:52:30 -0800722 // Assuming that targetMatrix requires @x.u-v, require that at least @x.u is served.
Yifan Honga8a8fa92018-03-20 14:42:43 -0700723 bool targetVersionServed = false;
724 for (const auto& newPair :
725 listInstances(package, targetMatrixMinVer, interface, instanceHint)) {
726 if (newPair.first == servedInstance) {
727 targetVersionServed = true;
728 break;
729 }
730 }
Yifan Hongf73ba512018-01-17 15:52:30 -0800731
732 if (!targetVersionServed) {
733 if (error) {
Yifan Honga8a8fa92018-03-20 14:42:43 -0700734 *error += toFQNameString(package, servedVersion, interface, servedInstance) +
735 " is deprecated; requires at least " + to_string(targetMatrixMinVer) +
736 "\n";
Yifan Hongf73ba512018-01-17 15:52:30 -0800737 }
738 return true;
739 }
740 }
Yifan Honga8a8fa92018-03-20 14:42:43 -0700741
Yifan Hongf73ba512018-01-17 15:52:30 -0800742 return false;
743}
744
Yifan Honga8a8fa92018-03-20 14:42:43 -0700745int32_t VintfObject::CheckDeprecation(const ListInstances& listInstances, std::string* error) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700746 return GetInstance()->checkDeprecation(listInstances, error);
747}
748int32_t VintfObject::checkDeprecation(const ListInstances& listInstances, std::string* error) {
749 auto matrixFragments = getAllFrameworkMatrixLevels(error);
Yifan Hongf73ba512018-01-17 15:52:30 -0800750 if (matrixFragments.empty()) {
751 if (error && error->empty())
752 *error = "Cannot get framework matrix for each FCM version for unknown error.";
753 return NAME_NOT_FOUND;
754 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700755 auto deviceManifest = getDeviceHalManifest();
Yifan Hongf73ba512018-01-17 15:52:30 -0800756 if (deviceManifest == nullptr) {
757 if (error) *error = "No device manifest.";
758 return NAME_NOT_FOUND;
759 }
760 Level deviceLevel = deviceManifest->level();
761 if (deviceLevel == Level::UNSPECIFIED) {
762 if (error) *error = "Device manifest does not specify Shipping FCM Version.";
763 return BAD_VALUE;
764 }
765
766 const CompatibilityMatrix* targetMatrix = nullptr;
767 for (const auto& namedMatrix : matrixFragments) {
768 if (namedMatrix.object.level() == deviceLevel) {
769 targetMatrix = &namedMatrix.object;
770 }
771 }
772 if (targetMatrix == nullptr) {
773 if (error)
774 *error = "Cannot find framework matrix at FCM version " + to_string(deviceLevel) + ".";
775 return NAME_NOT_FOUND;
776 }
777
778 bool hasDeprecatedHals = false;
779 for (const auto& namedMatrix : matrixFragments) {
780 if (namedMatrix.object.level() == Level::UNSPECIFIED) continue;
781 if (namedMatrix.object.level() >= deviceLevel) continue;
782
783 const auto& oldMatrix = namedMatrix.object;
784 for (const MatrixHal& hal : oldMatrix.getHals()) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700785 hasDeprecatedHals |= IsHalDeprecated(hal, *targetMatrix, listInstances, error);
Yifan Hongf73ba512018-01-17 15:52:30 -0800786 }
787 }
788
789 return hasDeprecatedHals ? DEPRECATED : NO_DEPRECATED_HALS;
790}
791
792int32_t VintfObject::CheckDeprecation(std::string* error) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700793 return GetInstance()->checkDeprecation(error);
794}
795int32_t VintfObject::checkDeprecation(std::string* error) {
Yifan Hong2a90ffe2018-03-05 17:45:34 -0800796 using namespace std::placeholders;
Yifan Hong9f78c182018-07-12 14:45:52 -0700797 auto deviceManifest = getDeviceHalManifest();
Yifan Honga8a8fa92018-03-20 14:42:43 -0700798 ListInstances inManifest =
799 [&deviceManifest](const std::string& package, Version version, const std::string& interface,
800 const std::vector<std::string>& /* hintInstances */) {
801 std::vector<std::pair<std::string, Version>> ret;
802 deviceManifest->forEachInstanceOfInterface(
803 package, version, interface, [&ret](const ManifestInstance& manifestInstance) {
804 ret.push_back(
805 std::make_pair(manifestInstance.instance(), manifestInstance.version()));
806 return true;
807 });
808 return ret;
809 };
Yifan Hong9f78c182018-07-12 14:45:52 -0700810 return checkDeprecation(inManifest, error);
Yifan Hongf73ba512018-01-17 15:52:30 -0800811}
Yifan Hong3daec812017-02-27 18:49:11 -0800812
Yifan Hong9f78c182018-07-12 14:45:52 -0700813const std::unique_ptr<FileSystem>& VintfObject::getFileSystem() {
814 return mFileSystem;
815}
816
817const std::unique_ptr<PartitionMounter>& VintfObject::getPartitionMounter() {
818 return mPartitionMounter;
819}
820
821const std::unique_ptr<PropertyFetcher>& VintfObject::getPropertyFetcher() {
822 return mPropertyFetcher;
823}
824
825const std::unique_ptr<details::ObjectFactory<RuntimeInfo>>& VintfObject::getRuntimeInfoFactory() {
826 return mRuntimeInfoFactory;
Yifan Hong10d86222018-04-06 15:41:05 -0700827}
828
Yifan Hong3daec812017-02-27 18:49:11 -0800829} // namespace vintf
830} // namespace android