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_COMPATIBILITY_MATRIX_H
18 #define ANDROID_VINTF_COMPATIBILITY_MATRIX_H
19 
20 #include <map>
21 #include <string>
22 
23 #include <utils/Errors.h>
24 
25 #include "MatrixHal.h"
26 #include "MatrixKernel.h"
27 #include "MapValueIterator.h"
28 #include "Sepolicy.h"
29 #include "SchemaType.h"
30 #include "Vndk.h"
31 
32 namespace android {
33 namespace vintf {
34 
35 // Compatibility matrix defines what hardware does the framework requires.
36 struct CompatibilityMatrix {
37 
38     // Create a framework compatibility matrix.
CompatibilityMatrixCompatibilityMatrix39     CompatibilityMatrix() : mType(SchemaType::FRAMEWORK) {};
40 
41     SchemaType type() const;
42 
43     constexpr static Version kVersion{1, 0};
44 
45 private:
46     bool add(MatrixHal &&hal);
47     bool add(MatrixKernel &&kernel);
48 
49     // Find a MatrixKernel entry that has version v. nullptr if not found.
50     const MatrixKernel *findKernel(const KernelVersion &v) const;
51 
52     // Return an iterable to all MatrixHal objects. Call it as follows:
53     // for (const MatrixHal &e : cm.getHals()) { }
54     ConstMultiMapValueIterable<std::string, MatrixHal> getHals() const;
55 
56     // for constructing matrix programitically only.
57     MatrixHal *getAnyHal(const std::string &name);
58 
59     status_t fetchAllInformation(const std::string &path);
60 
61     friend struct HalManifest;
62     friend struct RuntimeInfo;
63     friend struct CompatibilityMatrixConverter;
64     friend struct LibVintfTest;
65     friend class VintfObject;
66     friend class AssembleVintf;
67     friend bool operator==(const CompatibilityMatrix &, const CompatibilityMatrix &);
68 
69     SchemaType mType;
70 
71     // sorted map from component name to the entry.
72     std::multimap<std::string, MatrixHal> mHals;
73 
74     // entries only for framework compatibility matrix.
75     struct {
76         std::vector<MatrixKernel> mKernels;
77         Sepolicy mSepolicy;
78         Version mAvbMetaVersion;
79     } framework;
80 
81     // entries only for device compatibility matrix.
82     struct {
83         Vndk mVndk;
84     } device;
85 };
86 
87 } // namespace vintf
88 } // namespace android
89 
90 #endif // ANDROID_VINTF_COMPATIBILITY_MATRIX_H
91