diff options
author | 2022-07-21 15:22:09 +0000 | |
---|---|---|
committer | 2022-07-21 15:22:09 +0000 | |
commit | 82de44ff33ac5847611173ac27b602923c3d8686 (patch) | |
tree | 779d7d771670548ae5d00c182ccf0aa745cf09fe /libs/binder/RpcState.cpp | |
parent | db8f9c58d4e156638da862d5479c410b581e4418 (diff) | |
parent | 66d5b7ac5c78330dd7ad38f0319d432e2df7230f (diff) |
Merge "Add linkToDeath support for RPC binder so a client can act on disconnect"
Diffstat (limited to 'libs/binder/RpcState.cpp')
-rw-r--r-- | libs/binder/RpcState.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp index d063001414..c0e36c4322 100644 --- a/libs/binder/RpcState.cpp +++ b/libs/binder/RpcState.cpp @@ -226,6 +226,30 @@ status_t RpcState::flushExcessBinderRefs(const sp<RpcSession>& session, uint64_t return OK; } +status_t RpcState::sendObituaries(const sp<RpcSession>& session) { + RpcMutexUniqueLock _l(mNodeMutex); + + // Gather strong pointers to all of the remote binders for this session so + // we hold the strong references. remoteBinder() returns a raw pointer. + // Send the obituaries and drop the strong pointers outside of the lock so + // the destructors and the onBinderDied calls are not done while locked. + std::vector<sp<IBinder>> remoteBinders; + for (const auto& [_, binderNode] : mNodeForAddress) { + if (auto binder = binderNode.binder.promote()) { + remoteBinders.push_back(std::move(binder)); + } + } + _l.unlock(); + + for (const auto& binder : remoteBinders) { + if (binder->remoteBinder() && + binder->remoteBinder()->getPrivateAccessor().rpcSession() == session) { + binder->remoteBinder()->sendObituary(); + } + } + return OK; +} + size_t RpcState::countBinders() { RpcMutexLockGuard _l(mNodeMutex); return mNodeForAddress.size(); |