blob: 627c2384092e3abe600d89424f7df6c7fa0a2c3d [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 Hong0fd7aef2017-05-24 14:37:19 -070027 return HalGroup<MatrixHal>::add(std::move(hal));
Yifan Hong676447a2016-11-15 12:57:23 -080028}
29
30bool CompatibilityMatrix::add(MatrixKernel &&kernel) {
Yifan Hong7c7d7062017-04-04 16:26:51 -070031 if (mType != SchemaType::FRAMEWORK) {
32 return false;
33 }
34 framework.mKernels.push_back(std::move(kernel));
Yifan Hong676447a2016-11-15 12:57:23 -080035 return true;
36}
37
Yifan Hongc66ad1e2017-02-08 20:19:45 -080038const MatrixKernel *CompatibilityMatrix::findKernel(const KernelVersion &v) const {
Yifan Hong7c7d7062017-04-04 16:26:51 -070039 if (mType != SchemaType::FRAMEWORK) {
40 return nullptr;
41 }
42 for (const MatrixKernel &matrixKernel : framework.mKernels) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080043 if (matrixKernel.minLts().version == v.version &&
44 matrixKernel.minLts().majorRev == v.majorRev) {
45 return matrixKernel.minLts().minorRev <= v.minorRev ? &matrixKernel : nullptr;
46 }
47 }
48 return nullptr;
49}
50
Yifan Hong398f4c72017-04-13 20:18:01 -070051SchemaType CompatibilityMatrix::type() const {
52 return mType;
53}
54
Yifan Hong1e5a0542017-04-28 14:37:56 -070055
56status_t CompatibilityMatrix::fetchAllInformation(const std::string &path) {
57 return details::fetchAllInformation(path, gCompatibilityMatrixConverter, this);
58}
59
Yifan Hongfb7469c2017-04-05 19:15:21 -070060bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) {
61 return lft.mType == rgt.mType &&
62 lft.mHals == rgt.mHals &&
63 (lft.mType != SchemaType::DEVICE || (
64 lft.device.mVndk == rgt.device.mVndk)) &&
65 (lft.mType != SchemaType::FRAMEWORK || (
66 lft.framework.mKernels == rgt.framework.mKernels &&
Yifan Hongf3029302017-04-12 17:23:49 -070067 lft.framework.mSepolicy == rgt.framework.mSepolicy &&
68 lft.framework.mAvbMetaVersion == rgt.framework.mAvbMetaVersion));
Yifan Hongfb7469c2017-04-05 19:15:21 -070069}
70
Yifan Hong676447a2016-11-15 12:57:23 -080071} // namespace vintf
72} // namespace android