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 | |
| 19 | namespace android { |
| 20 | namespace vintf { |
| 21 | |
| 22 | constexpr Version CompatibilityMatrix::kVersion; |
| 23 | |
| 24 | bool CompatibilityMatrix::add(MatrixHal &&hal) { |
Yifan Hong | 9bbdb28 | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 25 | mHals.emplace(hal.name, std::move(hal)); |
| 26 | return true; |
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 | 9bbdb28 | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 37 | ConstMultiMapValueIterable<std::string, MatrixHal> CompatibilityMatrix::getHals() const { |
| 38 | return ConstMultiMapValueIterable<std::string, MatrixHal>(mHals); |
Yifan Hong | c66ad1e | 2017-02-08 20:19:45 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Yifan Hong | d0cbf1f | 2017-04-12 19:47:06 -0700 | [diff] [blame] | 41 | MatrixHal *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 Hong | c66ad1e | 2017-02-08 20:19:45 -0800 | [diff] [blame] | 49 | const MatrixKernel *CompatibilityMatrix::findKernel(const KernelVersion &v) const { |
Yifan Hong | 7c7d706 | 2017-04-04 16:26:51 -0700 | [diff] [blame] | 50 | if (mType != SchemaType::FRAMEWORK) { |
| 51 | return nullptr; |
| 52 | } |
| 53 | for (const MatrixKernel &matrixKernel : framework.mKernels) { |
Yifan Hong | c66ad1e | 2017-02-08 20:19:45 -0800 | [diff] [blame] | 54 | 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 Hong | 398f4c7 | 2017-04-13 20:18:01 -0700 | [diff] [blame^] | 62 | SchemaType CompatibilityMatrix::type() const { |
| 63 | return mType; |
| 64 | } |
| 65 | |
Yifan Hong | fb7469c | 2017-04-05 19:15:21 -0700 | [diff] [blame] | 66 | bool 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 Hong | f302930 | 2017-04-12 17:23:49 -0700 | [diff] [blame] | 73 | lft.framework.mSepolicy == rgt.framework.mSepolicy && |
| 74 | lft.framework.mAvbMetaVersion == rgt.framework.mAvbMetaVersion)); |
Yifan Hong | fb7469c | 2017-04-05 19:15:21 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 77 | } // namespace vintf |
| 78 | } // namespace android |