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