blob: 509ca1d980ba9f68d84248fee575f1d0618f3e94 [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
25constexpr Version CompatibilityMatrix::kVersion;
26
27bool CompatibilityMatrix::add(MatrixHal &&hal) {
Yifan Hong0fd7aef2017-05-24 14:37:19 -070028 return HalGroup<MatrixHal>::add(std::move(hal));
Yifan Hong676447a2016-11-15 12:57:23 -080029}
30
31bool CompatibilityMatrix::add(MatrixKernel &&kernel) {
Yifan Hong7c7d7062017-04-04 16:26:51 -070032 if (mType != SchemaType::FRAMEWORK) {
33 return false;
34 }
35 framework.mKernels.push_back(std::move(kernel));
Yifan Hong676447a2016-11-15 12:57:23 -080036 return true;
37}
38
Yifan Hongc66ad1e2017-02-08 20:19:45 -080039const MatrixKernel *CompatibilityMatrix::findKernel(const KernelVersion &v) const {
Yifan Hong7c7d7062017-04-04 16:26:51 -070040 if (mType != SchemaType::FRAMEWORK) {
41 return nullptr;
42 }
43 for (const MatrixKernel &matrixKernel : framework.mKernels) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080044 if (matrixKernel.minLts().version == v.version &&
45 matrixKernel.minLts().majorRev == v.majorRev) {
46 return matrixKernel.minLts().minorRev <= v.minorRev ? &matrixKernel : nullptr;
47 }
48 }
49 return nullptr;
50}
51
Yifan Hong398f4c72017-04-13 20:18:01 -070052SchemaType CompatibilityMatrix::type() const {
53 return mType;
54}
55
Yifan Hong1e5a0542017-04-28 14:37:56 -070056
57status_t CompatibilityMatrix::fetchAllInformation(const std::string &path) {
58 return details::fetchAllInformation(path, gCompatibilityMatrixConverter, this);
59}
60
Yifan Hongbbfff302017-06-06 17:10:13 -070061std::string CompatibilityMatrix::getXmlSchemaPath(const std::string& xmlFileName,
62 const Version& version) const {
63 using std::literals::string_literals::operator""s;
64 auto range = getXmlFiles(xmlFileName);
65 for (auto it = range.first; it != range.second; ++it) {
66 const MatrixXmlFile& matrixXmlFile = it->second;
67 if (matrixXmlFile.versionRange().contains(version)) {
68 if (!matrixXmlFile.overriddenPath().empty()) {
69 return matrixXmlFile.overriddenPath();
70 }
71 return "/"s + (type() == SchemaType::DEVICE ? "vendor" : "system") + "/etc/" +
72 xmlFileName + "_V" + std::to_string(matrixXmlFile.versionRange().majorVer) +
73 "_" + std::to_string(matrixXmlFile.versionRange().maxMinor) + "." +
74 to_string(matrixXmlFile.format());
75 }
76 }
77 return "";
78}
79
Yifan Hongfb7469c2017-04-05 19:15:21 -070080bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) {
Yifan Hongd4857902017-06-13 14:13:56 -070081 return lft.mType == rgt.mType && lft.mHals == rgt.mHals && lft.mXmlFiles == rgt.mXmlFiles &&
82 (lft.mType != SchemaType::DEVICE || (lft.device.mVndk == rgt.device.mVndk)) &&
83 (lft.mType != SchemaType::FRAMEWORK ||
84 (lft.framework.mKernels == rgt.framework.mKernels &&
85 lft.framework.mSepolicy == rgt.framework.mSepolicy &&
86 lft.framework.mAvbMetaVersion == rgt.framework.mAvbMetaVersion));
Yifan Hongfb7469c2017-04-05 19:15:21 -070087}
88
Yifan Hong676447a2016-11-15 12:57:23 -080089} // namespace vintf
90} // namespace android