blob: cee5d8941013413f33a397bd57ef47473e88219a [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 Hongab0e6e72017-04-26 11:43:47 -070048const KernelVersion &RuntimeInfo::kernelVersion() const {
49 return mKernelVersion;
50}
51
52
Yifan Hongfa2b18b2017-04-12 19:40:00 -070053const std::vector<std::string> &RuntimeInfo::sepolicyFilePaths() const {
54 return mSepolicyFilePaths;
55}
56
Yifan Hongab0e6e72017-04-26 11:43:47 -070057const std::map<std::string, std::string> &RuntimeInfo::kernelConfigs() const {
58 return mKernelConfigs;
59}
60
Yifan Honga7201e72017-02-17 10:09:59 -080061size_t RuntimeInfo::kernelSepolicyVersion() const {
Yifan Hongccf967b2017-01-18 11:04:19 -080062 return mKernelSepolicyVersion;
63}
64
Yifan Hong242eabf2017-04-20 14:06:26 -070065const std::string &RuntimeInfo::cpuInfo() const {
66 return mCpuInfo;
67}
68
Yifan Hongab0e6e72017-04-26 11:43:47 -070069const Version &RuntimeInfo::bootVbmetaAvbVersion() const {
70 return mBootVbmetaAvbVersion;
71}
72
73const Version &RuntimeInfo::bootAvbVersion() const {
74 return mBootAvbVersion;
75}
76
Yifan Honga7201e72017-02-17 10:09:59 -080077bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix &mat,
Yifan Hongc66ad1e2017-02-08 20:19:45 -080078 std::string *error) const {
Yifan Hong7c7d7062017-04-04 16:26:51 -070079 if (mat.mType != SchemaType::FRAMEWORK) {
80 if (error != nullptr) {
81 *error = "Should not check runtime info against " + to_string(mat.mType)
82 + " compatibility matrix.";
83 }
84 return false;
85 }
86 if (kernelSepolicyVersion() != mat.framework.mSepolicy.kernelSepolicyVersion()) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080087 if (error != nullptr) {
88 *error = "kernelSepolicyVersion = " + to_string(kernelSepolicyVersion())
Yifan Hong7c7d7062017-04-04 16:26:51 -070089 + " but required " + to_string(mat.framework.mSepolicy.kernelSepolicyVersion());
Yifan Hongc66ad1e2017-02-08 20:19:45 -080090 }
91 return false;
92 }
93
Yifan Hongf3029302017-04-12 17:23:49 -070094 // mat.mSepolicy.sepolicyVersion() is checked against static HalManifest.device.mSepolicyVersion
Yifan Hongc66ad1e2017-02-08 20:19:45 -080095
96 const MatrixKernel *matrixKernel = mat.findKernel(this->mKernelVersion);
97 if (matrixKernel == nullptr) {
98 if (error != nullptr) {
99 *error = "Cannot find suitable kernel entry for " + to_string(mKernelVersion);
100 }
101 return false;
102 }
103 for (const KernelConfig &matrixConfig : matrixKernel->configs()) {
104 const std::string &key = matrixConfig.first;
Yifan Hongf1af7522017-02-16 18:00:55 -0800105 auto it = this->mKernelConfigs.find(key);
106 if (it == this->mKernelConfigs.end()) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -0800107 // special case: <value type="tristate">n</value> matches if the config doesn't exist.
108 if (matrixConfig.second == KernelConfigTypedValue::gMissingConfig) {
109 continue;
110 }
111 if (error != nullptr) {
112 *error = "Missing config " + key;
113 }
114 return false;
115 }
116 const std::string &kernelValue = it->second;
117 if (!matrixConfig.second.matchValue(kernelValue)) {
118 if (error != nullptr) {
119 *error = "For config " + key + ", value = " + kernelValue
120 + " but required " + to_string(matrixConfig.second);
121 }
122 return false;
123 }
124 }
Yifan Hongf3029302017-04-12 17:23:49 -0700125
126 const Version &matAvb = mat.framework.mAvbMetaVersion;
Yifan Hong881a9e452017-04-27 19:31:13 -0700127 if (mBootAvbVersion.majorVer != matAvb.majorVer ||
128 mBootAvbVersion.minorVer < matAvb.minorVer ||
129 mBootVbmetaAvbVersion.majorVer != matAvb.majorVer ||
130 mBootVbmetaAvbVersion.minorVer < matAvb.minorVer) {
Yifan Hongf3029302017-04-12 17:23:49 -0700131 return false;
132 }
133
Yifan Hongc66ad1e2017-02-08 20:19:45 -0800134 return true;
135}
136
Yifan Hongccf967b2017-01-18 11:04:19 -0800137} // namespace vintf
138} // namespace android