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/Android.bp b/transport/Android.bp
index a65d8ef..47a4de3 100644
--- a/transport/Android.bp
+++ b/transport/Android.bp
@@ -58,7 +58,6 @@
srcs: [
"HidlBinderSupport.cpp",
- "HidlPassthroughSupport.cpp",
"HidlTransportSupport.cpp",
"ServiceManagement.cpp",
"Static.cpp"
diff --git a/transport/HidlPassthroughSupport.cpp b/transport/HidlPassthroughSupport.cpp
deleted file mode 100644
index 3a7f6dc..0000000
--- a/transport/HidlPassthroughSupport.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <hidl/HidlPassthroughSupport.h>
-
-#include <hidl/HidlSupport.h>
-#include <hidl/HidlTransportUtils.h>
-#include <hidl/Static.h>
-
-namespace android {
-namespace hardware {
-namespace details {
-
-sp<::android::hidl::base::V1_0::IBase> wrapPassthrough(
- sp<::android::hidl::base::V1_0::IBase> 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(reinterpret_cast<void *>(iface.get()));
-}
-
-} // namespace details
-} // namespace hardware
-} // namespace android
diff --git a/transport/include/hidl/HidlBinderSupport.h b/transport/include/hidl/HidlBinderSupport.h
index 302e289..a82f977 100644
--- a/transport/include/hidl/HidlBinderSupport.h
+++ b/transport/include/hidl/HidlBinderSupport.h
@@ -333,7 +333,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