blob: 90b446d8f84baf0d899fd3891ce581b98c8dc742 [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:
Yifan Hong12a11ac2018-01-19 13:58:32 -0800172// 1. /vendor/etc/vintf/manifest.xml + ODM manifest
173// 2. /vendor/etc/vintf/manifest.xml
174// 3. ODM manifest
175// 4. /vendor/manifest.xml
Yifan Hong5a93bf22018-01-17 18:22:32 -0800176// where:
Yifan Hong5a93bf22018-01-17 18:22:32 -0800177// A + B means adding <hal> tags from B to A (so that <hal>s from B can override A)
178status_t VintfObject::FetchDeviceHalManifest(HalManifest* out, std::string* error) {
Yifan Hong12a11ac2018-01-19 13:58:32 -0800179 status_t vendorStatus = FetchOneHalManifest(kVendorManifest, out, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800180 if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) {
181 return vendorStatus;
182 }
183
184 HalManifest odmManifest;
Yifan Hong12a11ac2018-01-19 13:58:32 -0800185 status_t odmStatus = FetchOdmHalManifest(&odmManifest, error);
186 if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
187 return odmStatus;
Yifan Hong5a93bf22018-01-17 18:22:32 -0800188 }
189
Yifan Hong5a93bf22018-01-17 18:22:32 -0800190 if (vendorStatus == OK) {
Yifan Hong12a11ac2018-01-19 13:58:32 -0800191 if (odmStatus == OK) {
192 out->addAllHals(&odmManifest);
193 }
Yifan Hong5a93bf22018-01-17 18:22:32 -0800194 return OK;
195 }
196
Yifan Hong12a11ac2018-01-19 13:58:32 -0800197 // vendorStatus != OK, "out" is not changed.
Yifan Hong5a93bf22018-01-17 18:22:32 -0800198 if (odmStatus == OK) {
199 *out = std::move(odmManifest);
200 return OK;
201 }
202
203 // Use legacy /vendor/manifest.xml
Yifan Hong270b5652018-01-18 18:46:01 -0800204 return out->fetchAllInformation(kVendorLegacyManifest, error);
Yifan Hong5a93bf22018-01-17 18:22:32 -0800205}
206
Yifan Hong12a11ac2018-01-19 13:58:32 -0800207// "out" is written to iff return status is OK.
208// Priority:
209// 1. if {sku} is defined, /odm/etc/vintf/manifest_{sku}.xml
210// 2. /odm/etc/vintf/manifest.xml
211// 3. if {sku} is defined, /odm/etc/manifest_{sku}.xml
212// 4. /odm/etc/manifest.xml
213// where:
214// {sku} is the value of ro.boot.product.hardware.sku
215status_t VintfObject::FetchOdmHalManifest(HalManifest* out, std::string* error) {
216 status_t status;
217
218#ifdef LIBVINTF_TARGET
219 std::string productModel;
220 productModel = android::base::GetProperty("ro.boot.product.hardware.sku", "");
221
222 if (!productModel.empty()) {
223 status =
224 FetchOneHalManifest(kOdmVintfDir + "manifest_" + productModel + ".xml", out, error);
225 if (status == OK || status != NAME_NOT_FOUND) {
226 return status;
227 }
228 }
229#endif
230
231 status = FetchOneHalManifest(kOdmManifest, out, error);
232 if (status == OK || status != NAME_NOT_FOUND) {
233 return status;
234 }
235
236#ifdef LIBVINTF_TARGET
237 if (!productModel.empty()) {
238 status = FetchOneHalManifest(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", out,
239 error);
240 if (status == OK || status != NAME_NOT_FOUND) {
241 return status;
242 }
243 }
244#endif
245
246 status = FetchOneHalManifest(kOdmLegacyManifest, out, error);
247 if (status == OK || status != NAME_NOT_FOUND) {
248 return status;
249 }
250
251 return NAME_NOT_FOUND;
252}
253
254// Fetch one manifest.xml file. "out" is written to iff return status is OK.
255// Returns NAME_NOT_FOUND if file is missing.
256status_t VintfObject::FetchOneHalManifest(const std::string& path, HalManifest* out,
257 std::string* error) {
258 HalManifest ret;
259 status_t status = ret.fetchAllInformation(path, error);
260 if (status == OK) {
261 *out = std::move(ret);
262 }
263 return status;
264}
265
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800266status_t VintfObject::FetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) {
267 CompatibilityMatrix etcMatrix;
268 if (etcMatrix.fetchAllInformation(kVendorMatrix, error) == OK) {
269 *out = std::move(etcMatrix);
270 return OK;
271 }
272 return out->fetchAllInformation(kVendorLegacyMatrix, error);
273}
274
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800275std::vector<Named<CompatibilityMatrix>> VintfObject::GetAllFrameworkMatrixLevels(
276 std::string* error) {
277 std::vector<std::string> fileNames;
278 std::vector<Named<CompatibilityMatrix>> results;
279
Yifan Hong270b5652018-01-18 18:46:01 -0800280 if (details::gFetcher->listFiles(kSystemVintfDir, &fileNames, error) != OK) {
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800281 return {};
282 }
283 for (const std::string& fileName : fileNames) {
Yifan Hong270b5652018-01-18 18:46:01 -0800284 std::string path = kSystemVintfDir + fileName;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800285
286 std::string content;
287 std::string fetchError;
288 status_t status = details::gFetcher->fetch(path, content, &fetchError);
289 if (status != OK) {
290 if (error) {
291 *error += "Ignore file " + path + ": " + fetchError + "\n";
292 }
293 continue;
294 }
295
296 auto it = results.emplace(results.end());
297 if (!gCompatibilityMatrixConverter(&it->object, content)) {
298 if (error) {
299 // TODO(b/71874788): do not use lastError() because it is not thread-safe.
300 *error +=
301 "Ignore file " + path + ": " + gCompatibilityMatrixConverter.lastError() + "\n";
302 }
303 results.erase(it);
304 continue;
305 }
306 }
307
308 if (results.empty()) {
309 if (error) {
Yifan Hong270b5652018-01-18 18:46:01 -0800310 *error = "No framework matrices under " + kSystemVintfDir +
311 " can be fetched or parsed.\n" + *error;
Yifan Hongd52bf3e2018-01-11 16:56:51 -0800312 }
313 } else {
314 if (error && !error->empty()) {
315 LOG(WARNING) << *error;
316 *error = "";
317 }
318 }
319
320 return results;
321}
322
Yifan Hong3daec812017-02-27 18:49:11 -0800323// static
Yifan Hong1fb004e2017-09-26 15:04:44 -0700324std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache,
325 RuntimeInfo::FetchFlags flags) {
326 static LockedRuntimeInfoCache gDeviceRuntimeInfo;
327 std::unique_lock<std::mutex> _lock(gDeviceRuntimeInfo.mutex);
328
329 if (!skipCache) {
330 flags &= (~gDeviceRuntimeInfo.fetchedFlags);
331 }
332
333 if (gDeviceRuntimeInfo.object == nullptr) {
Yifan Hong29bb2d42017-09-27 13:28:00 -0700334 gDeviceRuntimeInfo.object = details::gRuntimeInfoFactory->make_shared();
Yifan Hong1fb004e2017-09-26 15:04:44 -0700335 }
336
337 status_t status = gDeviceRuntimeInfo.object->fetchAllInformation(flags);
338 if (status != OK) {
339 gDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched"
340 return nullptr;
341 }
342
343 gDeviceRuntimeInfo.fetchedFlags |= flags;
344 return gDeviceRuntimeInfo.object;
Yifan Hong3daec812017-02-27 18:49:11 -0800345}
346
Yifan Hong143cfe62017-04-13 20:18:01 -0700347namespace details {
348
Yifan Hong143cfe62017-04-13 20:18:01 -0700349enum class ParseStatus {
350 OK,
351 PARSE_ERROR,
352 DUPLICATED_FWK_ENTRY,
353 DUPLICATED_DEV_ENTRY,
354};
355
Yifan Hong9532bd22017-04-14 15:30:52 -0700356static std::string toString(ParseStatus status) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700357 switch(status) {
358 case ParseStatus::OK: return "OK";
359 case ParseStatus::PARSE_ERROR: return "parse error";
360 case ParseStatus::DUPLICATED_FWK_ENTRY: return "duplicated framework";
361 case ParseStatus::DUPLICATED_DEV_ENTRY: return "duplicated device";
362 }
363 return "";
364}
365
366template<typename T>
Yifan Hong9532bd22017-04-14 15:30:52 -0700367static ParseStatus tryParse(const std::string &xml, const XmlConverter<T> &parse,
Yifan Hongfc73edf2017-08-29 11:39:07 -0700368 std::shared_ptr<T> *fwk, std::shared_ptr<T> *dev) {
369 std::shared_ptr<T> ret = std::make_shared<T>();
Yifan Hong143cfe62017-04-13 20:18:01 -0700370 if (!parse(ret.get(), xml)) {
371 return ParseStatus::PARSE_ERROR;
372 }
373 if (ret->type() == SchemaType::FRAMEWORK) {
374 if (fwk->get() != nullptr) {
375 return ParseStatus::DUPLICATED_FWK_ENTRY;
376 }
377 *fwk = std::move(ret);
378 } else if (ret->type() == SchemaType::DEVICE) {
379 if (dev->get() != nullptr) {
380 return ParseStatus::DUPLICATED_DEV_ENTRY;
381 }
382 *dev = std::move(ret);
383 }
384 return ParseStatus::OK;
385}
386
387template<typename T, typename GetFunction>
Yifan Hongfc73edf2017-08-29 11:39:07 -0700388static status_t getMissing(const std::shared_ptr<T>& pkg, bool mount,
Yifan Hong143cfe62017-04-13 20:18:01 -0700389 std::function<status_t(void)> mountFunction,
Yifan Hongfc73edf2017-08-29 11:39:07 -0700390 std::shared_ptr<const T>* updated,
Yifan Hong143cfe62017-04-13 20:18:01 -0700391 GetFunction getFunction) {
392 if (pkg != nullptr) {
393 *updated = pkg;
394 } else {
395 if (mount) {
396 (void)mountFunction(); // ignore mount errors
397 }
398 *updated = getFunction();
399 }
400 return OK;
401}
402
403#define ADD_MESSAGE(__error__) \
404 if (error != nullptr) { \
405 *error += (__error__); \
406 } \
407
408struct PackageInfo {
409 struct Pair {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700410 std::shared_ptr<HalManifest> manifest;
411 std::shared_ptr<CompatibilityMatrix> matrix;
Yifan Hong143cfe62017-04-13 20:18:01 -0700412 };
413 Pair dev;
414 Pair fwk;
415};
416
417struct UpdatedInfo {
418 struct Pair {
Yifan Hongfc73edf2017-08-29 11:39:07 -0700419 std::shared_ptr<const HalManifest> manifest;
420 std::shared_ptr<const CompatibilityMatrix> matrix;
Yifan Hong143cfe62017-04-13 20:18:01 -0700421 };
422 Pair dev;
423 Pair fwk;
Yifan Hongfc73edf2017-08-29 11:39:07 -0700424 std::shared_ptr<const RuntimeInfo> runtimeInfo;
Yifan Hong143cfe62017-04-13 20:18:01 -0700425};
426
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700427// Checks given compatibility info against info on the device. If no
428// compatability info is given then the device info will be checked against
429// itself.
Yifan Hongdb6423e2017-09-11 14:38:46 -0700430int32_t checkCompatibility(const std::vector<std::string>& xmls, bool mount,
431 const PartitionMounter& mounter, std::string* error,
432 DisabledChecks disabledChecks) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700433 status_t status;
434 ParseStatus parseStatus;
435 PackageInfo pkg; // All information from package.
436 UpdatedInfo updated; // All files and runtime info after the update.
437
Yifan Hong143cfe62017-04-13 20:18:01 -0700438 // parse all information from package
439 for (const auto &xml : xmls) {
440 parseStatus = tryParse(xml, gHalManifestConverter, &pkg.fwk.manifest, &pkg.dev.manifest);
441 if (parseStatus == ParseStatus::OK) {
442 continue; // work on next one
443 }
444 if (parseStatus != ParseStatus::PARSE_ERROR) {
445 ADD_MESSAGE(toString(parseStatus) + " manifest");
446 return ALREADY_EXISTS;
447 }
448 parseStatus = tryParse(xml, gCompatibilityMatrixConverter, &pkg.fwk.matrix, &pkg.dev.matrix);
449 if (parseStatus == ParseStatus::OK) {
450 continue; // work on next one
451 }
452 if (parseStatus != ParseStatus::PARSE_ERROR) {
453 ADD_MESSAGE(toString(parseStatus) + " matrix");
454 return ALREADY_EXISTS;
455 }
456 ADD_MESSAGE(toString(parseStatus)); // parse error
457 return BAD_VALUE;
458 }
459
460 // get missing info from device
Yifan Hong8640cd12017-05-17 12:02:28 -0700461 // use functions instead of std::bind because std::bind doesn't work well with mock objects
462 auto mountSystem = [&mounter] { return mounter.mountSystem(); };
463 auto mountVendor = [&mounter] { return mounter.mountVendor(); };
464 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700465 pkg.fwk.manifest, mount, mountSystem, &updated.fwk.manifest,
Yifan Hong8640cd12017-05-17 12:02:28 -0700466 std::bind(VintfObject::GetFrameworkHalManifest, true /* skipCache */))) != OK) {
Yifan Hong143cfe62017-04-13 20:18:01 -0700467 return status;
468 }
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700469 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700470 pkg.dev.manifest, mount, mountVendor, &updated.dev.manifest,
Yifan Hong8640cd12017-05-17 12:02:28 -0700471 std::bind(VintfObject::GetDeviceHalManifest, true /* skipCache */))) != OK) {
472 return status;
473 }
474 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700475 pkg.fwk.matrix, mount, mountSystem, &updated.fwk.matrix,
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700476 std::bind(VintfObject::GetFrameworkCompatibilityMatrix, true /* skipCache */))) !=
477 OK) {
478 return status;
479 }
480 if ((status = getMissing(
Yifan Hongfc73edf2017-08-29 11:39:07 -0700481 pkg.dev.matrix, mount, mountVendor, &updated.dev.matrix,
Michael Schwartz97dc0f92017-05-08 14:07:14 -0700482 std::bind(VintfObject::GetDeviceCompatibilityMatrix, true /* skipCache */))) != OK) {
483 return status;
484 }
Yifan Hong8640cd12017-05-17 12:02:28 -0700485
486 if (mount) {
487 (void)mounter.umountSystem(); // ignore errors
488 (void)mounter.umountVendor(); // ignore errors
489 }
490
491 updated.runtimeInfo = VintfObject::GetRuntimeInfo(true /* skipCache */);
Yifan Hong143cfe62017-04-13 20:18:01 -0700492
493 // null checks for files and runtime info after the update
494 // TODO(b/37321309) if a compat mat is missing, it is not matched and considered compatible.
495 if (updated.fwk.manifest == nullptr) {
496 ADD_MESSAGE("No framework manifest file from device or from update package");
497 return NO_INIT;
498 }
499 if (updated.dev.manifest == nullptr) {
500 ADD_MESSAGE("No device manifest file from device or from update package");
501 return NO_INIT;
502 }
503 if (updated.fwk.matrix == nullptr) {
504 ADD_MESSAGE("No framework matrix, skipping;");
505 // TODO(b/37321309) consider missing matricies as errors.
506 }
507 if (updated.dev.matrix == nullptr) {
508 ADD_MESSAGE("No device matrix, skipping;");
509 // TODO(b/37321309) consider missing matricies as errors.
510 }
511 if (updated.runtimeInfo == nullptr) {
512 ADD_MESSAGE("No runtime info from device");
513 return NO_INIT;
514 }
515
516 // compatiblity check.
517 // TODO(b/37321309) outer if checks can be removed if we consider missing matrices as errors.
518 if (updated.dev.manifest && updated.fwk.matrix) {
519 if (!updated.dev.manifest->checkCompatibility(*updated.fwk.matrix, error)) {
Yifan Hong0d4be122017-05-15 17:04:22 -0700520 if (error)
521 error->insert(0, "Device manifest and framework compatibility matrix "
522 "are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700523 return INCOMPATIBLE;
524 }
525 }
526 if (updated.fwk.manifest && updated.dev.matrix) {
527 if (!updated.fwk.manifest->checkCompatibility(*updated.dev.matrix, error)) {
Yifan Hong0d4be122017-05-15 17:04:22 -0700528 if (error)
529 error->insert(0, "Framework manifest and device compatibility matrix "
530 "are incompatible: ");
Yifan Hong143cfe62017-04-13 20:18:01 -0700531 return INCOMPATIBLE;
532 }
533 }
534 if (updated.runtimeInfo && updated.fwk.matrix) {
Yifan Hongdb6423e2017-09-11 14:38:46 -0700535 if (!updated.runtimeInfo->checkCompatibility(*updated.fwk.matrix, error, disabledChecks)) {
Yifan Hong0d4be122017-05-15 17:04:22 -0700536 if (error)
537 error->insert(0, "Runtime info and framework compatibility matrix "
538 "are incompatible: ");
Yifan Honge8b86842017-05-25 17:59:22 +0000539 return INCOMPATIBLE;
Yifan Hong143cfe62017-04-13 20:18:01 -0700540 }
541 }
542
543 return COMPATIBLE;
544}
545
Yifan Hong270b5652018-01-18 18:46:01 -0800546const std::string kSystemVintfDir = "/system/etc/vintf/";
Yifan Hongccbea052018-01-18 18:48:46 -0800547const std::string kVendorVintfDir = "/vendor/etc/vintf/";
Yifan Hong12a11ac2018-01-19 13:58:32 -0800548const std::string kOdmVintfDir = "/odm/etc/vintf/";
Yifan Hong270b5652018-01-18 18:46:01 -0800549
550const std::string kVendorManifest = kVendorVintfDir + "manifest.xml";
Yifan Honga5ddddf2018-01-18 18:50:13 -0800551const std::string kSystemManifest = kSystemVintfDir + "manifest.xml";
Yifan Hongb64ec9e2018-01-18 18:57:52 -0800552const std::string kVendorMatrix = kVendorVintfDir + "compatibility_matrix.xml";
Yifan Hong12a11ac2018-01-19 13:58:32 -0800553const std::string kOdmManifest = kOdmVintfDir + "manifest.xml";
Yifan Hong270b5652018-01-18 18:46:01 -0800554
555const std::string kVendorLegacyManifest = "/vendor/manifest.xml";
556const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml";
557const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml";
558const std::string kOdmLegacyVintfDir = "/odm/etc/";
559const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml";
560
Yifan Hong143cfe62017-04-13 20:18:01 -0700561} // namespace details
562
Yifan Hongfbbf0472017-04-07 18:14:18 -0700563// static
Yifan Hongdb6423e2017-09-11 14:38:46 -0700564int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error,
565 DisabledChecks disabledChecks) {
566 return details::checkCompatibility(xmls, false /* mount */, *details::gPartitionMounter, error,
567 disabledChecks);
Yifan Hongfbbf0472017-04-07 18:14:18 -0700568}
569
Yifan Hong3daec812017-02-27 18:49:11 -0800570
571} // namespace vintf
572} // namespace android