diff options
author | Yifan Hong <elsk@google.com> | 2017-04-20 18:10:50 -0700 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2017-04-20 18:26:11 -0700 |
commit | 81e25c13192462a60eda925413302d0f8c6a936e (patch) | |
tree | b987c3201530d19a56ba48dd7ab2ff30257d11a4 | |
parent | d42aa7086b6de6c93c44dcac4bba525d2f72607b (diff) | |
download | libhidl-81e25c13192462a60eda925413302d0f8c6a936e.tar.gz |
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
-rw-r--r-- | transport/Android.bp | 1 | ||||
-rw-r--r-- | transport/HidlPassthroughSupport.cpp | 46 | ||||
-rw-r--r-- | transport/include/hidl/HidlBinderSupport.h | 2 | ||||
-rw-r--r-- | transport/include/hidl/HidlPassthroughSupport.h | 18 |
4 files changed, 18 insertions, 49 deletions
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 @@ cc_library_shared { 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 @@ sp<IBinder> toBinder(sp<IType> iface) { 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 @@ namespace details { * 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 |