Add public forEachHidlInstanceOfInterface/Version
- Add private forEachInstanceOfVersion/Interface that takes
an additional HalFormat arg
- Add public forEachHidlInstanceOfVersion/Interface that
only loops over HIDL instances
- Hide existing forEachInstanceOfVersion/Interface because
they do not specify HalFormat. These two functions are deprecated
and will be removed in follow up CL.
Test: libvintf_test
Test: vintf_object_test
Bug: 140832836
Change-Id: Ie4b361f1207f721747cec864511c22ab0be6fe50
diff --git a/VintfObject.cpp b/VintfObject.cpp
index 69fbff6..ce037a5 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -799,7 +799,8 @@
const std::vector<std::string>& /* hintInstances */) {
std::vector<std::pair<std::string, Version>> ret;
deviceManifest->forEachInstanceOfInterface(
- package, version, interface, [&ret](const ManifestInstance& manifestInstance) {
+ HalFormat::HIDL, package, version, interface,
+ [&ret](const ManifestInstance& manifestInstance) {
ret.push_back(
std::make_pair(manifestInstance.instance(), manifestInstance.version()));
return true;
diff --git a/include/vintf/CompatibilityMatrix.h b/include/vintf/CompatibilityMatrix.h
index 475ccbf..54288cc 100644
--- a/include/vintf/CompatibilityMatrix.h
+++ b/include/vintf/CompatibilityMatrix.h
@@ -60,12 +60,13 @@
// (Normally, version ranges do not overlap, and the only match is returned.)
std::string getXmlSchemaPath(const std::string& xmlFileName, const Version& version) const;
+ std::string getVendorNdkVersion() const;
+
+ protected:
bool forEachInstanceOfVersion(
const std::string& package, const Version& expectVersion,
const std::function<bool(const MatrixInstance&)>& func) const override;
- std::string getVendorNdkVersion() const;
-
private:
// Add everything in inputMatrix to "this" as requirements.
bool addAll(Named<CompatibilityMatrix>* inputMatrix, std::string* error);
diff --git a/include/vintf/HalGroup.h b/include/vintf/HalGroup.h
index 7e0f51f..ccb869c 100644
--- a/include/vintf/HalGroup.h
+++ b/include/vintf/HalGroup.h
@@ -100,7 +100,7 @@
return true;
}
- public:
+ protected:
// Apply func to all instances of package@expectVersion::*/*.
// For example, if a.h.foo@1.1::IFoo/default is in "this" and getFqInstances
// is called with a.h.foo@1.0, then a.h.foo@1.1::IFoo/default is returned.
@@ -123,6 +123,57 @@
});
}
+ // Apply func to all instances of package@expectVersion::*/*.
+ // For example, if a.h.foo@1.1::IFoo/default is in "this" and getFqInstances
+ // is called with a.h.foo@1.0, then a.h.foo@1.1::IFoo/default is returned.
+ // If format is AIDL, expectVersion should be the fake AIDL version.
+ bool forEachInstanceOfVersion(HalFormat format, const std::string& package,
+ const Version& expectVersion,
+ const std::function<bool(const InstanceType&)>& func) const {
+ return forEachInstanceOfVersion(package, expectVersion,
+ [&func, format](const InstanceType& e) {
+ if (e.format() == format) {
+ return func(e);
+ }
+ return true;
+ });
+ }
+
+ // Apply func to instances of package@expectVersion::interface/*.
+ // For example, if a.h.foo@1.1::IFoo/default is in "this" and getFqInstances
+ // is called with a.h.foo@1.0::IFoo, then a.h.foo@1.1::IFoo/default is returned.
+ // If format is AIDL, expectVersion should be the fake AIDL version.
+ bool forEachInstanceOfInterface(HalFormat format, const std::string& package,
+ const Version& expectVersion, const std::string& interface,
+ const std::function<bool(const InstanceType&)>& func) const {
+ return forEachInstanceOfVersion(format, package, expectVersion,
+ [&func, &interface](const InstanceType& e) {
+ if (e.interface() == interface) {
+ return func(e);
+ }
+ return true;
+ });
+ }
+
+ public:
+ // Apply func to all instances of package@expectVersion::*/*.
+ // For example, if a.h.foo@1.1::IFoo/default is in "this" and getFqInstances
+ // is called with a.h.foo@1.0, then a.h.foo@1.1::IFoo/default is returned.
+ virtual bool forEachHidlInstanceOfVersion(
+ const std::string& package, const Version& expectVersion,
+ const std::function<bool(const InstanceType&)>& func) const {
+ return forEachInstanceOfVersion(HalFormat::HIDL, package, expectVersion, func);
+ }
+
+ // Apply func to instances of package@expectVersion::interface/*.
+ // For example, if a.h.foo@1.1::IFoo/default is in "this" and getFqInstances
+ // is called with a.h.foo@1.0::IFoo, then a.h.foo@1.1::IFoo/default is returned.
+ bool forEachHidlInstanceOfInterface(
+ const std::string& package, const Version& expectVersion, const std::string& interface,
+ const std::function<bool(const InstanceType&)>& func) const {
+ return forEachInstanceOfInterface(HalFormat::HIDL, package, expectVersion, interface, func);
+ }
+
// Alternative to forEachInstanceOfInterface if you need a vector instead.
// If interface is empty, returns all instances of package@version;
// else return all instances of package@version::interface.
diff --git a/include/vintf/HalManifest.h b/include/vintf/HalManifest.h
index a3f278b..988effd 100644
--- a/include/vintf/HalManifest.h
+++ b/include/vintf/HalManifest.h
@@ -110,10 +110,6 @@
// Get metaversion of this manifest.
Version getMetaVersion() const;
- bool forEachInstanceOfVersion(
- const std::string& package, const Version& expectVersion,
- const std::function<bool(const ManifestInstance&)>& func) const override;
-
// Alternative to forEachInstance if you just need a set of instance names instead.
std::set<std::string> getInstances(const std::string& halName, const Version& version,
const std::string& interfaceName) const;
@@ -140,6 +136,10 @@
bool shouldAdd(const ManifestHal& toAdd) const override;
bool shouldAddXmlFile(const ManifestXmlFile& toAdd) const override;
+ bool forEachInstanceOfVersion(
+ const std::string& package, const Version& expectVersion,
+ const std::function<bool(const ManifestInstance&)>& func) const override;
+
private:
friend struct HalManifestConverter;
friend class VintfObject;