lin
2025-07-30 fcd736bf35fd93b563e9bbf594f2aa7b62028cc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#ifndef ANDROID_VINTF_RUNTIME_INFO_H
#define ANDROID_VINTF_RUNTIME_INFO_H
 
#include "Version.h"
 
#include <map>
#include <string>
#include <vector>
 
#include <utils/Errors.h>
 
#include "CheckFlags.h"
#include "KernelInfo.h"
#include "MatrixKernel.h"
#include "Version.h"
 
namespace android {
namespace vintf {
 
struct CompatibilityMatrix;
 
// Runtime Info sent to OTA server
struct RuntimeInfo {
 
    RuntimeInfo() {}
    virtual ~RuntimeInfo() = default;
 
    // /proc/version
    // utsname.sysname
    const std::string &osName() const;
    // utsname.nodename
    const std::string &nodeName() const;
    // utsname.release
    const std::string &osRelease() const;
    // utsname.version
    const std::string &osVersion() const;
    // utsname.machine
    const std::string &hardwareId() const;
    // extract from utsname.release
    const KernelVersion &kernelVersion() const;
 
    const std::map<std::string, std::string> &kernelConfigs() const;
 
    const Version &bootVbmetaAvbVersion() const;
    const Version &bootAvbVersion() const;
 
    // /proc/cpuinfo
    const std::string &cpuInfo() const;
 
    // /sys/fs/selinux/policyvers
    size_t kernelSepolicyVersion() const;
 
    // Return whether this RuntimeInfo works with the given compatibility matrix. Return true if:
    // - mat is a framework compat-mat
    // - sepolicy.kernel-sepolicy-version == kernelSepolicyVersion()
    // - /proc/config.gz matches the requirements. Note that /proc/config.gz is read when the
    //   RuntimeInfo object is created (the first time VintfObject::GetRuntimeInfo is called),
    //   not when RuntimeInfo::checkCompatibility is called.
    // - avb-vbmetaversion matches related sysprops
    bool checkCompatibility(const CompatibilityMatrix& mat, std::string* error = nullptr,
                            CheckFlags::Type flags = CheckFlags::DEFAULT) const;
 
    using FetchFlags = uint32_t;
    enum FetchFlag : FetchFlags {
        CPU_VERSION     = 1 << 0,
        CONFIG_GZ       = 1 << 1,
        CPU_INFO        = 1 << 2,
        POLICYVERS      = 1 << 3,
        AVB             = 1 << 4,
        LAST_PLUS_ONE,
 
        NONE = 0,
        ALL = ((LAST_PLUS_ONE - 1) << 1) - 1,
    };
 
   protected:
    virtual status_t fetchAllInformation(FetchFlags flags);
 
    friend struct RuntimeInfoFetcher;
    friend class VintfObject;
    friend struct LibVintfTest;
    friend std::string dump(const RuntimeInfo& ki, bool);
 
    // /proc/config.gz
    // Key: CONFIG_xxx; Value: the value after = sign.
    KernelInfo mKernel;
    std::string mOsName;
    std::string mNodeName;
    std::string mOsRelease;
    std::string mOsVersion;
    std::string mHardwareId;
 
    std::vector<std::string> mSepolicyFilePaths;
    std::string mCpuInfo;
    Version mBootVbmetaAvbVersion;
    Version mBootAvbVersion;
 
    size_t mKernelSepolicyVersion = 0u;
};
 
} // namespace vintf
} // namespace android
 
#endif // ANDROID_VINTF_RUNTIME_INFO_H