blob: 8d249d2f305f33e7ad855ceeb59c79fd114f85ee [file] [log] [blame]
Yifan Hongccf967b2017-01-18 11:04:19 -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
18#define LOG_TAG "libvintf"
19
Yifan Honga7201e72017-02-17 10:09:59 -080020#include "RuntimeInfo.h"
Yifan Hongccf967b2017-01-18 11:04:19 -080021
Yifan Hongc66ad1e2017-02-08 20:19:45 -080022#include "CompatibilityMatrix.h"
23#include "parse_string.h"
24
Yifan Hongccf967b2017-01-18 11:04:19 -080025namespace android {
26namespace vintf {
27
Yifan Honga7201e72017-02-17 10:09:59 -080028const std::string &RuntimeInfo::osName() const {
Yifan Hongccf967b2017-01-18 11:04:19 -080029 return mOsName;
30}
31
Yifan Honga7201e72017-02-17 10:09:59 -080032const std::string &RuntimeInfo::nodeName() const {
Yifan Hongccf967b2017-01-18 11:04:19 -080033 return mNodeName;
34}
35
Yifan Honga7201e72017-02-17 10:09:59 -080036const std::string &RuntimeInfo::osRelease() const {
Yifan Hongccf967b2017-01-18 11:04:19 -080037 return mOsRelease;
38}
39
Yifan Honga7201e72017-02-17 10:09:59 -080040const std::string &RuntimeInfo::osVersion() const {
Yifan Hongccf967b2017-01-18 11:04:19 -080041 return mOsVersion;
42}
43
Yifan Honga7201e72017-02-17 10:09:59 -080044const std::string &RuntimeInfo::hardwareId() const {
Yifan Hongccf967b2017-01-18 11:04:19 -080045 return mHardwareId;
46}
47
Yifan Hongfa2b18b2017-04-12 19:40:00 -070048const std::vector<std::string> &RuntimeInfo::sepolicyFilePaths() const {
49 return mSepolicyFilePaths;
50}
51
Yifan Honga7201e72017-02-17 10:09:59 -080052size_t RuntimeInfo::kernelSepolicyVersion() const {
Yifan Hongccf967b2017-01-18 11:04:19 -080053 return mKernelSepolicyVersion;
54}
55
Yifan Honga7201e72017-02-17 10:09:59 -080056bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix &mat,
Yifan Hongc66ad1e2017-02-08 20:19:45 -080057 std::string *error) const {
Yifan Hong7c7d7062017-04-04 16:26:51 -070058 if (mat.mType != SchemaType::FRAMEWORK) {
59 if (error != nullptr) {
60 *error = "Should not check runtime info against " + to_string(mat.mType)
61 + " compatibility matrix.";
62 }
63 return false;
64 }
65 if (kernelSepolicyVersion() != mat.framework.mSepolicy.kernelSepolicyVersion()) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080066 if (error != nullptr) {
67 *error = "kernelSepolicyVersion = " + to_string(kernelSepolicyVersion())
Yifan Hong7c7d7062017-04-04 16:26:51 -070068 + " but required " + to_string(mat.framework.mSepolicy.kernelSepolicyVersion());
Yifan Hongc66ad1e2017-02-08 20:19:45 -080069 }
70 return false;
71 }
72
Yifan Hongf3029302017-04-12 17:23:49 -070073 // mat.mSepolicy.sepolicyVersion() is checked against static HalManifest.device.mSepolicyVersion
Yifan Hongc66ad1e2017-02-08 20:19:45 -080074
75 const MatrixKernel *matrixKernel = mat.findKernel(this->mKernelVersion);
76 if (matrixKernel == nullptr) {
77 if (error != nullptr) {
78 *error = "Cannot find suitable kernel entry for " + to_string(mKernelVersion);
79 }
80 return false;
81 }
82 for (const KernelConfig &matrixConfig : matrixKernel->configs()) {
83 const std::string &key = matrixConfig.first;
Yifan Hongf1af7522017-02-16 18:00:55 -080084 auto it = this->mKernelConfigs.find(key);
85 if (it == this->mKernelConfigs.end()) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080086 // special case: <value type="tristate">n</value> matches if the config doesn't exist.
87 if (matrixConfig.second == KernelConfigTypedValue::gMissingConfig) {
88 continue;
89 }
90 if (error != nullptr) {
91 *error = "Missing config " + key;
92 }
93 return false;
94 }
95 const std::string &kernelValue = it->second;
96 if (!matrixConfig.second.matchValue(kernelValue)) {
97 if (error != nullptr) {
98 *error = "For config " + key + ", value = " + kernelValue
99 + " but required " + to_string(matrixConfig.second);
100 }
101 return false;
102 }
103 }
Yifan Hongf3029302017-04-12 17:23:49 -0700104
105 const Version &matAvb = mat.framework.mAvbMetaVersion;
106 if (mAvbBootVersion.majorVer != matAvb.majorVer ||
107 mAvbBootVersion.minorVer < matAvb.minorVer ||
108 mAvbInitVersion.majorVer != matAvb.majorVer ||
109 mAvbInitVersion.minorVer < matAvb.minorVer) {
110 return false;
111 }
112
Yifan Hongc66ad1e2017-02-08 20:19:45 -0800113 return true;
114}
115
Yifan Hongccf967b2017-01-18 11:04:19 -0800116} // namespace vintf
117} // namespace android