Use wrapPassthrough in getService.
Also added tests for this in hidl_test.
This way in HIDL_FETCH_IParent, you can return an IChild object
and castFrom will work appropriately.
Test: ./test/run_all_device_tests.sh
Bug: 67104214
Change-Id: Ic317d610e733e1ead061a1090c121be30c3c4a9b
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 4179e64..8bcf16b 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -335,7 +335,8 @@
out.sIf("baseInterface != nullptr", [&]() {
out << "iface = " << interfaceName << "::castFrom(baseInterface);\n";
out.sIf("!getStub || trebleTestingOverride", [&] () {
- out << "iface = new " << fqName.getInterfacePassthroughName() << "(iface);\n";
+ // TODO(b/33754152): make sure this object doesn't get re-wrapped later.
+ out << "iface = ::android::hardware::details::wrapPassthrough(iface);\n";
}).endl();
}).endl();
}).endl();
@@ -625,11 +626,9 @@
out.sIf(name + " != nullptr && !" + name + "->isRemote()", [&] {
out << wrappedName
<< " = "
- << iface.fqName().cppName()
- << "::castFrom(::android::hardware::details::wrapPassthrough<"
- << iface.fqName().cppName()
- << ">("
- << name << "));\n";
+ << "::android::hardware::details::wrapPassthrough("
+ << name
+ << ");\n";
out.sIf(wrappedName + " == nullptr", [&] {
// Fatal error. Happens when the BsFoo class is not found in the binary
// or any dynamic libraries.
diff --git a/test/hidl_test/hidl_test_client.cpp b/test/hidl_test/hidl_test_client.cpp
index acee99c..839d305 100644
--- a/test/hidl_test/hidl_test_client.cpp
+++ b/test/hidl_test/hidl_test_client.cpp
@@ -723,6 +723,28 @@
"['" + descriptor + "/" + instanceOne + "', '" + descriptor + "/" + instanceTwo + "']");
}
+TEST_F(HidlTest, InterfacesEqualTest) {
+ using android::hardware::interfacesEqual;
+
+ sp<IParent> service1 = IParent::getService("child", mode == PASSTHROUGH /* getStub */);
+ sp<IParent> service2 = service1;
+
+ // Passthrough services are reinstantiated whenever getService is called.
+ if (mode == BINDERIZED) {
+ service2 = IParent::getService("child");
+ }
+
+ EXPECT_NE(nullptr, service1.get());
+ EXPECT_NE(nullptr, service2.get());
+ EXPECT_TRUE(interfacesEqual(service1, service2));
+
+ sp<IChild> child = IChild::castFrom(service1);
+ EXPECT_NE(nullptr, child.get()); // it is actually a child
+
+ EXPECT_TRUE(interfacesEqual(service1, child));
+ EXPECT_TRUE(interfacesEqual(service2, child));
+}
+
TEST_F(HidlTest, TestToken) {
using android::hardware::interfacesEqual;