blob: 4a3e235674594ae38e7503fe702354b97f871d7e [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 Hong2272bf82017-04-28 14:37:56 -070091 return Get(&gDeviceMatrix, skipCache,
Yifan Hong270b5652018-01-18 18:46:01 -080092 std::bind(&CompatibilityMatrix::fetchAllInformation, _1, kVendorLegacyMatrix, _2));
Yifan Hong2272bf82017-04-28 14:37:56 -070093}
94
95// static
Yifan Hongfc73edf2017-08-29 11:39:07 -070096std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) {
97 static LockedSharedPtr<CompatibilityMatrix> gFrameworkMatrix;
Yifan Hongd52bf3e2018-01-11 16:56:51 -080098 static LockedSharedPtr<CompatibilityMatrix> gCombinedFrameworkMatrix;
99 static std::mutex gFrameworkCompatibilityMatrixMutex;
100
101 // To avoid deadlock, get device manifest before any locks.
102 auto deviceManifest = GetDeviceHalManifest();
103
104 std::unique_lock<std::mutex> _lock(gFrameworkCompatibilityMatrixMutex);
105
106 auto combined =
107 Get(&gCombinedFrameworkMatrix, skipCache,
108 std::bind(&VintfObject::GetCombinedFrameworkMatrix, deviceManifest, _1, _2));
109 if (combined != nullptr) {
110 return combined;
111 }
112
Yifan Hong2272bf82017-04-28 14:37:56 -0700113 return Get(&gFrameworkMatrix, skipCache,
Yifan Hong270b5652018-01-18 18:46:01 -0800114 std::bind(&CompatibilityMatrix::fetchAllInformation, _1, kSystemLegacyMatrix, _2));
Yifan Hong2272bf82017-04-28 14:37:56 -0700115}
116
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800117status_t VintfObject::GetCombinedFrameworkMatrix(
118 const std::shared_ptr<const HalManifest>& deviceManifest, CompatibilityMatrix* out,
119 std::string* error) {
120 auto matrixFragments = GetAllFrameworkMatrixLevels(error);
121 if (matrixFragments.empty()) {
122 return NAME_NOT_FOUND;
123 }
124
125 Level deviceLevel = Level::UNSPECIFIED;
126
127 if (deviceManifest != nullptr) {
128 deviceLevel = deviceManifest->level();
129 }
130
131 // TODO(b/70628538): Do not infer from Shipping API level.
132#ifdef LIBVINTF_TARGET
133 if (deviceLevel == Level::UNSPECIFIED) {
134 auto shippingApi =
135 android::base::GetUintProperty<uint64_t>("ro.product.first_api_level", 0u);
136 if (shippingApi != 0u) {
137 deviceLevel = details::convertFromApiLevel(shippingApi);
138 }
139 }
140#endif
141
142 if (deviceLevel == Level::UNSPECIFIED) {
143 // Cannot infer FCM version. Combine all matrices by assuming
144 // Shipping FCM Version == min(all supported FCM Versions in the framework)
145 for (auto&& pair : matrixFragments) {
146 Level fragmentLevel = pair.object.level();
147 if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) {
148 deviceLevel = fragmentLevel;
149 }
150 }
151 }
152
153 if (deviceLevel == Level::UNSPECIFIED) {
154 // None of the fragments specify any FCM version. Should never happen except
155 // for inconsistent builds.
156 if (error) {
Yifan Hong270b5652018-01-18 18:46:01 -0800157 *error = "No framework compatibility matrix files under " + kSystemVintfDir +
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800158 " declare FCM version.";
159 }
160 return NAME_NOT_FOUND;
161 }
162
163 CompatibilityMatrix* combined =
164 CompatibilityMatrix::combine(deviceLevel, &matrixFragments, error);
165 if (combined == nullptr) {
166 return BAD_VALUE;
167 }
168 *out = std::move(*combined);
169 return OK;
170}
171
Yifan Hong5a93bf22018-01-17 18:22:32 -0800172// Priority for loading vendor manifest:
173// 1. If {sku} sysprop is set and both files exist,
Yifan Hongccbea052018-01-18 18:48:46 -0800174// /vendor/etc/vintf/manifest.xml + /odm/etc/manifest_{sku}.xml
Yifan Hong5a93bf22018-01-17 18:22:32 -0800175// 2. If both files exist,
Yifan Hongccbea052018-01-18 18:48:46 -0800176// /vendor/etc/vintf/manifest.xml + /odm/etc/manifest.xml
177// 3. If file exists, /vendor/etc/vintf/manifest.xml
Yifan Hong5a93bf22018-01-17 18:22:32 -0800178// 4. If {sku} sysprop is set and file exists,
179// /odm/etc/manifest_{sku}.xml
180// 5. If file exists, /odm/etc/manifest.xml
181// 6. If file exists, /vendor/manifest.xml
182// where:
183// {sku} is the value of ro.boot.product.hardware.sku
184// A + B means adding <hal> tags from B to A (so that <hal>s from B can override A)
185status_t VintfObject::FetchDeviceHalManifest(HalManifest* out, std::string* error) {
186 // fetchAllInformation returns NAME_NOT_FOUND if file is missing.
187 HalManifest vendorManifest;
Yifan Hong270b5652018-01-18 18:46:01 -0800188 status_t vendorStatus = vendorManifest.fetchAllInformation(kVendorManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800189 if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) {
190 return vendorStatus;
191 }
192
193 HalManifest odmManifest;
194 status_t odmStatus = NAME_NOT_FOUND;
195
196#ifdef LIBVINTF_TARGET
197 std::string productModel = android::base::GetProperty("ro.boot.product.hardware.sku", "");
198 if (!productModel.empty()) {
Yifan Hong270b5652018-01-18 18:46:01 -0800199 odmStatus = odmManifest.fetchAllInformation(
200 kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800201 if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
202 return odmStatus;
203 }
204 }
205#endif
206
207 if (odmStatus == NAME_NOT_FOUND) {
Yifan Hong270b5652018-01-18 18:46:01 -0800208 odmStatus = odmManifest.fetchAllInformation(kOdmLegacyManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800209 if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
210 return odmStatus;
211 }
212 }
213
214 // Both files exist. Use vendor manifest as base manifest and let ODM manifest override it.
215 if (vendorStatus == OK && odmStatus == OK) {
216 *out = std::move(vendorManifest);
217 out->addAllHals(&odmManifest);
218 return OK;
219 }
220
221 // Only vendor manifest exists. Use it.
222 if (vendorStatus == OK) {
223 *out = std::move(vendorManifest);
224 return OK;
225 }
226
227 // Only ODM manifest exists. use it.
228 if (odmStatus == OK) {
229 *out = std::move(odmManifest);
230 return OK;
231 }
232
233 // Use legacy /vendor/manifest.xml
Yifan Hong270b5652018-01-18 18:46:01 -0800234 return out->fetchAllInformation(kVendorLegacyManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800235}
236
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800237std::vector<Named<CompatibilityMatrix>> VintfObject::GetAllFrameworkMatrixLevels(
238 std::string* error) {
239 std::vector<std::string> fileNames;
240 std::vector<Named<CompatibilityMatrix>> results;
241
Yifan Hong270b5652018-01-18 18:46:01 -0800242 if (details::gFetcher->listFiles(kSystemVintfDir, &fileNames, error) != OK) {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800243 return {};
244 }
245 for (const std::string& fileName : fileNames) {
Yifan Hong270b5652018-01-18 18:46:01 -0800246 std::string path = kSystemVintfDir + fileName;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800247
248 std::string content;
249 std::string fetchError;
250 status_t status = details::gFetcher->fetch(path, content, &fetchError);
251 if (status != OK) {
252 if (error) {
253 *error += "Ignore file " + path + ": " + fetchError + "\n";
254 }
255 continue;
256 }
257
258 auto it = results.emplace(results.end());
259 if (!gCompatibilityMatrixConverter(&it->object, content)) {
260 if (error) {
261 // TODO(b/71874788): do not use lastError() because it is not thread-safe.
262 *error +=
263 "Ignore file " + path + ": " + gCompatibilityMatrixConverter.lastError() + "\n";
264 }
265 results.erase(it);
266 continue;
267 }
268 }
269
270 if (results.empty()) {
271 if (error) {
Yifan Hong270b5652018-01-18 18:46:01 -0800272 *error = "No framework matrices under " + kSystemVintfDir +
273 " can be fetched or parsed.\n" + *error;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800274 }
275 } else {
276 if (error && !error->empty()) {
277 LOG(WARNING) << *error;
278 *error = "";
279 }
280 }
281
282 return results;
283}
284
Yifan Hong3daec812017-02-27 18:49:11 -0800285// static
Yifan Hong1fb004e2017-09-26 15:04:44 -0700286std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache,
287 RuntimeInfo::FetchFlags flags) {
288 static LockedRuntimeInfoCache gDeviceRuntimeInfo;
289 std::unique_lock<std::mutex> _lock(gDeviceRuntimeInfo.mutex);
290
291 if (!skipCache) {
292 flags &= (~gDeviceRuntimeInfo.fetchedFlags);
293 }
294
295 if (gDeviceRuntimeInfo.object == nullptr) {
Yifan Hong29bb2d42017-09-27 13:28:00 -0700296 gDeviceRuntimeInfo.object = details::gRuntimeInfoFactory->make_shared();
Yifan Hong1fb004e2017-09-26 15:04:44 -0700297 }
298
299 status_t status = gDeviceRuntimeInfo.object->fetchAllInformation(flags);
300 if (status != OK) {
301 gDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched"
302 return nullptr;
303 }
304
305 gDeviceRuntimeInfo.fetchedFlags |= flags;
306 return gDeviceRuntimeInfo.object;
Yifan Hong3daec812017-02-27 18:49:11 -0800307}
308
Yifan Hong143cfe62017-04-13 20:18:01 -0700309namespace details {
310
Yifan Hong143cfe62017-04-13 20:18:01 -0700311enum class ParseStatus {
312 OK,
313 PARSE_ERROR,
314 DUPLICATED_FWK_ENTRY,
315 DUPLICATED_DEV_ENTRY,
316};
317
Yifan Hong9532bd22017-04-14 15:30:52 -0700318static std::string toString(ParseStatus status) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700319 switch(status) {
320 case ParseStatus::OK: return "OK";
321 case ParseStatus::PARSE_ERROR: return "parse error";
322 case ParseStatus::DUPLICATED_FWK_ENTRY: return "duplicated framework";
323 case ParseStatus::DUPLICATED_DEV_ENTRY: return "duplicated device";
324 }
325 return "";
326}
327
328template<typename T>
Yifan Hong9532bd22017-04-14 15:30:52 -0700329static ParseStatus tryParse(const std::string &xml, const XmlConverter<T> &parse,
Yifan Hongfc73edf2017-08-29 11:39:07 -0700330 std::shared_ptr<T> *fwk, std::shared_ptr<T> *dev) {
331 std::shared_ptr<T> ret = std::make_shared<T>();
Yifan Hong143cfe62017-04-13 20:18:01 -0700332 if (!parse(ret.get(), xml)) {
333 return ParseStatus::PARSE_ERROR;
334 }
335 if (ret->type() == SchemaType::FRAMEWORK) {
336 if (fwk->get() != nullptr) {
337 return ParseStatus::DUPLICATED_FWK_ENTRY;
338 }
339 *fwk = std::move(ret);
340 } else if (ret->type() == SchemaType::DEVICE) {
341 if (dev->get() != nullptr) {
342 return ParseStatus::DUPLICATED_DEV_ENTRY;
343 }
344 *dev = std::move(ret);
345 }
346 return ParseStatus::OK;
347}
348
349template<typename T, typename GetFunction>
Yifan Hongfc73edf2017-08-29 11:39:07 -0700350static status_t getMissing(const std::shared_ptr<T>& pkg, bool mount,
Yifan Hong143cfe62017-04-13 20:18:01 -0700351 std::function<status_t(void)> mountFunction,
Yifan Hongfc73edf2017-08-29 11:39:07 -0700352 std::shared_ptr<const T>* updated,
Yifan Hong143cfe62017-04-13 20:18:01 -0700353 GetFunction getFunction) {
354 if (pkg != nullptr) {
355 *updated = pkg;
356 } else {
357 if (mount) {
358 (void)mountFunction(); // ignore mount errors
359 }
360 *updated = getFunction();
361 }
362 return OK;
363}
364
365#define ADD_MESSAGE(__error__) \
366 if (error != nullptr) { \
367 *error += (__error__); \
368 } \
369
370struct PackageInfo {
371 struct Pair {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700372 std::shared_ptr<HalManifest> manifest;
373 std::shared_ptr<CompatibilityMatrix> matrix;
Yifan Hong143cfe62017-04-13 20:18:01 -0700374 };
375 Pair dev;
376 Pair fwk;
377};
378
379struct UpdatedInfo {
380 struct Pair {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700381 std::shared_ptr<const HalManifest> manifest;
382 std::shared_ptr<const CompatibilityMatrix> matrix;
Yifan Hong143cfe62017-04-13 20:18:01 -0700383 };
384 Pair dev;
385 Pair fwk;
Yifan Hongfc73edf2017-08-29 11:39:07 -0700386 std::shared_ptr<const RuntimeInfo> runtimeInfo;
Yifan Hong143cfe62017-04-13 20:18:01 -0700387};
388
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700389// Checks given compatibility info against info on the device. If no
390// compatability info is given then the device info will be checked against
391// itself.
Yifan Hongdb6423e2017-09-11 14:38:46 -0700392int32_t checkCompatibility(const std::vector<std::string>& xmls, bool mount,
393 const PartitionMounter& mounter, std::string* error,
394 DisabledChecks disabledChecks) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700395 status_t status;
396 ParseStatus parseStatus;
397 PackageInfo pkg; // All information from package.
398 UpdatedInfo updated; // All files and runtime info after the update.
399
Yifan Hong143cfe62017-04-13 20:18:01 -0700400 // parse all information from package
401 for (const auto &xml : xmls) {
402 parseStatus = tryParse(xml, gHalManifestConverter, &pkg.fwk.manifest, &pkg.dev.manifest);
403 if (parseStatus == ParseStatus::OK) {
404 continue; // work on next one
405 }
406 if (parseStatus != ParseStatus::PARSE_ERROR) {
407 ADD_MESSAGE(toString(parseStatus) + " manifest");
408 return ALREADY_EXISTS;
409 }
410 parseStatus = tryParse(xml, gCompatibilityMatrixConverter, &pkg.fwk.matrix, &pkg.dev.matrix);
411 if (parseStatus == ParseStatus::OK) {
412 continue; // work on next one
413 }
414 if (parseStatus != ParseStatus::PARSE_ERROR) {
415 ADD_MESSAGE(toString(parseStatus) + " matrix");
416 return ALREADY_EXISTS;
417 }
418 ADD_MESSAGE(toString(parseStatus)); // parse error
419 return BAD_VALUE;
420 }
421
422 // get missing info from device
Yifan Hong8640cd12017-05-17 12:02:28 -0700423 // use functions instead of std::bind because std::bind doesn't work well with mock objects
424 auto mountSystem = [&mounter] { return mounter.mountSystem(); };
425 auto mountVendor = [&mounter] { return mounter.mountVendor(); };
426 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700427 pkg.fwk.manifest, mount, mountSystem, &updated.fwk.manifest,
Yifan Hong8640cd12017-05-17 12:02:28 -0700428 std::bind(VintfObject::GetFrameworkHalManifest, true /* skipCache */))) != OK) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700429 return status;
430 }
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700431 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700432 pkg.dev.manifest, mount, mountVendor, &updated.dev.manifest,
Yifan Hong8640cd12017-05-17 12:02:28 -0700433 std::bind(VintfObject::GetDeviceHalManifest, true /* skipCache */))) != OK) {
434 return status;
435 }
436 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700437 pkg.fwk.matrix, mount, mountSystem, &updated.fwk.matrix,
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700438 std::bind(VintfObject::GetFrameworkCompatibilityMatrix, true /* skipCache */))) !=
439 OK) {
440 return status;
441 }
442 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700443 pkg.dev.matrix, mount, mountVendor, &updated.dev.matrix,
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700444 std::bind(VintfObject::GetDeviceCompatibilityMatrix, true /* skipCache */))) != OK) {
445 return status;
446 }
Yifan Hong8640cd12017-05-17 12:02:28 -0700447
448 if (mount) {
449 (void)mounter.umountSystem(); // ignore errors
450 (void)mounter.umountVendor(); // ignore errors
451 }
452
453 updated.runtimeInfo = VintfObject::GetRuntimeInfo(true /* skipCache */);
Yifan Hong143cfe62017-04-13 20:18:01 -0700454
455 // null checks for files and runtime info after the update
456 // TODO(b/37321309) if a compat mat is missing, it is not matched and considered compatible.
457 if (updated.fwk.manifest == nullptr) {
458 ADD_MESSAGE("No framework manifest file from device or from update package");
459 return NO_INIT;
460 }
461 if (updated.dev.manifest == nullptr) {
462 ADD_MESSAGE("No device manifest file from device or from update package");
463 return NO_INIT;
464 }
465 if (updated.fwk.matrix == nullptr) {
466 ADD_MESSAGE("No framework matrix, skipping;");
467 // TODO(b/37321309) consider missing matricies as errors.
468 }
469 if (updated.dev.matrix == nullptr) {
470 ADD_MESSAGE("No device matrix, skipping;");
471 // TODO(b/37321309) consider missing matricies as errors.
472 }
473 if (updated.runtimeInfo == nullptr) {
474 ADD_MESSAGE("No runtime info from device");
475 return NO_INIT;
476 }
477
478 // compatiblity check.
479 // TODO(b/37321309) outer if checks can be removed if we consider missing matrices as errors.
480 if (updated.dev.manifest && updated.fwk.matrix) {
481 if (!updated.dev.manifest->checkCompatibility(*updated.fwk.matrix, error)) {
Yifan Hong0d4be122017-05-15 17:04:22 -0700482 if (error)
483 error->insert(0, "Device manifest and framework compatibility matrix "
484 "are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700485 return INCOMPATIBLE;
486 }
487 }
488 if (updated.fwk.manifest && updated.dev.matrix) {
489 if (!updated.fwk.manifest->checkCompatibility(*updated.dev.matrix, error)) {
Yifan Hong0d4be122017-05-15 17:04:22 -0700490 if (error)
491 error->insert(0, "Framework manifest and device compatibility matrix "
492 "are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700493 return INCOMPATIBLE;
494 }
495 }
496 if (updated.runtimeInfo && updated.fwk.matrix) {
Yifan Hongdb6423e2017-09-11 14:38:46 -0700497 if (!updated.runtimeInfo->checkCompatibility(*updated.fwk.matrix, error, disabledChecks)) {
Yifan Hong0d4be122017-05-15 17:04:22 -0700498 if (error)
499 error->insert(0, "Runtime info and framework compatibility matrix "
500 "are incompatible: ");
Yifan Honge8b86842017-05-25 17:59:22 +0000501 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700502 }
503 }
504
505 return COMPATIBLE;
506}
507
Yifan Hong270b5652018-01-18 18:46:01 -0800508const std::string kSystemVintfDir = "/system/etc/vintf/";
Yifan Hongccbea052018-01-18 18:48:46 -0800509const std::string kVendorVintfDir = "/vendor/etc/vintf/";
Yifan Hong270b5652018-01-18 18:46:01 -0800510
511const std::string kVendorManifest = kVendorVintfDir + "manifest.xml";
Yifan Honga5ddddf2018-01-18 18:50:13 -0800512const std::string kSystemManifest = kSystemVintfDir + "manifest.xml";
Yifan Hong270b5652018-01-18 18:46:01 -0800513
514const std::string kVendorLegacyManifest = "/vendor/manifest.xml";
515const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml";
516const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml";
517const std::string kOdmLegacyVintfDir = "/odm/etc/";
518const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml";
519
Yifan Hong143cfe62017-04-13 20:18:01 -0700520} // namespace details
521
Yifan Hongfbbf0472017-04-07 18:14:18 -0700522// static
Yifan Hongdb6423e2017-09-11 14:38:46 -0700523int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error,
524 DisabledChecks disabledChecks) {
525 return details::checkCompatibility(xmls, false /* mount */, *details::gPartitionMounter, error,
526 disabledChecks);
Yifan Hongfbbf0472017-04-07 18:14:18 -0700527}
528
Yifan Hong3daec812017-02-27 18:49:11 -0800529
530} // namespace vintf
531} // namespace android