diff options
Diffstat (limited to 'transport/include/hidl/HidlBinderSupport.h')
-rw-r--r-- | transport/include/hidl/HidlBinderSupport.h | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/transport/include/hidl/HidlBinderSupport.h b/transport/include/hidl/HidlBinderSupport.h index 9759af1..a098805 100644 --- a/transport/include/hidl/HidlBinderSupport.h +++ b/transport/include/hidl/HidlBinderSupport.h @@ -24,11 +24,10 @@ #include <hidl/HidlSupport.h> #include <hidl/HidlTransportUtils.h> #include <hidl/MQDescriptor.h> -#include <hidl/Static.h> #include <hwbinder/IBinder.h> -#include <hwbinder/IPCThreadState.h> #include <hwbinder/Parcel.h> -#include <hwbinder/ProcessState.h> +#include <log/log.h> // TODO(b/65843592): remove. Too many users depending on this transitively. + // Defines functions for hidl_string, hidl_version, Status, hidl_vec, MQDescriptor, // etc. to interact with Parcel. @@ -49,6 +48,14 @@ private: wp<::android::hidl::base::V1_0::IBase> mBase; }; +// ---------------------- hidl_handle + +status_t readEmbeddedFromParcel(const hidl_handle &handle, + const Parcel &parcel, size_t parentHandle, size_t parentOffset); + +status_t writeEmbeddedToParcel(const hidl_handle &handle, + Parcel *parcel, size_t parentHandle, size_t parentOffset); + // ---------------------- hidl_memory status_t readEmbeddedFromParcel(const hidl_memory &memory, @@ -301,6 +308,10 @@ static status_t writeReferenceToParcel( // ---------------------- support for casting interfaces +// Constructs a binder for this interface and caches it. If it has already been created +// then it returns it. +sp<IBinder> getOrCreateCachedBinder(::android::hidl::base::V1_0::IBase* ifacePtr); + // Construct a smallest possible binder from the given interface. // If it is remote, then its remote() will be retrieved. // Otherwise, the smallest possible BnChild is found where IChild is a subclass of IType @@ -310,43 +321,7 @@ template <typename IType, typename = std::enable_if_t<std::is_same<details::i_tag, typename IType::_hidl_tag>::value>> sp<IBinder> toBinder(sp<IType> iface) { IType *ifacePtr = iface.get(); - if (ifacePtr == nullptr) { - return nullptr; - } - if (ifacePtr->isRemote()) { - return ::android::hardware::IInterface::asBinder( - static_cast<BpInterface<IType>*>(ifacePtr)); - } else { - std::string myDescriptor = details::getDescriptor(ifacePtr); - if (myDescriptor.empty()) { - // interfaceDescriptor fails - return nullptr; - } - - // for get + set - std::unique_lock<std::mutex> _lock = details::gBnMap.lock(); - - wp<BHwBinder> wBnObj = details::gBnMap.getLocked(ifacePtr, nullptr); - sp<IBinder> sBnObj = wBnObj.promote(); - - if (sBnObj == nullptr) { - auto func = details::getBnConstructorMap().get(myDescriptor, nullptr); - if (!func) { - func = details::gBnConstructorMap.get(myDescriptor, nullptr); - if (!func) { - return nullptr; - } - } - - sBnObj = sp<IBinder>(func(static_cast<void*>(ifacePtr))); - - if (sBnObj != nullptr) { - details::gBnMap.setLocked(ifacePtr, static_cast<BHwBinder*>(sBnObj.get())); - } - } - - return sBnObj; - } + return getOrCreateCachedBinder(ifacePtr); } template <typename IType, typename ProxyType, typename StubType> @@ -374,6 +349,8 @@ void joinBinderRpcThreadpool(); int setupBinderPolling(); status_t handleBinderPoll(); +void addPostCommandTask(const std::function<void(void)> task); + } // namespace hardware } // namespace android |