• 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; }
67 
getNameManifestHal68     inline const std::string& getName() const { return name; }
69 
70     // Assume isValid().
71     bool forEachInstance(const std::function<bool(const ManifestInstance&)>& func) const;
72 
isOverrideManifestHal73     bool isOverride() const { return mIsOverride; }
updatableViaApexManifestHal74     const std::optional<std::string>& updatableViaApex() const { return mUpdatableViaApex; }
75 
76     // When true, the existence of this <hal> tag means the component does NOT
77     // exist on the device. This is useful for ODM manifests to specify that
78     // a HAL is disabled on certain products.
79     bool isDisabledHal() const;
80 
getMaxLevelManifestHal81     Level getMaxLevel() const { return mMaxLevel; }
82 
83    private:
84     friend struct LibVintfTest;
85     friend struct ManifestHalConverter;
86     friend struct HalManifest;
87     friend bool parse(const std::string &s, ManifestHal *hal);
88 
89     // Whether this hal is a valid one. Note that an empty ManifestHal
90     // (constructed via ManifestHal()) is valid.
91     bool isValid(std::string* error = nullptr) const;
92 
93     // Return all versions mentioned by <version>s and <fqname>s.
94     void appendAllVersions(std::set<Version>* ret) const;
95 
96     // insert instances to mAdditionalInstances.
97     // Existing instances will be ignored.
98     // Pre: all instances to be inserted must satisfy
99     // !hasPackage() && hasVersion() && hasInterface() && hasInstance()
100     bool insertInstance(const FqInstance& fqInstance, std::string* error = nullptr);
101     bool insertInstances(const std::set<FqInstance>& fqInstances, std::string* error = nullptr);
102 
103     // Verify instance before inserting.
104     bool verifyInstance(const FqInstance& fqInstance, std::string* error = nullptr) const;
105 
106     bool mIsOverride = false;
107     std::optional<std::string> mUpdatableViaApex;
108     // Additional instances to <version> x <interface> x <instance>.
109     std::set<ManifestInstance> mAdditionalInstances;
110 
111     // Max level of this HAL. Only valid for framework manifest HALs.
112     // If set, HALs with max-level < target FCM version in device manifest is
113     // disabled.
114     Level mMaxLevel = Level::UNSPECIFIED;
115 };
116 
117 } // namespace vintf
118 } // namespace android
119 
120 #endif // ANDROID_VINTF_MANIFEST_HAL_H
121