blob: 379fd78d80edc65bb937b3826533ca27127c68f5 [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 Hong1e5a0542017-04-28 14:37:56 -070019#include "utils.h"
20
Yifan Hong676447a2016-11-15 12:57:23 -080021namespace android {
22namespace vintf {
23
24constexpr Version CompatibilityMatrix::kVersion;
25
26bool CompatibilityMatrix::add(MatrixHal &&hal) {
Yifan Hong9bbdb282017-04-12 21:53:59 -070027 mHals.emplace(hal.name, std::move(hal));
28 return true;
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 Hong9bbdb282017-04-12 21:53:59 -070039ConstMultiMapValueIterable<std::string, MatrixHal> CompatibilityMatrix::getHals() const {
40 return ConstMultiMapValueIterable<std::string, MatrixHal>(mHals);
Yifan Hongc66ad1e2017-02-08 20:19:45 -080041}
42
Yifan Hongd0cbf1f2017-04-12 19:47:06 -070043MatrixHal *CompatibilityMatrix::getAnyHal(const std::string &name) {
44 auto it = mHals.find(name);
45 if (it == mHals.end()) {
46 return nullptr;
47 }
48 return &(it->second);
49}
50
Yifan Hongc66ad1e2017-02-08 20:19:45 -080051const MatrixKernel *CompatibilityMatrix::findKernel(const KernelVersion &v) const {
Yifan Hong7c7d7062017-04-04 16:26:51 -070052 if (mType != SchemaType::FRAMEWORK) {
53 return nullptr;
54 }
55 for (const MatrixKernel &matrixKernel : framework.mKernels) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080056 if (matrixKernel.minLts().version == v.version &&
57 matrixKernel.minLts().majorRev == v.majorRev) {
58 return matrixKernel.minLts().minorRev <= v.minorRev ? &matrixKernel : nullptr;
59 }
60 }
61 return nullptr;
62}
63
Yifan Hong398f4c72017-04-13 20:18:01 -070064SchemaType CompatibilityMatrix::type() const {
65 return mType;
66}
67
Yifan Hong1e5a0542017-04-28 14:37:56 -070068
69status_t CompatibilityMatrix::fetchAllInformation(const std::string &path) {
70 return details::fetchAllInformation(path, gCompatibilityMatrixConverter, this);
71}
72
Yifan Hongfb7469c2017-04-05 19:15:21 -070073bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) {
74 return lft.mType == rgt.mType &&
75 lft.mHals == rgt.mHals &&
76 (lft.mType != SchemaType::DEVICE || (
77 lft.device.mVndk == rgt.device.mVndk)) &&
78 (lft.mType != SchemaType::FRAMEWORK || (
79 lft.framework.mKernels == rgt.framework.mKernels &&
Yifan Hongf3029302017-04-12 17:23:49 -070080 lft.framework.mSepolicy == rgt.framework.mSepolicy &&
81 lft.framework.mAvbMetaVersion == rgt.framework.mAvbMetaVersion));
Yifan Hongfb7469c2017-04-05 19:15:21 -070082}
83
Yifan Hong676447a2016-11-15 12:57:23 -080084} // namespace vintf
85} // namespace android