• 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 "CheckFlags.h"
29 #include "KernelInfo.h"
30 #include "MatrixKernel.h"
31 #include "Version.h"
32 
33 namespace android {
34 namespace vintf {
35 
36 namespace testing {
37 class VintfObjectRuntimeInfoTest;
38 }  // namespace testing
39 
40 struct CompatibilityMatrix;
41 
42 // Runtime Info sent to OTA server
43 struct RuntimeInfo {
44 
RuntimeInfoRuntimeInfo45     RuntimeInfo() {}
46     virtual ~RuntimeInfo() = default;
47 
48     // /proc/version
49     // utsname.sysname
50     const std::string &osName() const;
51     // utsname.nodename
52     const std::string &nodeName() const;
53     // utsname.release
54     const std::string &osRelease() const;
55     // utsname.version
56     const std::string &osVersion() const;
57     // utsname.machine
58     const std::string &hardwareId() const;
59     // extract from utsname.release
60     const KernelVersion &kernelVersion() const;
61 
62     const std::map<std::string, std::string> &kernelConfigs() const;
63 
64     const Version &bootVbmetaAvbVersion() const;
65     const Version &bootAvbVersion() const;
66 
67     // /proc/cpuinfo
68     const std::string &cpuInfo() const;
69 
70     // /sys/fs/selinux/policyvers
71     size_t kernelSepolicyVersion() const;
72 
73     // Return whether this RuntimeInfo works with the given compatibility matrix. Return true if:
74     // - mat is a framework compat-mat
75     // - sepolicy.kernel-sepolicy-version == kernelSepolicyVersion()
76     // - /proc/config.gz matches the requirements. Note that /proc/config.gz is read when the
77     //   RuntimeInfo object is created (the first time VintfObject::GetRuntimeInfo is called),
78     //   not when RuntimeInfo::checkCompatibility is called.
79     // - avb-vbmetaversion matches related sysprops
80     bool checkCompatibility(const CompatibilityMatrix& mat, std::string* error = nullptr,
81                             CheckFlags::Type flags = CheckFlags::DEFAULT) const;
82 
83 
84     using FetchFlags = uint32_t;
85     enum FetchFlag : FetchFlags {
86         CPU_VERSION = 1 << 0,
87         CONFIG_GZ = 1 << 1,
88         CPU_INFO = 1 << 2,
89         POLICYVERS = 1 << 3,
90         AVB = 1 << 4,
91         KERNEL_FCM = 1 << 5,
92         LAST_PLUS_ONE,
93 
94         NONE = 0,
95         ALL = ((LAST_PLUS_ONE - 1) << 1) - 1,
96     };
97 
98     Level kernelLevel() const;
99 
100    protected:
101     virtual status_t fetchAllInformation(FetchFlags flags);
102 
103     void setKernelLevel(Level level);
104 
105     friend struct RuntimeInfoFetcher;
106     friend class VintfObject;
107     friend struct LibVintfTest;
108     friend std::string dump(const RuntimeInfo& ki, bool);
109     friend class testing::VintfObjectRuntimeInfoTest;
110 
111     // /proc/config.gz
112     // Key: CONFIG_xxx; Value: the value after = sign.
113     KernelInfo mKernel;
114     std::string mOsName;
115     std::string mNodeName;
116     std::string mOsRelease;
117     std::string mOsVersion;
118     std::string mHardwareId;
119 
120     std::vector<std::string> mSepolicyFilePaths;
121     std::string mCpuInfo;
122     Version mBootVbmetaAvbVersion;
123     Version mBootAvbVersion;
124 
125     size_t mKernelSepolicyVersion = 0u;
126 };
127 
128 } // namespace vintf
129 } // namespace android
130 
131 #endif // ANDROID_VINTF_RUNTIME_INFO_H
132