Add helper API to get all HAL instances.
This API is technically already available as defaultServiceManager1_2
listManifestByInterface, but it is somewhat cumbersome to use.
Two things in mind with this change:
a). convenient method for VTS HIDL tests to use instead of having the
VTS test runner invoke a test many times.
b). with an eye towards validating FCM <regex-instance> entries.
Bug: 139437880
Test: updated Lights VTS test.
Change-Id: I2060dcf67a0969ac0099bb4b0f4a021ff6ec6599
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index 357bb30..f35abdc 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -559,6 +559,18 @@
return manager;
}
+std::vector<std::string> getAllHalInstanceNames(const std::string& descriptor) {
+ std::vector<std::string> ret;
+ auto sm = defaultServiceManager1_2();
+ sm->listManifestByInterface(descriptor, [&](const auto& instances) {
+ ret.reserve(instances.size());
+ for (const auto& i : instances) {
+ ret.push_back(i);
+ }
+ });
+ return ret;
+}
+
namespace details {
void preloadPassthroughService(const std::string &descriptor) {
diff --git a/transport/include/hidl/ServiceManagement.h b/transport/include/hidl/ServiceManagement.h
index a962034..4573a25 100644
--- a/transport/include/hidl/ServiceManagement.h
+++ b/transport/include/hidl/ServiceManagement.h
@@ -18,6 +18,7 @@
#define ANDROID_HARDWARE_ISERVICE_MANAGER_H
#include <string>
+#include <vector>
#include <android/hidl/base/1.0/IBase.h>
#include <utils/StrongPointer.h>
@@ -71,6 +72,14 @@
sp<::android::hidl::manager::V1_1::IServiceManager> getPassthroughServiceManager1_1();
/**
+ * Given a descriptor (e.g. from IFoo::descriptor), return a list of all instance names
+ * on a device (e.g. the VINTF manifest). These HALs may not be currently running, but
+ * the expectation is that if they aren't running, they should start as lazy HALs.
+ * So, getService should return for each of these instance names.
+ */
+std::vector<std::string> getAllHalInstanceNames(const std::string& descriptor);
+
+/**
* Given a service that is in passthrough mode, this function will go ahead and load the
* required passthrough module library (but not call HIDL_FETCH_I* functions to instantiate it).
*