blob: 73d0384f86e4d76a0ee91a60b2d25c1ba3579bab [file] [log] [blame]
Yifan Hong676447a2016-11-15 12:57:23 -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 "CompatibilityMatrix.h"
18
Yifan Hongbbfff302017-06-06 17:10:13 -070019#include "parse_string.h"
Yifan Hong1e5a0542017-04-28 14:37:56 -070020#include "utils.h"
21
Yifan Hong676447a2016-11-15 12:57:23 -080022namespace android {
23namespace vintf {
24
Yifan Hong676447a2016-11-15 12:57:23 -080025bool CompatibilityMatrix::add(MatrixHal &&hal) {
Yifan Hong0fd7aef2017-05-24 14:37:19 -070026 return HalGroup<MatrixHal>::add(std::move(hal));
Yifan Hong676447a2016-11-15 12:57:23 -080027}
28
29bool CompatibilityMatrix::add(MatrixKernel &&kernel) {
Yifan Hong7c7d7062017-04-04 16:26:51 -070030 if (mType != SchemaType::FRAMEWORK) {
31 return false;
32 }
33 framework.mKernels.push_back(std::move(kernel));
Yifan Hong676447a2016-11-15 12:57:23 -080034 return true;
35}
36
Yifan Hong398f4c72017-04-13 20:18:01 -070037SchemaType CompatibilityMatrix::type() const {
38 return mType;
39}
40
Yifan Hongdb127cb2017-09-19 13:36:21 -070041Version CompatibilityMatrix::getMinimumMetaVersion() const {
42 // TODO(b/62801658): this needs to depend on whether there are 1.1 requirements
43 // (e.g. required <xmlfile> entry)
44 return {1, 0};
45}
Yifan Hong1e5a0542017-04-28 14:37:56 -070046
47status_t CompatibilityMatrix::fetchAllInformation(const std::string &path) {
48 return details::fetchAllInformation(path, gCompatibilityMatrixConverter, this);
49}
50
Yifan Hongbbfff302017-06-06 17:10:13 -070051std::string CompatibilityMatrix::getXmlSchemaPath(const std::string& xmlFileName,
52 const Version& version) const {
53 using std::literals::string_literals::operator""s;
54 auto range = getXmlFiles(xmlFileName);
55 for (auto it = range.first; it != range.second; ++it) {
56 const MatrixXmlFile& matrixXmlFile = it->second;
57 if (matrixXmlFile.versionRange().contains(version)) {
58 if (!matrixXmlFile.overriddenPath().empty()) {
59 return matrixXmlFile.overriddenPath();
60 }
61 return "/"s + (type() == SchemaType::DEVICE ? "vendor" : "system") + "/etc/" +
62 xmlFileName + "_V" + std::to_string(matrixXmlFile.versionRange().majorVer) +
63 "_" + std::to_string(matrixXmlFile.versionRange().maxMinor) + "." +
64 to_string(matrixXmlFile.format());
65 }
66 }
67 return "";
68}
69
Yifan Hongfb7469c2017-04-05 19:15:21 -070070bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) {
Yifan Hongd4857902017-06-13 14:13:56 -070071 return lft.mType == rgt.mType && lft.mHals == rgt.mHals && lft.mXmlFiles == rgt.mXmlFiles &&
72 (lft.mType != SchemaType::DEVICE || (lft.device.mVndk == rgt.device.mVndk)) &&
73 (lft.mType != SchemaType::FRAMEWORK ||
74 (lft.framework.mKernels == rgt.framework.mKernels &&
75 lft.framework.mSepolicy == rgt.framework.mSepolicy &&
76 lft.framework.mAvbMetaVersion == rgt.framework.mAvbMetaVersion));
Yifan Hongfb7469c2017-04-05 19:15:21 -070077}
78
Yifan Hong676447a2016-11-15 12:57:23 -080079} // namespace vintf
80} // namespace android