• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ANDROID_VINTF_RUNTIME_INFO_H
18 #define ANDROID_VINTF_RUNTIME_INFO_H
19 
20 #include "Version.h"
21 
22 #include <map>
23 #include <string>
24 #include <vector>
25 
26 #include <utils/Errors.h>
27 
28 #include "DisabledChecks.h"
29 #include "MatrixKernel.h"
30 #include "Version.h"
31 
32 namespace android {
33 namespace vintf {
34 
35 struct CompatibilityMatrix;
36 
37 // Runtime Info sent to OTA server
38 struct RuntimeInfo {
39 
RuntimeInfoRuntimeInfo40     RuntimeInfo() {}
41 
42     // /proc/version
43     // utsname.sysname
44     const std::string &osName() const;
45     // utsname.nodename
46     const std::string &nodeName() const;
47     // utsname.release
48     const std::string &osRelease() const;
49     // utsname.version
50     const std::string &osVersion() const;
51     // utsname.machine
52     const std::string &hardwareId() const;
53     // extract from utsname.release
54     const KernelVersion &kernelVersion() const;
55 
56     const std::map<std::string, std::string> &kernelConfigs() const;
57 
58     const Version &bootVbmetaAvbVersion() const;
59     const Version &bootAvbVersion() const;
60 
61     // /proc/cpuinfo
62     const std::string &cpuInfo() const;
63 
64     // /sys/fs/selinux/policyvers
65     size_t kernelSepolicyVersion() const;
66 
67     // Return whether this RuntimeInfo works with the given compatibility matrix. Return true if:
68     // - mat is a framework compat-mat
69     // - sepolicy.kernel-sepolicy-version == kernelSepolicyVersion()
70     // - /proc/config.gz matches the requirements. Note that /proc/config.gz is read when the
71     //   RuntimeInfo object is created (the first time VintfObject::GetRuntimeInfo is called),
72     //   not when RuntimeInfo::checkCompatibility is called.
73     // - avb-vbmetaversion matches related sysprops
74     bool checkCompatibility(const CompatibilityMatrix& mat, std::string* error = nullptr,
75                             DisabledChecks disabledChecks = ENABLE_ALL_CHECKS) const;
76 
77    private:
78     friend struct RuntimeInfoFetcher;
79     friend class VintfObject;
80     friend struct LibVintfTest;
81     friend std::string dump(const RuntimeInfo &ki);
82 
83     status_t fetchAllInformation();
84 
85     // mKernelVersion = x'.y'.z', minLts = x.y.z,
86     // match if x == x' , y == y' , and z <= z'.
87     bool matchKernelVersion(const KernelVersion& minLts) const;
88     // return true if all kernel configs in matrixConfigs matches.
89     bool matchKernelConfigs(const std::vector<KernelConfig>& matrixConfigs,
90                             std::string* error = nullptr) const;
91 
92     // /proc/config.gz
93     // Key: CONFIG_xxx; Value: the value after = sign.
94     std::map<std::string, std::string> mKernelConfigs;
95     std::string mOsName;
96     std::string mNodeName;
97     std::string mOsRelease;
98     std::string mOsVersion;
99     std::string mHardwareId;
100     KernelVersion mKernelVersion;
101 
102     std::vector<std::string> mSepolicyFilePaths;
103     std::string mCpuInfo;
104     Version mBootVbmetaAvbVersion;
105     Version mBootAvbVersion;
106 
107     size_t mKernelSepolicyVersion = 0u;
108 };
109 
110 } // namespace vintf
111 } // namespace android
112 
113 #endif // ANDROID_VINTF_RUNTIME_INFO_H
114