• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <hidl-util/FqInstance.h>
28 
29 #include "HalFormat.h"
30 #include "HalInterface.h"
31 #include "Level.h"
32 #include "ManifestInstance.h"
33 #include "TransportArch.h"
34 #include "Version.h"
35 #include "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 
ManifestHalManifestHal46     ManifestHal(HalFormat fmt, std::string&& n, std::vector<Version>&& vs, TransportArch ta,
47                 std::map<std::string, HalInterface>&& intf)
48         : format(fmt),
49           name(std::move(n)),
50           versions(std::move(vs)),
51           transportArch(ta),
52           interfaces(std::move(intf)) {}
53 
54     bool operator==(const ManifestHal &other) const;
55 
56     HalFormat format = HalFormat::HIDL;
57     std::string name;
58     std::vector<Version> versions;
59     TransportArch transportArch;
60     std::map<std::string, HalInterface> interfaces;
61 
transportManifestHal62     inline Transport transport() const {
63         return transportArch.transport;
64     }
65 
archManifestHal66     inline Arch arch() const { return transportArch.arch; }
ipManifestHal67     inline std::optional<std::string> ip() const { return transportArch.ip; }
portManifestHal68     inline std::optional<uint64_t> port() const { return transportArch.port; }
69 
getNameManifestHal70     inline const std::string& getName() const { return name; }
71 
72     // Assume isValid().
73     bool forEachInstance(const std::function<bool(const ManifestInstance&)>& func) const;
74 
isOverrideManifestHal75     bool isOverride() const { return mIsOverride; }
updatableViaApexManifestHal76     const std::optional<std::string>& updatableViaApex() const { return mUpdatableViaApex; }
77 
78     // When true, the existence of this <hal> tag means the component does NOT
79     // exist on the device. This is useful for ODM manifests to specify that
80     // a HAL is disabled on certain products.
81     bool isDisabledHal() const;
82 
getMaxLevelManifestHal83     Level getMaxLevel() const { return mMaxLevel; }
84 
85    private:
86     friend struct LibVintfTest;
87     friend struct ManifestHalConverter;
88     friend struct HalManifest;
89     friend bool parse(const std::string &s, ManifestHal *hal);
90 
91     // Whether this hal is a valid one. Note that an empty ManifestHal
92     // (constructed via ManifestHal()) is valid.
93     bool isValid(std::string* error = nullptr) const;
94 
95     // Return all versions mentioned by <version>s and <fqname>s.
96     void appendAllVersions(std::set<Version>* ret) const;
97 
98     // insert instances to mAdditionalInstances.
99     // Existing instances will be ignored.
100     // Pre: all instances to be inserted must satisfy
101     // !hasPackage() && hasVersion() && hasInterface() && hasInstance()
102     bool insertInstance(const FqInstance& fqInstance, std::string* error = nullptr);
103     bool insertInstances(const std::set<FqInstance>& fqInstances, std::string* error = nullptr);
104 
105     // Verify instance before inserting.
106     bool verifyInstance(const FqInstance& fqInstance, std::string* error = nullptr) const;
107 
108     bool mIsOverride = false;
109     std::optional<std::string> mUpdatableViaApex;
110     // Additional instances to <version> x <interface> x <instance>.
111     std::set<ManifestInstance> mAdditionalInstances;
112 
113     // Max level of this HAL. Only valid for framework manifest HALs.
114     // If set, HALs with max-level < target FCM version in device manifest is
115     // disabled.
116     Level mMaxLevel = Level::UNSPECIFIED;
117 };
118 
119 } // namespace vintf
120 } // namespace android
121 
122 #endif // ANDROID_VINTF_MANIFEST_HAL_H
123