xref: /aosp_15_r20/system/libvintf/include/vintf/ManifestHal.h (revision 70a7ec852fcefd15a4fb57f8f183a8b1c3aacb08)
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 
18 #ifndef ANDROID_VINTF_MANIFEST_HAL_H
19 #define ANDROID_VINTF_MANIFEST_HAL_H
20 
21 #include <map>
22 #include <optional>
23 #include <set>
24 #include <string>
25 #include <vector>
26 
27 #include <vintf/ExclusiveTo.h>
28 #include <vintf/FqInstance.h>
29 #include <vintf/HalFormat.h>
30 #include <vintf/HalInterface.h>
31 #include <vintf/Level.h>
32 #include <vintf/ManifestInstance.h>
33 #include <vintf/TransportArch.h>
34 #include <vintf/Version.h>
35 #include <vintf/WithFileName.h>
36 
37 namespace android {
38 namespace vintf {
39 
40 // A component of HalManifest.
41 struct ManifestHal : public WithFileName {
42     using InstanceType = ManifestInstance;
43 
44     ManifestHal() = default;
45 
46     bool operator==(const ManifestHal &other) const;
47 
48     HalFormat format = HalFormat::HIDL;
49     std::string name;
50     std::vector<Version> versions;
51     TransportArch transportArch;
52     // If this is set to something other than EMPTY, the service is only
53     // accessible by specific means like through a Trusty VM, and not
54     // available on the host device.
55     ExclusiveTo exclusiveTo = ExclusiveTo::EMPTY;
56 
transportManifestHal57     inline Transport transport() const {
58         return transportArch.transport;
59     }
60 
archManifestHal61     inline Arch arch() const { return transportArch.arch; }
ipManifestHal62     inline std::optional<std::string> ip() const { return transportArch.ip; }
portManifestHal63     inline std::optional<uint64_t> port() const { return transportArch.port; }
64 
getExclusiveToManifestHal65     ExclusiveTo getExclusiveTo() const { return exclusiveTo; }
getNameManifestHal66     inline const std::string& getName() const { return name; }
updatableViaSystemManifestHal67     inline bool updatableViaSystem() const { return mUpdatableViaSystem; }
68 
69     // Assume isValid().
70     bool forEachInstance(const std::function<bool(const ManifestInstance&)>& func) const;
71 
isOverrideManifestHal72     bool isOverride() const { return mIsOverride; }
updatableViaApexManifestHal73     const std::optional<std::string>& updatableViaApex() const { return mUpdatableViaApex; }
74 
75     // Returns the name of the accessor interface for this HAL.
76     // If not set, no accessor will be used.
accessorManifestHal77     const std::optional<std::string>& accessor() const { return mAccessor; }
78 
79     // When true, the existence of this <hal> tag means the component does NOT
80     // exist on the device. This is useful for ODM manifests to specify that
81     // a HAL is disabled on certain products.
82     bool isDisabledHal() const;
83 
getMaxLevelManifestHal84     Level getMaxLevel() const { return mMaxLevel; }
getMinLevelManifestHal85     Level getMinLevel() const { return mMinLevel; }
86 
87    private:
88     friend struct LibVintfTest;
89     friend struct ManifestHalConverter;
90     friend struct HalManifest;
91     friend bool parse(const std::string &s, ManifestHal *hal);
92 
93     // Whether this hal is a valid one. Note that an empty ManifestHal
94     // (constructed via ManifestHal()) is valid.
95     bool isValid(std::string* error = nullptr) const;
96 
97     // Return all versions mentioned by <version>s and <fqname>s.
98     void appendAllVersions(std::set<Version>* ret) const;
99 
100     // insert instances to mManifestInstances.
101     // Existing instances will be ignored.
102     // Pre: all instances to be inserted must satisfy
103     // !hasPackage() && hasVersion() && hasInterface() && hasInstance()
104     bool insertInstance(const FqInstance& fqInstance, bool allowDupMajorVersion,
105                         std::string* error = nullptr);
106     bool insertInstances(const std::set<FqInstance>& fqInstances, bool allowDupMajorVersion,
107                          std::string* error = nullptr);
108 
109     // Verify instance before inserting.
110     bool verifyInstance(const FqInstance& fqInstance, std::string* error = nullptr) const;
111 
112     bool mIsOverride = false;
113     std::optional<std::string> mAccessor;
114     std::optional<std::string> mUpdatableViaApex;
115     bool mUpdatableViaSystem = false;
116     // All instances specified with <fqname> and <version> x <interface> x <instance>
117     std::set<ManifestInstance> mManifestInstances;
118 
119     // Max level of this HAL (inclusive). Only valid for framework manifest HALs.
120     // If set, HALs with max-level < target FCM version in device manifest is
121     // disabled.
122     Level mMaxLevel = Level::UNSPECIFIED;
123     // Min level of this HAL (inclusive). Only valid for framework manifest HALs.
124     // If set, HALs with max-level > target FCM version in device manifest is
125     // disabled.
126     Level mMinLevel = Level::UNSPECIFIED;
127 };
128 
129 } // namespace vintf
130 } // namespace android
131 
132 #endif // ANDROID_VINTF_MANIFEST_HAL_H
133