• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 #pragma once
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include "MatrixKernel.h"
24 #include "Version.h"
25 
26 namespace android {
27 namespace vintf {
28 
29 namespace details {
30 class MockRuntimeInfo;
31 struct StaticRuntimeInfo;
32 }  // namespace details
33 
34 // KernelInfo includes kernel-specific information on a device.
35 class KernelInfo {
36    public:
37     KernelInfo() = default;
38 
39     const KernelVersion& version() const;
40     const std::map<std::string, std::string>& configs() const;
41 
42     // mVersion = x'.y'.z', minLts = x.y.z,
43     // match if x == x' , y == y' , and z <= z'.
44     bool matchKernelVersion(const KernelVersion& minLts) const;
45     // return true if all kernel configs in matrixConfigs matches.
46     bool matchKernelConfigs(const std::vector<KernelConfig>& matrixConfigs,
47                             std::string* error = nullptr) const;
48     // return vector of pointers to elements in "kernels" that this matches
49     // kernel requirement specified.
50     std::vector<const MatrixKernel*> getMatchedKernelRequirements(
51         const std::vector<MatrixKernel>& kernels, Level kernelLevel,
52         std::string* error = nullptr) const;
53     bool operator==(const KernelInfo& other) const;
54 
55     // Merge information from "other".
56     bool merge(KernelInfo* other, std::string* error = nullptr);
57 
58    private:
59     friend class AssembleVintfImpl;
60     friend class details::MockRuntimeInfo;
61     friend struct details::StaticRuntimeInfo;
62     friend struct HalManifest;
63     friend struct KernelInfoConverter;
64     friend struct LibVintfTest;
65     friend struct RuntimeInfoFetcher;
66     friend struct RuntimeInfo;
67 
68     std::vector<const MatrixKernel*> getMatchedKernelVersionAndConfigs(
69         const std::vector<const MatrixKernel*>& kernels, std::string* error) const;
70 
71     // The kernel FCM version.
72     // This API is for internal use only, depending on the parent object that contains this
73     // KernelInfo. For public clients of libvintf, use VintfObject::getKernelLevel().
74     Level level() const;
75 
76     // x.y.z
77     KernelVersion mVersion;
78     // /proc/config.gz
79     // Key: CONFIG_xxx; Value: the value after = sign.
80     std::map<std::string, std::string> mConfigs;
81     // Kernel FCM version
82     Level mLevel = Level::UNSPECIFIED;
83 };
84 
85 }  // namespace vintf
86 }  // namespace android
87