Merge "vts_treble_no_hidl check vintf instead of hwservicemanager" into main
diff --git a/treble/vintf/VtsNoHidl.cpp b/treble/vintf/VtsNoHidl.cpp
index 9cb2a0a..128ff51 100644
--- a/treble/vintf/VtsNoHidl.cpp
+++ b/treble/vintf/VtsNoHidl.cpp
@@ -19,6 +19,7 @@
#include <android/hidl/manager/1.0/IServiceManager.h>
#include <gmock/gmock.h>
#include <hidl/ServiceManagement.h>
+#include <vintf/VintfObject.h>
#define __ANDROID_VENDOR_API_24Q2__ 202404
@@ -36,6 +37,20 @@
// 14 and later.
class VintfNoHidlTest : public ::testing::Test {};
+static std::set<std::string> allHidlManifestInterfaces() {
+ std::set<std::string> ret;
+ auto setInserter = [&](const vintf::ManifestInstance& i) -> bool {
+ if (i.format() != vintf::HalFormat::HIDL) {
+ return true;
+ }
+ ret.insert(i.getFqInstance().getFqNameString());
+ return true;
+ };
+ vintf::VintfObject::GetDeviceHalManifest()->forEachInstance(setInserter);
+ vintf::VintfObject::GetFrameworkHalManifest()->forEachInstance(setInserter);
+ return ret;
+}
+
// @VsrTest = VSR-3.2-001.001|VSR-3.2-001.002
TEST_F(VintfNoHidlTest, NoHidl) {
int apiLevel = android::base::GetIntProperty("ro.vendor.api_level", 0);
@@ -44,43 +59,43 @@
return;
}
int maxNumberOfHidlHals = 0;
+ std::set<std::string> halInterfaces;
if (apiLevel == __ANDROID_API_U__) {
maxNumberOfHidlHals = kMaxNumberOfHidlHalsU;
+ sp<hidl::manager::V1_0::IServiceManager> sm =
+ ::android::hardware::defaultServiceManager();
+ ASSERT_NE(sm, nullptr);
+ hardware::Return<void> ret =
+ sm->list([&halInterfaces](const auto& interfaces) {
+ for (const auto& interface : interfaces) {
+ std::vector<std::string> splitInterface =
+ android::base::Split(interface, "@");
+ ASSERT_GE(splitInterface.size(), 1);
+ // We only care about packages, since HIDL HALs typically need to
+ // include all of the older minor versions as well as the version
+ // they are implementing and we don't want to count those
+ halInterfaces.insert(splitInterface[0]);
+ }
+ });
} else if (apiLevel == __ANDROID_VENDOR_API_24Q2__) {
maxNumberOfHidlHals = kMaxNumberOfHidlHalsV;
+ halInterfaces = allHidlManifestInterfaces();
} else {
// TODO(232439834) We can remove this once kMaxNumberOfHidlHalsV is 0.
GTEST_FAIL() << "Unexpected Android vendor API level (" << apiLevel
<< "). Must be either " << __ANDROID_API_U__ << " or "
<< __ANDROID_VENDOR_API_24Q2__;
}
- sp<hidl::manager::V1_0::IServiceManager> sm =
- ::android::hardware::defaultServiceManager();
- ASSERT_NE(sm, nullptr);
- hardware::Return<void> ret = sm->list([&maxNumberOfHidlHals](
- const auto& interfaces) {
- std::set<std::string> packages;
- for (const auto& interface : interfaces) {
- std::vector<std::string> splitInterface =
- android::base::Split(interface, "@");
- ASSERT_GE(splitInterface.size(), 1);
- // We only care about packages, since HIDL HALs typically need to
- // include all of the older minor versions as well as the version they
- // are implementing
- packages.insert(splitInterface[0]);
+ if (halInterfaces.size() > maxNumberOfHidlHals) {
+ ADD_FAILURE() << "There are " << halInterfaces.size()
+ << " HIDL interfaces served on the device. "
+ << "These must be converted to AIDL as part of HIDL's "
+ "deprecation processes.";
+ for (const auto& interface : halInterfaces) {
+ ADD_FAILURE() << interface << " registered as a HIDL interface "
+ << "but must be in AIDL";
}
- if (packages.size() > maxNumberOfHidlHals) {
- ADD_FAILURE() << "There are " << packages.size()
- << " HIDL interfaces served on the device. "
- << "These must be converted to AIDL as part of HIDL's "
- "deprecation processes.";
- for (const auto& package : packages) {
- ADD_FAILURE() << package << " registered as a HIDL interface "
- << "but must be in AIDL";
- }
- }
- });
- ASSERT_TRUE(ret.isOk());
+ }
}
} // namespace testing