blob: b852665e53273974c12ce1accf003cfe1f05e893 [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"
20#include "parse_xml.h"
Yifan Hong8640cd12017-05-17 12:02:28 -070021#include "utils.h"
Yifan Hong143cfe62017-04-13 20:18:01 -070022
Yifan Hongd52bf3e2018-01-11 16:56:51 -080023#include <dirent.h>
24
Yifan Hong3daec812017-02-27 18:49:11 -080025#include <functional>
26#include <memory>
27#include <mutex>
28
Bowgo Tsai39adc142017-11-03 12:46:26 +080029#ifdef LIBVINTF_TARGET
30#include <android-base/properties.h>
31#endif
32
Yifan Hong60217032018-01-08 16:19:42 -080033#include <android-base/logging.h>
34
35using std::placeholders::_1;
36using std::placeholders::_2;
37
Yifan Hong3daec812017-02-27 18:49:11 -080038namespace android {
39namespace vintf {
40
Yifan Hong270b5652018-01-18 18:46:01 -080041using namespace details;
42
Yifan Hong3daec812017-02-27 18:49:11 -080043template <typename T>
Yifan Hongfc73edf2017-08-29 11:39:07 -070044struct LockedSharedPtr {
45 std::shared_ptr<T> object;
Yifan Hong3daec812017-02-27 18:49:11 -080046 std::mutex mutex;
Yifan Hong7219ba12018-01-08 16:23:49 -080047 bool fetchedOnce = false;
Yifan Hong3daec812017-02-27 18:49:11 -080048};
49
Yifan Hong1fb004e2017-09-26 15:04:44 -070050struct LockedRuntimeInfoCache {
51 std::shared_ptr<RuntimeInfo> object;
52 std::mutex mutex;
53 RuntimeInfo::FetchFlags fetchedFlags = RuntimeInfo::FetchFlag::NONE;
54};
55
Yifan Hong3daec812017-02-27 18:49:11 -080056template <typename T, typename F>
Yifan Hongfc73edf2017-08-29 11:39:07 -070057static std::shared_ptr<const T> Get(
58 LockedSharedPtr<T> *ptr,
Yifan Hong143cfe62017-04-13 20:18:01 -070059 bool skipCache,
Yifan Hong3daec812017-02-27 18:49:11 -080060 const F &fetchAllInformation) {
61 std::unique_lock<std::mutex> _lock(ptr->mutex);
Yifan Hong7219ba12018-01-08 16:23:49 -080062 if (skipCache || !ptr->fetchedOnce) {
Yifan Hong3daec812017-02-27 18:49:11 -080063 ptr->object = std::make_unique<T>();
Yifan Hong60217032018-01-08 16:19:42 -080064 std::string error;
65 if (fetchAllInformation(ptr->object.get(), &error) != OK) {
66 LOG(WARNING) << error;
Yifan Hong3daec812017-02-27 18:49:11 -080067 ptr->object = nullptr; // frees the old object
68 }
Yifan Hong7219ba12018-01-08 16:23:49 -080069 ptr->fetchedOnce = true;
Yifan Hong3daec812017-02-27 18:49:11 -080070 }
Yifan Hongfc73edf2017-08-29 11:39:07 -070071 return ptr->object;
Yifan Hong3daec812017-02-27 18:49:11 -080072}
73
74// static
Yifan Hongfc73edf2017-08-29 11:39:07 -070075std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCache) {
Steven Moreland648a0012017-10-19 21:23:41 -070076 static LockedSharedPtr<HalManifest> gVendorManifest;
Yifan Hong5a93bf22018-01-17 18:22:32 -080077 return Get(&gVendorManifest, skipCache, &VintfObject::FetchDeviceHalManifest);
Yifan Hong3daec812017-02-27 18:49:11 -080078}
79
80// static
Yifan Hongfc73edf2017-08-29 11:39:07 -070081std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) {
82 static LockedSharedPtr<HalManifest> gFrameworkManifest;
Yifan Hong143cfe62017-04-13 20:18:01 -070083 return Get(&gFrameworkManifest, skipCache,
Yifan Hong270b5652018-01-18 18:46:01 -080084 std::bind(&HalManifest::fetchAllInformation, _1, kSystemManifest, _2));
Yifan Hong3daec812017-02-27 18:49:11 -080085}
86
Yifan Hong2272bf82017-04-28 14:37:56 -070087
88// static
Yifan Hongfc73edf2017-08-29 11:39:07 -070089std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) {
90 static LockedSharedPtr<CompatibilityMatrix> gDeviceMatrix;
Yifan Hongb64ec9e2018-01-18 18:57:52 -080091 return Get(&gDeviceMatrix, skipCache, &VintfObject::FetchDeviceMatrix);
Yifan Hong2272bf82017-04-28 14:37:56 -070092}
93
94// static
Yifan Hongfc73edf2017-08-29 11:39:07 -070095std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) {
96 static LockedSharedPtr<CompatibilityMatrix> gFrameworkMatrix;
Yifan Hongd52bf3e2018-01-11 16:56:51 -080097 static LockedSharedPtr<CompatibilityMatrix> gCombinedFrameworkMatrix;
98 static std::mutex gFrameworkCompatibilityMatrixMutex;
99
100 // To avoid deadlock, get device manifest before any locks.
101 auto deviceManifest = GetDeviceHalManifest();
102
103 std::unique_lock<std::mutex> _lock(gFrameworkCompatibilityMatrixMutex);
104
105 auto combined =
106 Get(&gCombinedFrameworkMatrix, skipCache,
107 std::bind(&VintfObject::GetCombinedFrameworkMatrix, deviceManifest, _1, _2));
108 if (combined != nullptr) {
109 return combined;
110 }
111
Yifan Hong2272bf82017-04-28 14:37:56 -0700112 return Get(&gFrameworkMatrix, skipCache,
Yifan Hong270b5652018-01-18 18:46:01 -0800113 std::bind(&CompatibilityMatrix::fetchAllInformation, _1, kSystemLegacyMatrix, _2));
Yifan Hong2272bf82017-04-28 14:37:56 -0700114}
115
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800116status_t VintfObject::GetCombinedFrameworkMatrix(
117 const std::shared_ptr<const HalManifest>& deviceManifest, CompatibilityMatrix* out,
118 std::string* error) {
119 auto matrixFragments = GetAllFrameworkMatrixLevels(error);
120 if (matrixFragments.empty()) {
121 return NAME_NOT_FOUND;
122 }
123
124 Level deviceLevel = Level::UNSPECIFIED;
125
126 if (deviceManifest != nullptr) {
127 deviceLevel = deviceManifest->level();
128 }
129
130 // TODO(b/70628538): Do not infer from Shipping API level.
131#ifdef LIBVINTF_TARGET
132 if (deviceLevel == Level::UNSPECIFIED) {
133 auto shippingApi =
134 android::base::GetUintProperty<uint64_t>("ro.product.first_api_level", 0u);
135 if (shippingApi != 0u) {
136 deviceLevel = details::convertFromApiLevel(shippingApi);
137 }
138 }
139#endif
140
141 if (deviceLevel == Level::UNSPECIFIED) {
142 // Cannot infer FCM version. Combine all matrices by assuming
143 // Shipping FCM Version == min(all supported FCM Versions in the framework)
144 for (auto&& pair : matrixFragments) {
145 Level fragmentLevel = pair.object.level();
146 if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) {
147 deviceLevel = fragmentLevel;
148 }
149 }
150 }
151
152 if (deviceLevel == Level::UNSPECIFIED) {
153 // None of the fragments specify any FCM version. Should never happen except
154 // for inconsistent builds.
155 if (error) {
Yifan Hong270b5652018-01-18 18:46:01 -0800156 *error = "No framework compatibility matrix files under " + kSystemVintfDir +
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800157 " declare FCM version.";
158 }
159 return NAME_NOT_FOUND;
160 }
161
162 CompatibilityMatrix* combined =
163 CompatibilityMatrix::combine(deviceLevel, &matrixFragments, error);
164 if (combined == nullptr) {
165 return BAD_VALUE;
166 }
167 *out = std::move(*combined);
168 return OK;
169}
170
Yifan Hong5a93bf22018-01-17 18:22:32 -0800171// Priority for loading vendor manifest:
172// 1. If {sku} sysprop is set and both files exist,
Yifan Hongccbea052018-01-18 18:48:46 -0800173// /vendor/etc/vintf/manifest.xml + /odm/etc/manifest_{sku}.xml
Yifan Hong5a93bf22018-01-17 18:22:32 -0800174// 2. If both files exist,
Yifan Hongccbea052018-01-18 18:48:46 -0800175// /vendor/etc/vintf/manifest.xml + /odm/etc/manifest.xml
176// 3. If file exists, /vendor/etc/vintf/manifest.xml
Yifan Hong5a93bf22018-01-17 18:22:32 -0800177// 4. If {sku} sysprop is set and file exists,
178// /odm/etc/manifest_{sku}.xml
179// 5. If file exists, /odm/etc/manifest.xml
180// 6. If file exists, /vendor/manifest.xml
181// where:
182// {sku} is the value of ro.boot.product.hardware.sku
183// A + B means adding <hal> tags from B to A (so that <hal>s from B can override A)
184status_t VintfObject::FetchDeviceHalManifest(HalManifest* out, std::string* error) {
185 // fetchAllInformation returns NAME_NOT_FOUND if file is missing.
186 HalManifest vendorManifest;
Yifan Hong270b5652018-01-18 18:46:01 -0800187 status_t vendorStatus = vendorManifest.fetchAllInformation(kVendorManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800188 if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) {
189 return vendorStatus;
190 }
191
192 HalManifest odmManifest;
193 status_t odmStatus = NAME_NOT_FOUND;
194
195#ifdef LIBVINTF_TARGET
196 std::string productModel = android::base::GetProperty("ro.boot.product.hardware.sku", "");
197 if (!productModel.empty()) {
Yifan Hong270b5652018-01-18 18:46:01 -0800198 odmStatus = odmManifest.fetchAllInformation(
199 kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800200 if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
201 return odmStatus;
202 }
203 }
204#endif
205
206 if (odmStatus == NAME_NOT_FOUND) {
Yifan Hong270b5652018-01-18 18:46:01 -0800207 odmStatus = odmManifest.fetchAllInformation(kOdmLegacyManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800208 if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
209 return odmStatus;
210 }
211 }
212
213 // Both files exist. Use vendor manifest as base manifest and let ODM manifest override it.
214 if (vendorStatus == OK && odmStatus == OK) {
215 *out = std::move(vendorManifest);
216 out->addAllHals(&odmManifest);
217 return OK;
218 }
219
220 // Only vendor manifest exists. Use it.
221 if (vendorStatus == OK) {
222 *out = std::move(vendorManifest);
223 return OK;
224 }
225
226 // Only ODM manifest exists. use it.
227 if (odmStatus == OK) {
228 *out = std::move(odmManifest);
229 return OK;
230 }
231
232 // Use legacy /vendor/manifest.xml
Yifan Hong270b5652018-01-18 18:46:01 -0800233 return out->fetchAllInformation(kVendorLegacyManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800234}
235
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800236status_t VintfObject::FetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) {
237 CompatibilityMatrix etcMatrix;
238 if (etcMatrix.fetchAllInformation(kVendorMatrix, error) == OK) {
239 *out = std::move(etcMatrix);
240 return OK;
241 }
242 return out->fetchAllInformation(kVendorLegacyMatrix, error);
243}
244
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800245std::vector<Named<CompatibilityMatrix>> VintfObject::GetAllFrameworkMatrixLevels(
246 std::string* error) {
247 std::vector<std::string> fileNames;
248 std::vector<Named<CompatibilityMatrix>> results;
249
Yifan Hong270b5652018-01-18 18:46:01 -0800250 if (details::gFetcher->listFiles(kSystemVintfDir, &fileNames, error) != OK) {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800251 return {};
252 }
253 for (const std::string& fileName : fileNames) {
Yifan Hong270b5652018-01-18 18:46:01 -0800254 std::string path = kSystemVintfDir + fileName;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800255
256 std::string content;
257 std::string fetchError;
258 status_t status = details::gFetcher->fetch(path, content, &fetchError);
259 if (status != OK) {
260 if (error) {
261 *error += "Ignore file " + path + ": " + fetchError + "\n";
262 }
263 continue;
264 }
265
266 auto it = results.emplace(results.end());
267 if (!gCompatibilityMatrixConverter(&it->object, content)) {
268 if (error) {
269 // TODO(b/71874788): do not use lastError() because it is not thread-safe.
270 *error +=
271 "Ignore file " + path + ": " + gCompatibilityMatrixConverter.lastError() + "\n";
272 }
273 results.erase(it);
274 continue;
275 }
276 }
277
278 if (results.empty()) {
279 if (error) {
Yifan Hong270b5652018-01-18 18:46:01 -0800280 *error = "No framework matrices under " + kSystemVintfDir +
281 " can be fetched or parsed.\n" + *error;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800282 }
283 } else {
284 if (error && !error->empty()) {
285 LOG(WARNING) << *error;
286 *error = "";
287 }
288 }
289
290 return results;
291}
292
Yifan Hong3daec812017-02-27 18:49:11 -0800293// static
Yifan Hong1fb004e2017-09-26 15:04:44 -0700294std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache,
295 RuntimeInfo::FetchFlags flags) {
296 static LockedRuntimeInfoCache gDeviceRuntimeInfo;
297 std::unique_lock<std::mutex> _lock(gDeviceRuntimeInfo.mutex);
298
299 if (!skipCache) {
300 flags &= (~gDeviceRuntimeInfo.fetchedFlags);
301 }
302
303 if (gDeviceRuntimeInfo.object == nullptr) {
Yifan Hong29bb2d42017-09-27 13:28:00 -0700304 gDeviceRuntimeInfo.object = details::gRuntimeInfoFactory->make_shared();
Yifan Hong1fb004e2017-09-26 15:04:44 -0700305 }
306
307 status_t status = gDeviceRuntimeInfo.object->fetchAllInformation(flags);
308 if (status != OK) {
309 gDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched"
310 return nullptr;
311 }
312
313 gDeviceRuntimeInfo.fetchedFlags |= flags;
314 return gDeviceRuntimeInfo.object;
Yifan Hong3daec812017-02-27 18:49:11 -0800315}
316
Yifan Hong143cfe62017-04-13 20:18:01 -0700317namespace details {
318
Yifan Hong143cfe62017-04-13 20:18:01 -0700319enum class ParseStatus {
320 OK,
321 PARSE_ERROR,
322 DUPLICATED_FWK_ENTRY,
323 DUPLICATED_DEV_ENTRY,
324};
325
Yifan Hong9532bd22017-04-14 15:30:52 -0700326static std::string toString(ParseStatus status) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700327 switch(status) {
328 case ParseStatus::OK: return "OK";
329 case ParseStatus::PARSE_ERROR: return "parse error";
330 case ParseStatus::DUPLICATED_FWK_ENTRY: return "duplicated framework";
331 case ParseStatus::DUPLICATED_DEV_ENTRY: return "duplicated device";
332 }
333 return "";
334}
335
336template<typename T>
Yifan Hong9532bd22017-04-14 15:30:52 -0700337static ParseStatus tryParse(const std::string &xml, const XmlConverter<T> &parse,
Yifan Hongfc73edf2017-08-29 11:39:07 -0700338 std::shared_ptr<T> *fwk, std::shared_ptr<T> *dev) {
339 std::shared_ptr<T> ret = std::make_shared<T>();
Yifan Hong143cfe62017-04-13 20:18:01 -0700340 if (!parse(ret.get(), xml)) {
341 return ParseStatus::PARSE_ERROR;
342 }
343 if (ret->type() == SchemaType::FRAMEWORK) {
344 if (fwk->get() != nullptr) {
345 return ParseStatus::DUPLICATED_FWK_ENTRY;
346 }
347 *fwk = std::move(ret);
348 } else if (ret->type() == SchemaType::DEVICE) {
349 if (dev->get() != nullptr) {
350 return ParseStatus::DUPLICATED_DEV_ENTRY;
351 }
352 *dev = std::move(ret);
353 }
354 return ParseStatus::OK;
355}
356
357template<typename T, typename GetFunction>
Yifan Hongfc73edf2017-08-29 11:39:07 -0700358static status_t getMissing(const std::shared_ptr<T>& pkg, bool mount,
Yifan Hong143cfe62017-04-13 20:18:01 -0700359 std::function<status_t(void)> mountFunction,
Yifan Hongfc73edf2017-08-29 11:39:07 -0700360 std::shared_ptr<const T>* updated,
Yifan Hong143cfe62017-04-13 20:18:01 -0700361 GetFunction getFunction) {
362 if (pkg != nullptr) {
363 *updated = pkg;
364 } else {
365 if (mount) {
366 (void)mountFunction(); // ignore mount errors
367 }
368 *updated = getFunction();
369 }
370 return OK;
371}
372
373#define ADD_MESSAGE(__error__) \
374 if (error != nullptr) { \
375 *error += (__error__); \
376 } \
377
378struct PackageInfo {
379 struct Pair {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700380 std::shared_ptr<HalManifest> manifest;
381 std::shared_ptr<CompatibilityMatrix> matrix;
Yifan Hong143cfe62017-04-13 20:18:01 -0700382 };
383 Pair dev;
384 Pair fwk;
385};
386
387struct UpdatedInfo {
388 struct Pair {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700389 std::shared_ptr<const HalManifest> manifest;
390 std::shared_ptr<const CompatibilityMatrix> matrix;
Yifan Hong143cfe62017-04-13 20:18:01 -0700391 };
392 Pair dev;
393 Pair fwk;
Yifan Hongfc73edf2017-08-29 11:39:07 -0700394 std::shared_ptr<const RuntimeInfo> runtimeInfo;
Yifan Hong143cfe62017-04-13 20:18:01 -0700395};
396
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700397// Checks given compatibility info against info on the device. If no
398// compatability info is given then the device info will be checked against
399// itself.
Yifan Hongdb6423e2017-09-11 14:38:46 -0700400int32_t checkCompatibility(const std::vector<std::string>& xmls, bool mount,
401 const PartitionMounter& mounter, std::string* error,
402 DisabledChecks disabledChecks) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700403 status_t status;
404 ParseStatus parseStatus;
405 PackageInfo pkg; // All information from package.
406 UpdatedInfo updated; // All files and runtime info after the update.
407
Yifan Hong143cfe62017-04-13 20:18:01 -0700408 // parse all information from package
409 for (const auto &xml : xmls) {
410 parseStatus = tryParse(xml, gHalManifestConverter, &pkg.fwk.manifest, &pkg.dev.manifest);
411 if (parseStatus == ParseStatus::OK) {
412 continue; // work on next one
413 }
414 if (parseStatus != ParseStatus::PARSE_ERROR) {
415 ADD_MESSAGE(toString(parseStatus) + " manifest");
416 return ALREADY_EXISTS;
417 }
418 parseStatus = tryParse(xml, gCompatibilityMatrixConverter, &pkg.fwk.matrix, &pkg.dev.matrix);
419 if (parseStatus == ParseStatus::OK) {
420 continue; // work on next one
421 }
422 if (parseStatus != ParseStatus::PARSE_ERROR) {
423 ADD_MESSAGE(toString(parseStatus) + " matrix");
424 return ALREADY_EXISTS;
425 }
426 ADD_MESSAGE(toString(parseStatus)); // parse error
427 return BAD_VALUE;
428 }
429
430 // get missing info from device
Yifan Hong8640cd12017-05-17 12:02:28 -0700431 // use functions instead of std::bind because std::bind doesn't work well with mock objects
432 auto mountSystem = [&mounter] { return mounter.mountSystem(); };
433 auto mountVendor = [&mounter] { return mounter.mountVendor(); };
434 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700435 pkg.fwk.manifest, mount, mountSystem, &updated.fwk.manifest,
Yifan Hong8640cd12017-05-17 12:02:28 -0700436 std::bind(VintfObject::GetFrameworkHalManifest, true /* skipCache */))) != OK) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700437 return status;
438 }
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700439 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700440 pkg.dev.manifest, mount, mountVendor, &updated.dev.manifest,
Yifan Hong8640cd12017-05-17 12:02:28 -0700441 std::bind(VintfObject::GetDeviceHalManifest, true /* skipCache */))) != OK) {
442 return status;
443 }
444 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700445 pkg.fwk.matrix, mount, mountSystem, &updated.fwk.matrix,
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700446 std::bind(VintfObject::GetFrameworkCompatibilityMatrix, true /* skipCache */))) !=
447 OK) {
448 return status;
449 }
450 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700451 pkg.dev.matrix, mount, mountVendor, &updated.dev.matrix,
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700452 std::bind(VintfObject::GetDeviceCompatibilityMatrix, true /* skipCache */))) != OK) {
453 return status;
454 }
Yifan Hong8640cd12017-05-17 12:02:28 -0700455
456 if (mount) {
457 (void)mounter.umountSystem(); // ignore errors
458 (void)mounter.umountVendor(); // ignore errors
459 }
460
461 updated.runtimeInfo = VintfObject::GetRuntimeInfo(true /* skipCache */);
Yifan Hong143cfe62017-04-13 20:18:01 -0700462
463 // null checks for files and runtime info after the update
464 // TODO(b/37321309) if a compat mat is missing, it is not matched and considered compatible.
465 if (updated.fwk.manifest == nullptr) {
466 ADD_MESSAGE("No framework manifest file from device or from update package");
467 return NO_INIT;
468 }
469 if (updated.dev.manifest == nullptr) {
470 ADD_MESSAGE("No device manifest file from device or from update package");
471 return NO_INIT;
472 }
473 if (updated.fwk.matrix == nullptr) {
474 ADD_MESSAGE("No framework matrix, skipping;");
475 // TODO(b/37321309) consider missing matricies as errors.
476 }
477 if (updated.dev.matrix == nullptr) {
478 ADD_MESSAGE("No device matrix, skipping;");
479 // TODO(b/37321309) consider missing matricies as errors.
480 }
481 if (updated.runtimeInfo == nullptr) {
482 ADD_MESSAGE("No runtime info from device");
483 return NO_INIT;
484 }
485
486 // compatiblity check.
487 // TODO(b/37321309) outer if checks can be removed if we consider missing matrices as errors.
488 if (updated.dev.manifest && updated.fwk.matrix) {
489 if (!updated.dev.manifest->checkCompatibility(*updated.fwk.matrix, error)) {
Yifan Hong0d4be122017-05-15 17:04:22 -0700490 if (error)
491 error->insert(0, "Device manifest and framework compatibility matrix "
492 "are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700493 return INCOMPATIBLE;
494 }
495 }
496 if (updated.fwk.manifest && updated.dev.matrix) {
497 if (!updated.fwk.manifest->checkCompatibility(*updated.dev.matrix, error)) {
Yifan Hong0d4be122017-05-15 17:04:22 -0700498 if (error)
499 error->insert(0, "Framework manifest and device compatibility matrix "
500 "are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700501 return INCOMPATIBLE;
502 }
503 }
504 if (updated.runtimeInfo && updated.fwk.matrix) {
Yifan Hongdb6423e2017-09-11 14:38:46 -0700505 if (!updated.runtimeInfo->checkCompatibility(*updated.fwk.matrix, error, disabledChecks)) {
Yifan Hong0d4be122017-05-15 17:04:22 -0700506 if (error)
507 error->insert(0, "Runtime info and framework compatibility matrix "
508 "are incompatible: ");
Yifan Honge8b86842017-05-25 17:59:22 +0000509 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700510 }
511 }
512
513 return COMPATIBLE;
514}
515
Yifan Hong270b5652018-01-18 18:46:01 -0800516const std::string kSystemVintfDir = "/system/etc/vintf/";
Yifan Hongccbea052018-01-18 18:48:46 -0800517const std::string kVendorVintfDir = "/vendor/etc/vintf/";
Yifan Hong270b5652018-01-18 18:46:01 -0800518
519const std::string kVendorManifest = kVendorVintfDir + "manifest.xml";
Yifan Honga5ddddf2018-01-18 18:50:13 -0800520const std::string kSystemManifest = kSystemVintfDir + "manifest.xml";
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800521const std::string kVendorMatrix = kVendorVintfDir + "compatibility_matrix.xml";
Yifan Hong270b5652018-01-18 18:46:01 -0800522
523const std::string kVendorLegacyManifest = "/vendor/manifest.xml";
524const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml";
525const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml";
526const std::string kOdmLegacyVintfDir = "/odm/etc/";
527const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml";
528
Yifan Hong143cfe62017-04-13 20:18:01 -0700529} // namespace details
530
Yifan Hongfbbf0472017-04-07 18:14:18 -0700531// static
Yifan Hongdb6423e2017-09-11 14:38:46 -0700532int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error,
533 DisabledChecks disabledChecks) {
534 return details::checkCompatibility(xmls, false /* mount */, *details::gPartitionMounter, error,
535 disabledChecks);
Yifan Hongfbbf0472017-04-07 18:14:18 -0700536}
537
Yifan Hong3daec812017-02-27 18:49:11 -0800538
539} // namespace vintf
540} // namespace android