Fix wrapPassthrough casts to the wrong type.

wrapPassthrough should cast to IType *, not
IBase *, for the incoming pointer.

Also, use static_cast instead of reinterpret_cast
everywhere.

Bug: 37542631
Bug: 36225019
Test: hidl_test
Change-Id: Ifc3455b2313ea3cdf765e8959707b08a4a8ff101
diff --git a/transport/include/hidl/HidlBinderSupport.h b/transport/include/hidl/HidlBinderSupport.h
index 86ac74c..454656c 100644
--- a/transport/include/hidl/HidlBinderSupport.h
+++ b/transport/include/hidl/HidlBinderSupport.h
@@ -332,7 +332,7 @@
         if (!func) {
             return nullptr;
         }
-        return sp<IBinder>(func(reinterpret_cast<void *>(ifacePtr)));
+        return sp<IBinder>(func(static_cast<void *>(ifacePtr)));
     }
 }
 
diff --git a/transport/include/hidl/HidlPassthroughSupport.h b/transport/include/hidl/HidlPassthroughSupport.h
index 0a8f15b..4fb1ae4 100644
--- a/transport/include/hidl/HidlPassthroughSupport.h
+++ b/transport/include/hidl/HidlPassthroughSupport.h
@@ -27,8 +27,24 @@
  * Wrap the given interface with the smallest BsChild possible. Will return the
  * argument directly if nullptr or isRemote().
  */
+template<typename IType>
 sp<::android::hidl::base::V1_0::IBase> wrapPassthrough(
-        sp<::android::hidl::base::V1_0::IBase> iface);
+        sp<IType> iface) {
+    if (iface.get() == nullptr || iface->isRemote()) {
+        // doesn't know how to handle it.
+        return iface;
+    }
+    std::string myDescriptor = getDescriptor(iface.get());
+    if (myDescriptor.empty()) {
+        // interfaceDescriptor fails
+        return nullptr;
+    }
+    auto func = gBsConstructorMap.get(myDescriptor, nullptr);
+    if (!func) {
+        return nullptr;
+    }
+    return func(static_cast<void *>(iface.get()));
+}
 
 }  // namespace details
 }  // namespace hardware