blob: f9f8d8b61a2d9898a409947bbc1009086a5b044c [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 Honga7201e72017-02-17 10:09:59 -080048size_t RuntimeInfo::kernelSepolicyVersion() const {
Yifan Hongccf967b2017-01-18 11:04:19 -080049 return mKernelSepolicyVersion;
50}
51
Yifan Honga7201e72017-02-17 10:09:59 -080052bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix &mat,
Yifan Hongc66ad1e2017-02-08 20:19:45 -080053 std::string *error) const {
Yifan Hong7c7d7062017-04-04 16:26:51 -070054 if (mat.mType != SchemaType::FRAMEWORK) {
55 if (error != nullptr) {
56 *error = "Should not check runtime info against " + to_string(mat.mType)
57 + " compatibility matrix.";
58 }
59 return false;
60 }
61 if (kernelSepolicyVersion() != mat.framework.mSepolicy.kernelSepolicyVersion()) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080062 if (error != nullptr) {
63 *error = "kernelSepolicyVersion = " + to_string(kernelSepolicyVersion())
Yifan Hong7c7d7062017-04-04 16:26:51 -070064 + " but required " + to_string(mat.framework.mSepolicy.kernelSepolicyVersion());
Yifan Hongc66ad1e2017-02-08 20:19:45 -080065 }
66 return false;
67 }
68
Yifan Honge8b7d952017-04-04 15:44:26 -070069 // TODO(b/35217573): check sepolicy version against mat.mSepolicy.sepolicyVersion() here.
Yifan Hongc66ad1e2017-02-08 20:19:45 -080070
71 const MatrixKernel *matrixKernel = mat.findKernel(this->mKernelVersion);
72 if (matrixKernel == nullptr) {
73 if (error != nullptr) {
74 *error = "Cannot find suitable kernel entry for " + to_string(mKernelVersion);
75 }
76 return false;
77 }
78 for (const KernelConfig &matrixConfig : matrixKernel->configs()) {
79 const std::string &key = matrixConfig.first;
Yifan Hongf1af7522017-02-16 18:00:55 -080080 auto it = this->mKernelConfigs.find(key);
81 if (it == this->mKernelConfigs.end()) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080082 // special case: <value type="tristate">n</value> matches if the config doesn't exist.
83 if (matrixConfig.second == KernelConfigTypedValue::gMissingConfig) {
84 continue;
85 }
86 if (error != nullptr) {
87 *error = "Missing config " + key;
88 }
89 return false;
90 }
91 const std::string &kernelValue = it->second;
92 if (!matrixConfig.second.matchValue(kernelValue)) {
93 if (error != nullptr) {
94 *error = "For config " + key + ", value = " + kernelValue
95 + " but required " + to_string(matrixConfig.second);
96 }
97 return false;
98 }
99 }
100 return true;
101}
102
Yifan Hongccf967b2017-01-18 11:04:19 -0800103} // namespace vintf
104} // namespace android