blob: 64f4a610ab883662eddbe1cc71b8b222b7a723f0 [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 Hong3daec812017-02-27 18:49:11 -080021#include <functional>
22#include <memory>
23#include <mutex>
24
Yifan Hong60217032018-01-08 16:19:42 -080025#include <android-base/logging.h>
26
Yifan Hong12e23c22018-11-05 14:53:30 -080027#include "CompatibilityMatrix.h"
28#include "VintfObjectAfterUpdate.h"
29#include "parse_string.h"
30#include "parse_xml.h"
31#include "utils.h"
32
Yifan Hong60217032018-01-08 16:19:42 -080033using std::placeholders::_1;
34using std::placeholders::_2;
35
Yifan Hong3daec812017-02-27 18:49:11 -080036namespace android {
37namespace vintf {
38
Yifan Hong270b5652018-01-18 18:46:01 -080039using namespace details;
40
Yifan Hong9f78c182018-07-12 14:45:52 -070041#ifdef LIBVINTF_TARGET
42static constexpr bool kIsTarget = true;
43#else
44static constexpr bool kIsTarget = false;
45#endif
Yifan Hong1fb004e2017-09-26 15:04:44 -070046
Yifan Hong3daec812017-02-27 18:49:11 -080047template <typename T, typename F>
Yifan Hongfc73edf2017-08-29 11:39:07 -070048static std::shared_ptr<const T> Get(
49 LockedSharedPtr<T> *ptr,
Yifan Hong143cfe62017-04-13 20:18:01 -070050 bool skipCache,
Yifan Hong3daec812017-02-27 18:49:11 -080051 const F &fetchAllInformation) {
52 std::unique_lock<std::mutex> _lock(ptr->mutex);
Yifan Hong7219ba12018-01-08 16:23:49 -080053 if (skipCache || !ptr->fetchedOnce) {
Yifan Hong3daec812017-02-27 18:49:11 -080054 ptr->object = std::make_unique<T>();
Yifan Hong60217032018-01-08 16:19:42 -080055 std::string error;
56 if (fetchAllInformation(ptr->object.get(), &error) != OK) {
57 LOG(WARNING) << error;
Yifan Hong3daec812017-02-27 18:49:11 -080058 ptr->object = nullptr; // frees the old object
59 }
Yifan Hong7219ba12018-01-08 16:23:49 -080060 ptr->fetchedOnce = true;
Yifan Hong3daec812017-02-27 18:49:11 -080061 }
Yifan Hongfc73edf2017-08-29 11:39:07 -070062 return ptr->object;
Yifan Hong3daec812017-02-27 18:49:11 -080063}
64
Yifan Hong9f78c182018-07-12 14:45:52 -070065static std::unique_ptr<FileSystem> createDefaultFileSystem() {
66 std::unique_ptr<FileSystem> fileSystem;
67 if (kIsTarget) {
68 fileSystem = std::make_unique<details::FileSystemImpl>();
69 } else {
70 fileSystem = std::make_unique<details::FileSystemNoOp>();
71 }
72 return fileSystem;
73}
74
75static std::unique_ptr<PropertyFetcher> createDefaultPropertyFetcher() {
76 std::unique_ptr<PropertyFetcher> propertyFetcher;
77 if (kIsTarget) {
78 propertyFetcher = std::make_unique<details::PropertyFetcherImpl>();
79 } else {
80 propertyFetcher = std::make_unique<details::PropertyFetcherNoOp>();
81 }
82 return propertyFetcher;
83}
84
Yifan Hong9f78c182018-07-12 14:45:52 -070085details::LockedSharedPtr<VintfObject> VintfObject::sInstance{};
86std::shared_ptr<VintfObject> VintfObject::GetInstance() {
87 std::unique_lock<std::mutex> lock(sInstance.mutex);
88 if (sInstance.object == nullptr) {
Yifan Hong78f5b572018-11-27 14:05:03 -080089 sInstance.object = std::shared_ptr<VintfObject>(VintfObject::Builder().build().release());
Yifan Hong9f78c182018-07-12 14:45:52 -070090 }
91 return sInstance.object;
92}
93
Yifan Hongfc73edf2017-08-29 11:39:07 -070094std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -070095 return GetInstance()->getDeviceHalManifest(skipCache);
Yifan Hong3daec812017-02-27 18:49:11 -080096}
97
Yifan Hong9f78c182018-07-12 14:45:52 -070098std::shared_ptr<const HalManifest> VintfObject::getDeviceHalManifest(bool skipCache) {
99 return Get(&mDeviceManifest, skipCache,
100 std::bind(&VintfObject::fetchDeviceHalManifest, this, _1, _2));
101}
102
Yifan Hongfc73edf2017-08-29 11:39:07 -0700103std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700104 return GetInstance()->getFrameworkHalManifest(skipCache);
Yifan Hong3daec812017-02-27 18:49:11 -0800105}
106
Yifan Hong9f78c182018-07-12 14:45:52 -0700107std::shared_ptr<const HalManifest> VintfObject::getFrameworkHalManifest(bool skipCache) {
108 return Get(&mFrameworkManifest, skipCache,
109 std::bind(&VintfObject::fetchFrameworkHalManifest, this, _1, _2));
110}
Yifan Hong2272bf82017-04-28 14:37:56 -0700111
Yifan Hongfc73edf2017-08-29 11:39:07 -0700112std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700113 return GetInstance()->getDeviceCompatibilityMatrix(skipCache);
Yifan Hong2272bf82017-04-28 14:37:56 -0700114}
115
Yifan Hong9f78c182018-07-12 14:45:52 -0700116std::shared_ptr<const CompatibilityMatrix> VintfObject::getDeviceCompatibilityMatrix(
117 bool skipCache) {
118 return Get(&mDeviceMatrix, skipCache, std::bind(&VintfObject::fetchDeviceMatrix, this, _1, _2));
119}
120
Yifan Hongfc73edf2017-08-29 11:39:07 -0700121std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700122 return GetInstance()->getFrameworkCompatibilityMatrix(skipCache);
123}
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800124
Yifan Hong9f78c182018-07-12 14:45:52 -0700125std::shared_ptr<const CompatibilityMatrix> VintfObject::getFrameworkCompatibilityMatrix(
126 bool skipCache) {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800127 // To avoid deadlock, get device manifest before any locks.
Yifan Hong9f78c182018-07-12 14:45:52 -0700128 auto deviceManifest = getDeviceHalManifest();
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800129
Yifan Hong9f78c182018-07-12 14:45:52 -0700130 std::unique_lock<std::mutex> _lock(mFrameworkCompatibilityMatrixMutex);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800131
132 auto combined =
Yifan Hong9f78c182018-07-12 14:45:52 -0700133 Get(&mCombinedFrameworkMatrix, skipCache,
134 std::bind(&VintfObject::getCombinedFrameworkMatrix, this, deviceManifest, _1, _2));
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800135 if (combined != nullptr) {
136 return combined;
137 }
138
Yifan Hong9f78c182018-07-12 14:45:52 -0700139 return Get(&mFrameworkMatrix, skipCache,
Yifan Hong12e23c22018-11-05 14:53:30 -0800140 std::bind(&CompatibilityMatrix::fetchAllInformation, _1, getFileSystem().get(),
Yifan Hong9f78c182018-07-12 14:45:52 -0700141 kSystemLegacyMatrix, _2));
Yifan Hong2272bf82017-04-28 14:37:56 -0700142}
143
Yifan Hong9f78c182018-07-12 14:45:52 -0700144status_t VintfObject::getCombinedFrameworkMatrix(
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800145 const std::shared_ptr<const HalManifest>& deviceManifest, CompatibilityMatrix* out,
146 std::string* error) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700147 auto matrixFragments = getAllFrameworkMatrixLevels(error);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800148 if (matrixFragments.empty()) {
149 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)
169 for (auto&& pair : matrixFragments) {
170 Level fragmentLevel = pair.object.level();
171 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 Hong270b5652018-01-18 18:46:01 -0800181 *error = "No framework compatibility matrix files under " + kSystemVintfDir +
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800182 " declare FCM version.";
183 }
184 return NAME_NOT_FOUND;
185 }
186
Yifan Honge7837b12018-10-11 10:38:57 -0700187 auto combined = CompatibilityMatrix::combine(deviceLevel, &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 Hong9f78c182018-07-12 14:45:52 -0700196status_t VintfObject::addDirectoryManifests(const std::string& directory, HalManifest* manifest,
Steven Morelandeedf2d42018-04-04 16:36:27 -0700197 std::string* error) {
198 std::vector<std::string> fileNames;
Yifan Hong12e23c22018-11-05 14:53:30 -0800199 status_t err = getFileSystem()->listFiles(directory, &fileNames, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700200 // if the directory isn't there, that's okay
201 if (err == NAME_NOT_FOUND) return OK;
202 if (err != OK) return err;
203
204 for (const std::string& file : fileNames) {
205 // Only adds HALs because all other things are added by libvintf
206 // itself for now.
207 HalManifest fragmentManifest;
Yifan Hong9f78c182018-07-12 14:45:52 -0700208 err = fetchOneHalManifest(directory + file, &fragmentManifest, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700209 if (err != OK) return err;
210
211 manifest->addAllHals(&fragmentManifest);
212 }
213
214 return OK;
215}
216
Yifan Hong5a93bf22018-01-17 18:22:32 -0800217// Priority for loading vendor manifest:
Steven Morelandeedf2d42018-04-04 16:36:27 -0700218// 1. /vendor/etc/vintf/manifest.xml + device fragments + ODM manifest (optional) + odm fragments
219// 2. /vendor/etc/vintf/manifest.xml + device fragments
220// 3. ODM manifest (optional) + odm fragments
221// 4. /vendor/manifest.xml (legacy, no fragments)
Yifan Hong5a93bf22018-01-17 18:22:32 -0800222// where:
Steven Moreland30a532c2018-11-01 08:46:32 -0700223// A + B means unioning <hal> tags from A and B. If B declares an override, then this takes priority
224// over A.
Yifan Hong9f78c182018-07-12 14:45:52 -0700225status_t VintfObject::fetchDeviceHalManifest(HalManifest* out, std::string* error) {
226 status_t vendorStatus = fetchOneHalManifest(kVendorManifest, out, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800227 if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) {
228 return vendorStatus;
229 }
230
Steven Morelandeedf2d42018-04-04 16:36:27 -0700231 if (vendorStatus == OK) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700232 status_t fragmentStatus = addDirectoryManifests(kVendorManifestFragmentDir, out, error);
Steven Morelandeedf2d42018-04-04 16:36:27 -0700233 if (fragmentStatus != OK) {
234 return fragmentStatus;
235 }
236 }
237
Yifan Hong5a93bf22018-01-17 18:22:32 -0800238 HalManifest odmManifest;
Yifan Hong9f78c182018-07-12 14:45:52 -0700239 status_t odmStatus = fetchOdmHalManifest(&odmManifest, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800240 if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
241 return odmStatus;
Yifan Hong5a93bf22018-01-17 18:22:32 -0800242 }
243
Yifan Hong5a93bf22018-01-17 18:22:32 -0800244 if (vendorStatus == OK) {
Yifan Hong12a11ac2018-01-19 13:58:32 -0800245 if (odmStatus == OK) {
246 out->addAllHals(&odmManifest);
247 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700248 return addDirectoryManifests(kOdmManifestFragmentDir, out, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800249 }
250
Yifan Hong12a11ac2018-01-19 13:58:32 -0800251 // vendorStatus != OK, "out" is not changed.
Yifan Hong5a93bf22018-01-17 18:22:32 -0800252 if (odmStatus == OK) {
253 *out = std::move(odmManifest);
Yifan Hong9f78c182018-07-12 14:45:52 -0700254 return addDirectoryManifests(kOdmManifestFragmentDir, out, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800255 }
256
257 // Use legacy /vendor/manifest.xml
Yifan Hong12e23c22018-11-05 14:53:30 -0800258 return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800259}
260
Yifan Hong12a11ac2018-01-19 13:58:32 -0800261// "out" is written to iff return status is OK.
262// Priority:
263// 1. if {sku} is defined, /odm/etc/vintf/manifest_{sku}.xml
264// 2. /odm/etc/vintf/manifest.xml
265// 3. if {sku} is defined, /odm/etc/manifest_{sku}.xml
266// 4. /odm/etc/manifest.xml
267// where:
268// {sku} is the value of ro.boot.product.hardware.sku
Yifan Hong9f78c182018-07-12 14:45:52 -0700269status_t VintfObject::fetchOdmHalManifest(HalManifest* out, std::string* error) {
Yifan Hong12a11ac2018-01-19 13:58:32 -0800270 status_t status;
271
Yifan Hong12a11ac2018-01-19 13:58:32 -0800272 std::string productModel;
Yifan Hong12e23c22018-11-05 14:53:30 -0800273 productModel = getPropertyFetcher()->getProperty("ro.boot.product.hardware.sku", "");
Yifan Hong12a11ac2018-01-19 13:58:32 -0800274
275 if (!productModel.empty()) {
276 status =
Yifan Hong9f78c182018-07-12 14:45:52 -0700277 fetchOneHalManifest(kOdmVintfDir + "manifest_" + productModel + ".xml", out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800278 if (status == OK || status != NAME_NOT_FOUND) {
279 return status;
280 }
281 }
Yifan Hong12a11ac2018-01-19 13:58:32 -0800282
Yifan Hong9f78c182018-07-12 14:45:52 -0700283 status = fetchOneHalManifest(kOdmManifest, out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800284 if (status == OK || status != NAME_NOT_FOUND) {
285 return status;
286 }
287
Yifan Hong12a11ac2018-01-19 13:58:32 -0800288 if (!productModel.empty()) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700289 status = fetchOneHalManifest(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", out,
Yifan Hong12a11ac2018-01-19 13:58:32 -0800290 error);
291 if (status == OK || status != NAME_NOT_FOUND) {
292 return status;
293 }
294 }
Yifan Hong12a11ac2018-01-19 13:58:32 -0800295
Yifan Hong9f78c182018-07-12 14:45:52 -0700296 status = fetchOneHalManifest(kOdmLegacyManifest, out, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800297 if (status == OK || status != NAME_NOT_FOUND) {
298 return status;
299 }
300
301 return NAME_NOT_FOUND;
302}
303
304// Fetch one manifest.xml file. "out" is written to iff return status is OK.
305// Returns NAME_NOT_FOUND if file is missing.
Yifan Hong9f78c182018-07-12 14:45:52 -0700306status_t VintfObject::fetchOneHalManifest(const std::string& path, HalManifest* out,
Yifan Hong12a11ac2018-01-19 13:58:32 -0800307 std::string* error) {
308 HalManifest ret;
Yifan Hong12e23c22018-11-05 14:53:30 -0800309 status_t status = ret.fetchAllInformation(getFileSystem().get(), path, error);
Yifan Hong12a11ac2018-01-19 13:58:32 -0800310 if (status == OK) {
311 *out = std::move(ret);
312 }
313 return status;
314}
315
Yifan Hong9f78c182018-07-12 14:45:52 -0700316status_t VintfObject::fetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) {
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800317 CompatibilityMatrix etcMatrix;
Yifan Hong12e23c22018-11-05 14:53:30 -0800318 if (etcMatrix.fetchAllInformation(getFileSystem().get(), kVendorMatrix, error) == OK) {
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800319 *out = std::move(etcMatrix);
320 return OK;
321 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800322 return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyMatrix, error);
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800323}
324
Yifan Hong9f78c182018-07-12 14:45:52 -0700325status_t VintfObject::fetchFrameworkHalManifest(HalManifest* out, std::string* error) {
Yifan Hongde6d00e2018-02-27 17:11:28 -0800326 HalManifest etcManifest;
Yifan Hong12e23c22018-11-05 14:53:30 -0800327 if (etcManifest.fetchAllInformation(getFileSystem().get(), kSystemManifest, error) == OK) {
Yifan Hongde6d00e2018-02-27 17:11:28 -0800328 *out = std::move(etcManifest);
Yifan Hong9f78c182018-07-12 14:45:52 -0700329 return addDirectoryManifests(kSystemManifestFragmentDir, out, error);
Yifan Hongde6d00e2018-02-27 17:11:28 -0800330 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800331 return out->fetchAllInformation(getFileSystem().get(), kSystemLegacyManifest, error);
Yifan Hongde6d00e2018-02-27 17:11:28 -0800332}
333
Yifan Hong9f8f6562018-11-06 16:26:20 -0800334static void appendLine(std::string* error, const std::string& message) {
335 if (error != nullptr) {
336 if (!error->empty()) *error += "\n";
337 *error += message;
338 }
339}
340
Yifan Hong9f78c182018-07-12 14:45:52 -0700341std::vector<Named<CompatibilityMatrix>> VintfObject::getAllFrameworkMatrixLevels(
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800342 std::string* error) {
343 std::vector<std::string> fileNames;
344 std::vector<Named<CompatibilityMatrix>> results;
345
Yifan Hong12e23c22018-11-05 14:53:30 -0800346 if (getFileSystem()->listFiles(kSystemVintfDir, &fileNames, error) != OK) {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800347 return {};
348 }
349 for (const std::string& fileName : fileNames) {
Yifan Hong270b5652018-01-18 18:46:01 -0800350 std::string path = kSystemVintfDir + fileName;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800351
352 std::string content;
353 std::string fetchError;
Yifan Hong12e23c22018-11-05 14:53:30 -0800354 status_t status = getFileSystem()->fetch(path, &content, &fetchError);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800355 if (status != OK) {
Yifan Hong9f8f6562018-11-06 16:26:20 -0800356 appendLine(error, "Framework Matrix: Ignore file " + path + ": " + fetchError);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800357 continue;
358 }
359
360 auto it = results.emplace(results.end());
Yifan Hong9f8f6562018-11-06 16:26:20 -0800361 std::string parseError;
362 if (!gCompatibilityMatrixConverter(&it->object, content, &parseError)) {
363 appendLine(error, "Framework Matrix: Ignore file " + path + ": " + parseError);
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800364 results.erase(it);
365 continue;
366 }
367 }
368
369 if (results.empty()) {
370 if (error) {
Yifan Hong9f8f6562018-11-06 16:26:20 -0800371 error->insert(0, "No framework matrices under " + kSystemVintfDir +
372 " can be fetched or parsed.\n");
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800373 }
374 } else {
375 if (error && !error->empty()) {
376 LOG(WARNING) << *error;
377 *error = "";
378 }
379 }
380
381 return results;
382}
383
Yifan Hong1fb004e2017-09-26 15:04:44 -0700384std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache,
385 RuntimeInfo::FetchFlags flags) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700386 return GetInstance()->getRuntimeInfo(skipCache, flags);
387}
388std::shared_ptr<const RuntimeInfo> VintfObject::getRuntimeInfo(bool skipCache,
389 RuntimeInfo::FetchFlags flags) {
390 std::unique_lock<std::mutex> _lock(mDeviceRuntimeInfo.mutex);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700391
392 if (!skipCache) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700393 flags &= (~mDeviceRuntimeInfo.fetchedFlags);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700394 }
395
Yifan Hong9f78c182018-07-12 14:45:52 -0700396 if (mDeviceRuntimeInfo.object == nullptr) {
Yifan Hong12e23c22018-11-05 14:53:30 -0800397 mDeviceRuntimeInfo.object = getRuntimeInfoFactory()->make_shared();
Yifan Hong1fb004e2017-09-26 15:04:44 -0700398 }
399
Yifan Hong9f78c182018-07-12 14:45:52 -0700400 status_t status = mDeviceRuntimeInfo.object->fetchAllInformation(flags);
Yifan Hong1fb004e2017-09-26 15:04:44 -0700401 if (status != OK) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700402 mDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched"
Yifan Hong1fb004e2017-09-26 15:04:44 -0700403 return nullptr;
404 }
405
Yifan Hong9f78c182018-07-12 14:45:52 -0700406 mDeviceRuntimeInfo.fetchedFlags |= flags;
407 return mDeviceRuntimeInfo.object;
Yifan Hong3daec812017-02-27 18:49:11 -0800408}
409
Yifan Hong143cfe62017-04-13 20:18:01 -0700410namespace details {
411
Yifan Hong143cfe62017-04-13 20:18:01 -0700412enum class ParseStatus {
413 OK,
414 PARSE_ERROR,
415 DUPLICATED_FWK_ENTRY,
416 DUPLICATED_DEV_ENTRY,
417};
418
Yifan Hong9532bd22017-04-14 15:30:52 -0700419static std::string toString(ParseStatus status) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700420 switch(status) {
421 case ParseStatus::OK: return "OK";
422 case ParseStatus::PARSE_ERROR: return "parse error";
423 case ParseStatus::DUPLICATED_FWK_ENTRY: return "duplicated framework";
424 case ParseStatus::DUPLICATED_DEV_ENTRY: return "duplicated device";
425 }
426 return "";
427}
428
Yifan Hong12e23c22018-11-05 14:53:30 -0800429template <typename T>
430static ParseStatus tryParse(const std::string& xml, const XmlConverter<T>& parse,
431 VintfObjectAfterUpdate* afterUpdate) {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700432 std::shared_ptr<T> ret = std::make_shared<T>();
Yifan Hong94757062018-02-09 16:36:31 -0800433 if (!parse(ret.get(), xml, nullptr /* error */)) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700434 return ParseStatus::PARSE_ERROR;
435 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800436 if (!afterUpdate->set(ret)) {
437 if (ret->type() == SchemaType::FRAMEWORK) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700438 return ParseStatus::DUPLICATED_FWK_ENTRY;
Yifan Hong12e23c22018-11-05 14:53:30 -0800439 } else if (ret->type() == SchemaType::DEVICE) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700440 return ParseStatus::DUPLICATED_DEV_ENTRY;
441 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800442 LOG(FATAL) << "unknown SchemaType: "
443 << static_cast<std::underlying_type_t<SchemaType>>(ret->type());
Yifan Hong143cfe62017-04-13 20:18:01 -0700444 }
445 return ParseStatus::OK;
446}
447
Yifan Hong9f78c182018-07-12 14:45:52 -0700448} // namespace details
449
Yifan Hong12e23c22018-11-05 14:53:30 -0800450// Simulate applying xmls to VintfObject, then checkCompatibility as usual.
Yifan Hongaf3713e2018-11-05 13:59:18 -0800451int32_t VintfObject::checkCompatibility(const std::vector<std::string>& xmls, std::string* error,
452 CheckFlags::Type flags) {
Yifan Hong12e23c22018-11-05 14:53:30 -0800453 VintfObjectAfterUpdate afterUpdate(this);
454 ParseStatus parseStatus = ParseStatus::OK;
Yifan Hong143cfe62017-04-13 20:18:01 -0700455
Yifan Hong143cfe62017-04-13 20:18:01 -0700456 // parse all information from package
457 for (const auto &xml : xmls) {
Yifan Hong12e23c22018-11-05 14:53:30 -0800458 parseStatus = tryParse(xml, gHalManifestConverter, &afterUpdate);
Yifan Hong143cfe62017-04-13 20:18:01 -0700459 if (parseStatus == ParseStatus::OK) {
460 continue; // work on next one
461 }
462 if (parseStatus != ParseStatus::PARSE_ERROR) {
Yifan Hong878556e2018-07-13 13:45:30 -0700463 appendLine(error, toString(parseStatus) + " manifest");
Yifan Hong143cfe62017-04-13 20:18:01 -0700464 return ALREADY_EXISTS;
465 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800466 parseStatus = tryParse(xml, gCompatibilityMatrixConverter, &afterUpdate);
Yifan Hong143cfe62017-04-13 20:18:01 -0700467 if (parseStatus == ParseStatus::OK) {
468 continue; // work on next one
469 }
470 if (parseStatus != ParseStatus::PARSE_ERROR) {
Yifan Hong878556e2018-07-13 13:45:30 -0700471 appendLine(error, toString(parseStatus) + " matrix");
Yifan Hong143cfe62017-04-13 20:18:01 -0700472 return ALREADY_EXISTS;
473 }
Yifan Hong878556e2018-07-13 13:45:30 -0700474 appendLine(error, toString(parseStatus)); // parse error
Yifan Hong143cfe62017-04-13 20:18:01 -0700475 return BAD_VALUE;
476 }
477
Yifan Hong12e23c22018-11-05 14:53:30 -0800478 return afterUpdate.checkCompatibility(error, flags);
479}
Yifan Hong8640cd12017-05-17 12:02:28 -0700480
Yifan Hong12e23c22018-11-05 14:53:30 -0800481int32_t VintfObject::checkCompatibility(std::string* error, CheckFlags::Type flags) {
482 status_t status = OK;
483 // null checks for files and runtime info
484 if (getFrameworkHalManifest() == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700485 appendLine(error, "No framework manifest file from device or from update package");
486 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700487 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800488 if (getDeviceHalManifest() == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700489 appendLine(error, "No device manifest file from device or from update package");
490 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700491 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800492 if (getFrameworkCompatibilityMatrix() == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700493 appendLine(error, "No framework matrix file from device or from update package");
494 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700495 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800496 if (getDeviceCompatibilityMatrix() == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700497 appendLine(error, "No device matrix file from device or from update package");
498 status = NO_INIT;
Yifan Hong143cfe62017-04-13 20:18:01 -0700499 }
Yifan Hong69c1b112018-02-27 17:06:00 -0800500
Yifan Hong072f12d2018-08-08 13:04:51 -0700501 if (flags.isRuntimeInfoEnabled()) {
Yifan Hong12e23c22018-11-05 14:53:30 -0800502 if (getRuntimeInfo() == nullptr) {
Yifan Hong878556e2018-07-13 13:45:30 -0700503 appendLine(error, "No runtime info from device");
504 status = NO_INIT;
Yifan Hong69c1b112018-02-27 17:06:00 -0800505 }
Yifan Hong143cfe62017-04-13 20:18:01 -0700506 }
Yifan Hong878556e2018-07-13 13:45:30 -0700507 if (status != OK) return status;
Yifan Hong143cfe62017-04-13 20:18:01 -0700508
509 // compatiblity check.
Yifan Hong12e23c22018-11-05 14:53:30 -0800510 if (!getDeviceHalManifest()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error)) {
Yifan Hongca386fe2018-02-07 11:29:03 -0800511 if (error) {
512 error->insert(0,
513 "Device manifest and framework compatibility matrix are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700514 }
Yifan Hongca386fe2018-02-07 11:29:03 -0800515 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700516 }
Yifan Hong12e23c22018-11-05 14:53:30 -0800517 if (!getFrameworkHalManifest()->checkCompatibility(*getDeviceCompatibilityMatrix(), error)) {
Yifan Hongca386fe2018-02-07 11:29:03 -0800518 if (error) {
519 error->insert(0,
520 "Framework manifest and device compatibility matrix are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700521 }
Yifan Hongca386fe2018-02-07 11:29:03 -0800522 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700523 }
Yifan Hong69c1b112018-02-27 17:06:00 -0800524
Yifan Hong072f12d2018-08-08 13:04:51 -0700525 if (flags.isRuntimeInfoEnabled()) {
Yifan Hong12e23c22018-11-05 14:53:30 -0800526 if (!getRuntimeInfo()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error,
527 flags)) {
Yifan Hong69c1b112018-02-27 17:06:00 -0800528 if (error) {
529 error->insert(0,
530 "Runtime info and framework compatibility matrix are incompatible: ");
531 }
532 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700533 }
534 }
535
536 return COMPATIBLE;
537}
538
Yifan Hong9f78c182018-07-12 14:45:52 -0700539namespace details {
540
Yifan Hong270b5652018-01-18 18:46:01 -0800541const std::string kSystemVintfDir = "/system/etc/vintf/";
Yifan Hongccbea052018-01-18 18:48:46 -0800542const std::string kVendorVintfDir = "/vendor/etc/vintf/";
Yifan Hong12a11ac2018-01-19 13:58:32 -0800543const std::string kOdmVintfDir = "/odm/etc/vintf/";
Yifan Hong270b5652018-01-18 18:46:01 -0800544
545const std::string kVendorManifest = kVendorVintfDir + "manifest.xml";
Yifan Honga5ddddf2018-01-18 18:50:13 -0800546const std::string kSystemManifest = kSystemVintfDir + "manifest.xml";
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800547const std::string kVendorMatrix = kVendorVintfDir + "compatibility_matrix.xml";
Yifan Hong12a11ac2018-01-19 13:58:32 -0800548const std::string kOdmManifest = kOdmVintfDir + "manifest.xml";
Yifan Hong270b5652018-01-18 18:46:01 -0800549
Steven Morelandeedf2d42018-04-04 16:36:27 -0700550const std::string kVendorManifestFragmentDir = kVendorVintfDir + "manifest/";
551const std::string kSystemManifestFragmentDir = kSystemVintfDir + "manifest/";
552const std::string kOdmManifestFragmentDir = kOdmVintfDir + "manifest/";
553
Yifan Hong270b5652018-01-18 18:46:01 -0800554const std::string kVendorLegacyManifest = "/vendor/manifest.xml";
555const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml";
Yifan Hongde6d00e2018-02-27 17:11:28 -0800556const std::string kSystemLegacyManifest = "/system/manifest.xml";
Yifan Hong270b5652018-01-18 18:46:01 -0800557const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml";
558const std::string kOdmLegacyVintfDir = "/odm/etc/";
559const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml";
560
Yifan Hong69c1b112018-02-27 17:06:00 -0800561std::vector<std::string> dumpFileList() {
562 return {
563 kSystemVintfDir, kVendorVintfDir, kOdmVintfDir, kOdmLegacyVintfDir,
564
565 kVendorLegacyManifest, kVendorLegacyMatrix, kSystemLegacyManifest, kSystemLegacyMatrix,
566 };
567}
568
Yifan Hong9f78c182018-07-12 14:45:52 -0700569} // namespace details
Yifan Hong143cfe62017-04-13 20:18:01 -0700570
Yifan Hongdb6423e2017-09-11 14:38:46 -0700571int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error,
Yifan Hong072f12d2018-08-08 13:04:51 -0700572 CheckFlags::Type flags) {
573 return GetInstance()->checkCompatibility(xmls, error, flags);
Yifan Hongfbbf0472017-04-07 18:14:18 -0700574}
575
Yifan Hong9f78c182018-07-12 14:45:52 -0700576bool VintfObject::IsHalDeprecated(const MatrixHal& oldMatrixHal,
Yifan Hongf73ba512018-01-17 15:52:30 -0800577 const CompatibilityMatrix& targetMatrix,
Yifan Honga8a8fa92018-03-20 14:42:43 -0700578 const ListInstances& listInstances, std::string* error) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700579 bool isDeprecated = false;
580 oldMatrixHal.forEachInstance([&](const MatrixInstance& oldMatrixInstance) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700581 if (IsInstanceDeprecated(oldMatrixInstance, targetMatrix, listInstances, error)) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700582 isDeprecated = true;
Yifan Hongf73ba512018-01-17 15:52:30 -0800583 }
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700584 return !isDeprecated; // continue if no deprecated instance is found.
585 });
586 return isDeprecated;
Yifan Hongf73ba512018-01-17 15:52:30 -0800587}
588
Yifan Honga8a8fa92018-03-20 14:42:43 -0700589// Let oldMatrixInstance = package@x.y-w::interface with instancePattern.
590// If any "servedInstance" in listInstances(package@x.y::interface) matches instancePattern, return
591// true iff:
592// 1. package@x.?::interface/servedInstance is not in targetMatrix; OR
593// 2. package@x.z::interface/servedInstance is in targetMatrix but
594// servedInstance is not in listInstances(package@x.z::interface)
Yifan Hong9f78c182018-07-12 14:45:52 -0700595bool VintfObject::IsInstanceDeprecated(const MatrixInstance& oldMatrixInstance,
Yifan Hongf73ba512018-01-17 15:52:30 -0800596 const CompatibilityMatrix& targetMatrix,
Yifan Honga8a8fa92018-03-20 14:42:43 -0700597 const ListInstances& listInstances, std::string* error) {
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700598 const std::string& package = oldMatrixInstance.package();
599 const Version& version = oldMatrixInstance.versionRange().minVer();
600 const std::string& interface = oldMatrixInstance.interface();
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700601
Yifan Honga8a8fa92018-03-20 14:42:43 -0700602 std::vector<std::string> instanceHint;
603 if (!oldMatrixInstance.isRegex()) {
604 instanceHint.push_back(oldMatrixInstance.exactInstance());
605 }
606
607 auto list = listInstances(package, version, interface, instanceHint);
608 for (const auto& pair : list) {
609 const std::string& servedInstance = pair.first;
610 Version servedVersion = pair.second;
611 if (!oldMatrixInstance.matchInstance(servedInstance)) {
612 continue;
613 }
614
Yifan Hongf73ba512018-01-17 15:52:30 -0800615 // Find any package@x.? in target matrix, and check if instance is in target matrix.
Yifan Hong217f47e2018-03-15 12:34:05 -0700616 bool foundInstance = false;
617 Version targetMatrixMinVer;
618 targetMatrix.forEachInstanceOfPackage(package, [&](const auto& targetMatrixInstance) {
619 if (targetMatrixInstance.versionRange().majorVer == version.majorVer &&
620 targetMatrixInstance.interface() == interface &&
Yifan Honga8a8fa92018-03-20 14:42:43 -0700621 targetMatrixInstance.matchInstance(servedInstance)) {
Yifan Hong217f47e2018-03-15 12:34:05 -0700622 targetMatrixMinVer = targetMatrixInstance.versionRange().minVer();
623 foundInstance = true;
624 }
625 return !foundInstance; // continue if not found
626 });
627 if (!foundInstance) {
Yifan Hongf73ba512018-01-17 15:52:30 -0800628 if (error) {
Yifan Honga8a8fa92018-03-20 14:42:43 -0700629 *error = toFQNameString(package, servedVersion, interface, servedInstance) +
Steven Morelanda1b984c2018-03-09 13:09:15 -0800630 " is deprecated in compatibility matrix at FCM Version " +
Yifan Hongf73ba512018-01-17 15:52:30 -0800631 to_string(targetMatrix.level()) + "; it should not be served.";
632 }
633 return true;
634 }
635
Yifan Hongf73ba512018-01-17 15:52:30 -0800636 // Assuming that targetMatrix requires @x.u-v, require that at least @x.u is served.
Yifan Honga8a8fa92018-03-20 14:42:43 -0700637 bool targetVersionServed = false;
638 for (const auto& newPair :
639 listInstances(package, targetMatrixMinVer, interface, instanceHint)) {
640 if (newPair.first == servedInstance) {
641 targetVersionServed = true;
642 break;
643 }
644 }
Yifan Hongf73ba512018-01-17 15:52:30 -0800645
646 if (!targetVersionServed) {
Yifan Hong9f8f6562018-11-06 16:26:20 -0800647 appendLine(error, toFQNameString(package, servedVersion, interface, servedInstance) +
648 " is deprecated; requires at least " +
649 to_string(targetMatrixMinVer));
Yifan Hongf73ba512018-01-17 15:52:30 -0800650 return true;
651 }
652 }
Yifan Honga8a8fa92018-03-20 14:42:43 -0700653
Yifan Hongf73ba512018-01-17 15:52:30 -0800654 return false;
655}
656
Yifan Honga8a8fa92018-03-20 14:42:43 -0700657int32_t VintfObject::CheckDeprecation(const ListInstances& listInstances, std::string* error) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700658 return GetInstance()->checkDeprecation(listInstances, error);
659}
660int32_t VintfObject::checkDeprecation(const ListInstances& listInstances, std::string* error) {
661 auto matrixFragments = getAllFrameworkMatrixLevels(error);
Yifan Hongf73ba512018-01-17 15:52:30 -0800662 if (matrixFragments.empty()) {
663 if (error && error->empty())
664 *error = "Cannot get framework matrix for each FCM version for unknown error.";
665 return NAME_NOT_FOUND;
666 }
Yifan Hong9f78c182018-07-12 14:45:52 -0700667 auto deviceManifest = getDeviceHalManifest();
Yifan Hongf73ba512018-01-17 15:52:30 -0800668 if (deviceManifest == nullptr) {
669 if (error) *error = "No device manifest.";
670 return NAME_NOT_FOUND;
671 }
672 Level deviceLevel = deviceManifest->level();
673 if (deviceLevel == Level::UNSPECIFIED) {
674 if (error) *error = "Device manifest does not specify Shipping FCM Version.";
675 return BAD_VALUE;
676 }
677
678 const CompatibilityMatrix* targetMatrix = nullptr;
679 for (const auto& namedMatrix : matrixFragments) {
680 if (namedMatrix.object.level() == deviceLevel) {
681 targetMatrix = &namedMatrix.object;
682 }
683 }
684 if (targetMatrix == nullptr) {
685 if (error)
686 *error = "Cannot find framework matrix at FCM version " + to_string(deviceLevel) + ".";
687 return NAME_NOT_FOUND;
688 }
689
690 bool hasDeprecatedHals = false;
691 for (const auto& namedMatrix : matrixFragments) {
692 if (namedMatrix.object.level() == Level::UNSPECIFIED) continue;
693 if (namedMatrix.object.level() >= deviceLevel) continue;
694
695 const auto& oldMatrix = namedMatrix.object;
696 for (const MatrixHal& hal : oldMatrix.getHals()) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700697 hasDeprecatedHals |= IsHalDeprecated(hal, *targetMatrix, listInstances, error);
Yifan Hongf73ba512018-01-17 15:52:30 -0800698 }
699 }
700
701 return hasDeprecatedHals ? DEPRECATED : NO_DEPRECATED_HALS;
702}
703
704int32_t VintfObject::CheckDeprecation(std::string* error) {
Yifan Hong9f78c182018-07-12 14:45:52 -0700705 return GetInstance()->checkDeprecation(error);
706}
707int32_t VintfObject::checkDeprecation(std::string* error) {
Yifan Hong2a90ffe2018-03-05 17:45:34 -0800708 using namespace std::placeholders;
Yifan Hong9f78c182018-07-12 14:45:52 -0700709 auto deviceManifest = getDeviceHalManifest();
Yifan Honga8a8fa92018-03-20 14:42:43 -0700710 ListInstances inManifest =
711 [&deviceManifest](const std::string& package, Version version, const std::string& interface,
712 const std::vector<std::string>& /* hintInstances */) {
713 std::vector<std::pair<std::string, Version>> ret;
714 deviceManifest->forEachInstanceOfInterface(
715 package, version, interface, [&ret](const ManifestInstance& manifestInstance) {
716 ret.push_back(
717 std::make_pair(manifestInstance.instance(), manifestInstance.version()));
718 return true;
719 });
720 return ret;
721 };
Yifan Hong9f78c182018-07-12 14:45:52 -0700722 return checkDeprecation(inManifest, error);
Yifan Hongf73ba512018-01-17 15:52:30 -0800723}
Yifan Hong3daec812017-02-27 18:49:11 -0800724
Yifan Hong9f78c182018-07-12 14:45:52 -0700725const std::unique_ptr<FileSystem>& VintfObject::getFileSystem() {
726 return mFileSystem;
727}
728
Yifan Hong9f78c182018-07-12 14:45:52 -0700729const std::unique_ptr<PropertyFetcher>& VintfObject::getPropertyFetcher() {
730 return mPropertyFetcher;
731}
732
Yifan Hongd038b2b2018-11-27 13:57:56 -0800733const std::unique_ptr<ObjectFactory<RuntimeInfo>>& VintfObject::getRuntimeInfoFactory() {
Yifan Hong9f78c182018-07-12 14:45:52 -0700734 return mRuntimeInfoFactory;
Yifan Hong10d86222018-04-06 15:41:05 -0700735}
736
Yifan Hong78f5b572018-11-27 14:05:03 -0800737// make_unique does not work because VintfObject constructor is private.
738VintfObject::Builder::Builder() : mObject(std::unique_ptr<VintfObject>(new VintfObject())) {}
739
740VintfObject::Builder& VintfObject::Builder::setFileSystem(std::unique_ptr<FileSystem>&& e) {
741 mObject->mFileSystem = std::move(e);
742 return *this;
743}
744
745VintfObject::Builder& VintfObject::Builder::setRuntimeInfoFactory(
746 std::unique_ptr<ObjectFactory<RuntimeInfo>>&& e) {
747 mObject->mRuntimeInfoFactory = std::move(e);
748 return *this;
749}
750
751VintfObject::Builder& VintfObject::Builder::setPropertyFetcher(
752 std::unique_ptr<PropertyFetcher>&& e) {
753 mObject->mPropertyFetcher = std::move(e);
754 return *this;
755}
756
757std::unique_ptr<VintfObject> VintfObject::Builder::build() {
758 if (!mObject->mFileSystem) mObject->mFileSystem = createDefaultFileSystem();
759 if (!mObject->mRuntimeInfoFactory)
760 mObject->mRuntimeInfoFactory = std::make_unique<ObjectFactory<RuntimeInfo>>();
761 if (!mObject->mPropertyFetcher) mObject->mPropertyFetcher = createDefaultPropertyFetcher();
762 return std::move(mObject);
763}
764
Yifan Hong3daec812017-02-27 18:49:11 -0800765} // namespace vintf
766} // namespace android