blob: 1f95adacce5d3d1bcdd162c1637fb34ffb233bce [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
19namespace android {
20namespace vintf {
21
22constexpr Version CompatibilityMatrix::kVersion;
23
24bool CompatibilityMatrix::add(MatrixHal &&hal) {
Yifan Hong9bbdb282017-04-12 21:53:59 -070025 mHals.emplace(hal.name, std::move(hal));
26 return true;
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 Hong9bbdb282017-04-12 21:53:59 -070037ConstMultiMapValueIterable<std::string, MatrixHal> CompatibilityMatrix::getHals() const {
38 return ConstMultiMapValueIterable<std::string, MatrixHal>(mHals);
Yifan Hongc66ad1e2017-02-08 20:19:45 -080039}
40
Yifan Hongd0cbf1f2017-04-12 19:47:06 -070041MatrixHal *CompatibilityMatrix::getAnyHal(const std::string &name) {
42 auto it = mHals.find(name);
43 if (it == mHals.end()) {
44 return nullptr;
45 }
46 return &(it->second);
47}
48
Yifan Hongc66ad1e2017-02-08 20:19:45 -080049const MatrixKernel *CompatibilityMatrix::findKernel(const KernelVersion &v) const {
Yifan Hong7c7d7062017-04-04 16:26:51 -070050 if (mType != SchemaType::FRAMEWORK) {
51 return nullptr;
52 }
53 for (const MatrixKernel &matrixKernel : framework.mKernels) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080054 if (matrixKernel.minLts().version == v.version &&
55 matrixKernel.minLts().majorRev == v.majorRev) {
56 return matrixKernel.minLts().minorRev <= v.minorRev ? &matrixKernel : nullptr;
57 }
58 }
59 return nullptr;
60}
61
Yifan Hong398f4c72017-04-13 20:18:01 -070062SchemaType CompatibilityMatrix::type() const {
63 return mType;
64}
65
Yifan Hongfb7469c2017-04-05 19:15:21 -070066bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) {
67 return lft.mType == rgt.mType &&
68 lft.mHals == rgt.mHals &&
69 (lft.mType != SchemaType::DEVICE || (
70 lft.device.mVndk == rgt.device.mVndk)) &&
71 (lft.mType != SchemaType::FRAMEWORK || (
72 lft.framework.mKernels == rgt.framework.mKernels &&
Yifan Hongf3029302017-04-12 17:23:49 -070073 lft.framework.mSepolicy == rgt.framework.mSepolicy &&
74 lft.framework.mAvbMetaVersion == rgt.framework.mAvbMetaVersion));
Yifan Hongfb7469c2017-04-05 19:15:21 -070075}
76
Yifan Hong676447a2016-11-15 12:57:23 -080077} // namespace vintf
78} // namespace android