blob: df09958b3acdf1b56e7d7e6a74bbdc7d1829412f [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 {
Yifan Hong90ed9972018-12-03 15:08:34 -080049 return mKernel.version();
Yifan Hongab0e6e72017-04-26 11:43:47 -070050}
51
Yifan Hongab0e6e72017-04-26 11:43:47 -070052const std::map<std::string, std::string> &RuntimeInfo::kernelConfigs() const {
Yifan Hong90ed9972018-12-03 15:08:34 -080053 return mKernel.configs();
Yifan Hongab0e6e72017-04-26 11:43:47 -070054}
55
Yifan Honga7201e72017-02-17 10:09:59 -080056size_t RuntimeInfo::kernelSepolicyVersion() const {
Yifan Hongccf967b2017-01-18 11:04:19 -080057 return mKernelSepolicyVersion;
58}
59
Yifan Hong242eabf2017-04-20 14:06:26 -070060const std::string &RuntimeInfo::cpuInfo() const {
61 return mCpuInfo;
62}
63
Yifan Hongab0e6e72017-04-26 11:43:47 -070064const Version &RuntimeInfo::bootVbmetaAvbVersion() const {
65 return mBootVbmetaAvbVersion;
66}
67
68const Version &RuntimeInfo::bootAvbVersion() const {
69 return mBootAvbVersion;
70}
71
Yifan Hongdb6423e2017-09-11 14:38:46 -070072bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix& mat, std::string* error,
Yifan Hong072f12d2018-08-08 13:04:51 -070073 CheckFlags::Type flags) const {
Yifan Hong7c7d7062017-04-04 16:26:51 -070074 if (mat.mType != SchemaType::FRAMEWORK) {
75 if (error != nullptr) {
76 *error = "Should not check runtime info against " + to_string(mat.mType)
77 + " compatibility matrix.";
78 }
79 return false;
80 }
Yifan Hong98935522018-04-16 09:16:41 -070081 if (kernelSepolicyVersion() < mat.framework.mSepolicy.kernelSepolicyVersion()) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080082 if (error != nullptr) {
Yifan Hong98935522018-04-16 09:16:41 -070083 *error =
84 "kernelSepolicyVersion = " + to_string(kernelSepolicyVersion()) +
85 " but required >= " + to_string(mat.framework.mSepolicy.kernelSepolicyVersion());
Yifan Hongc66ad1e2017-02-08 20:19:45 -080086 }
87 return false;
88 }
89
Yifan Hongd776d202017-08-23 12:56:31 -070090 // mat.mSepolicy.sepolicyVersion() is checked against static
91 // HalManifest.device.mSepolicyVersion in HalManifest::checkCompatibility.
Yifan Hongc66ad1e2017-02-08 20:19:45 -080092
Yifan Hong0df914b2018-10-04 12:33:46 -070093 if (flags.isKernelEnabled()) {
Yifan Hong89093ed2019-12-12 12:16:01 -080094 if (mKernel.getMatchedKernelRequirements(mat.framework.mKernels, kernelLevel(), error)
95 .empty()) {
Yifan Hongd776d202017-08-23 12:56:31 -070096 return false;
97 }
Yifan Hongc66ad1e2017-02-08 20:19:45 -080098 }
Yifan Hongf3029302017-04-12 17:23:49 -070099
Yifan Hong072f12d2018-08-08 13:04:51 -0700100 if (flags.isAvbEnabled()) {
Yifan Hongdb6423e2017-09-11 14:38:46 -0700101 const Version& matAvb = mat.framework.mAvbMetaVersion;
102 if (mBootAvbVersion.majorVer != matAvb.majorVer ||
103 mBootAvbVersion.minorVer < matAvb.minorVer) {
104 if (error != nullptr) {
105 std::stringstream ss;
106 ss << "AVB version " << mBootAvbVersion << " does not match framework matrix "
107 << matAvb;
108 *error = ss.str();
109 }
110 return false;
Michael Schwartz5cfbc922017-05-08 14:06:49 -0700111 }
Yifan Hongdb6423e2017-09-11 14:38:46 -0700112 if (mBootVbmetaAvbVersion.majorVer != matAvb.majorVer ||
113 mBootVbmetaAvbVersion.minorVer < matAvb.minorVer) {
114 if (error != nullptr) {
115 std::stringstream ss;
116 ss << "Vbmeta version " << mBootVbmetaAvbVersion
117 << " does not match framework matrix " << matAvb;
118 *error = ss.str();
119 }
120 return false;
Michael Schwartz5cfbc922017-05-08 14:06:49 -0700121 }
Yifan Hongf3029302017-04-12 17:23:49 -0700122 }
123
Yifan Hongc66ad1e2017-02-08 20:19:45 -0800124 return true;
125}
126
Yifan Hongf3247982019-12-12 12:11:36 -0800127void RuntimeInfo::setKernelLevel(Level level) {
128 mKernel.mLevel = level;
129}
130
131Level RuntimeInfo::kernelLevel() const {
132 return mKernel.mLevel;
133}
134
Yifan Hongccf967b2017-01-18 11:04:19 -0800135} // namespace vintf
136} // namespace android