Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 1 | /* |
| 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 Hong | bbfff30 | 2017-06-06 17:10:13 -0700 | [diff] [blame] | 19 | #include "parse_string.h" |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 20 | #include "utils.h" |
| 21 | |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 22 | namespace android { |
| 23 | namespace vintf { |
| 24 | |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 25 | bool CompatibilityMatrix::add(MatrixHal &&hal) { |
Yifan Hong | 0fd7aef | 2017-05-24 14:37:19 -0700 | [diff] [blame] | 26 | return HalGroup<MatrixHal>::add(std::move(hal)); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | bool CompatibilityMatrix::add(MatrixKernel &&kernel) { |
Yifan Hong | 7c7d706 | 2017-04-04 16:26:51 -0700 | [diff] [blame] | 30 | if (mType != SchemaType::FRAMEWORK) { |
| 31 | return false; |
| 32 | } |
| 33 | framework.mKernels.push_back(std::move(kernel)); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 34 | return true; |
| 35 | } |
| 36 | |
Yifan Hong | 398f4c7 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 37 | SchemaType CompatibilityMatrix::type() const { |
| 38 | return mType; |
| 39 | } |
| 40 | |
Yifan Hong | 2027a49 | 2017-12-11 15:21:19 -0800 | [diff] [blame^] | 41 | Level CompatibilityMatrix::level() const { |
| 42 | return mLevel; |
| 43 | } |
| 44 | |
Yifan Hong | db127cb | 2017-09-19 13:36:21 -0700 | [diff] [blame] | 45 | Version CompatibilityMatrix::getMinimumMetaVersion() const { |
| 46 | // TODO(b/62801658): this needs to depend on whether there are 1.1 requirements |
| 47 | // (e.g. required <xmlfile> entry) |
| 48 | return {1, 0}; |
| 49 | } |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 50 | |
| 51 | status_t CompatibilityMatrix::fetchAllInformation(const std::string &path) { |
| 52 | return details::fetchAllInformation(path, gCompatibilityMatrixConverter, this); |
| 53 | } |
| 54 | |
Yifan Hong | bbfff30 | 2017-06-06 17:10:13 -0700 | [diff] [blame] | 55 | std::string CompatibilityMatrix::getXmlSchemaPath(const std::string& xmlFileName, |
| 56 | const Version& version) const { |
| 57 | using std::literals::string_literals::operator""s; |
| 58 | auto range = getXmlFiles(xmlFileName); |
| 59 | for (auto it = range.first; it != range.second; ++it) { |
| 60 | const MatrixXmlFile& matrixXmlFile = it->second; |
| 61 | if (matrixXmlFile.versionRange().contains(version)) { |
| 62 | if (!matrixXmlFile.overriddenPath().empty()) { |
| 63 | return matrixXmlFile.overriddenPath(); |
| 64 | } |
| 65 | return "/"s + (type() == SchemaType::DEVICE ? "vendor" : "system") + "/etc/" + |
| 66 | xmlFileName + "_V" + std::to_string(matrixXmlFile.versionRange().majorVer) + |
| 67 | "_" + std::to_string(matrixXmlFile.versionRange().maxMinor) + "." + |
| 68 | to_string(matrixXmlFile.format()); |
| 69 | } |
| 70 | } |
| 71 | return ""; |
| 72 | } |
| 73 | |
Yifan Hong | fb7469c | 2017-04-05 19:15:21 -0700 | [diff] [blame] | 74 | bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) { |
Yifan Hong | 2027a49 | 2017-12-11 15:21:19 -0800 | [diff] [blame^] | 75 | return lft.mType == rgt.mType && lft.mLevel == rgt.mLevel && lft.mHals == rgt.mHals && |
| 76 | lft.mXmlFiles == rgt.mXmlFiles && |
Yifan Hong | d485790 | 2017-06-13 14:13:56 -0700 | [diff] [blame] | 77 | (lft.mType != SchemaType::DEVICE || (lft.device.mVndk == rgt.device.mVndk)) && |
| 78 | (lft.mType != SchemaType::FRAMEWORK || |
| 79 | (lft.framework.mKernels == rgt.framework.mKernels && |
| 80 | lft.framework.mSepolicy == rgt.framework.mSepolicy && |
| 81 | lft.framework.mAvbMetaVersion == rgt.framework.mAvbMetaVersion)); |
Yifan Hong | fb7469c | 2017-04-05 19:15:21 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 84 | } // namespace vintf |
| 85 | } // namespace android |