From 00aeb76928c7bd4c6455ff959ed3cc3bce69a73d Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 12 May 2021 17:07:36 -0700 Subject: RpcServer: expose server fd Add a few functions that allows to expose the socket() fd, because socket() and accept() may be called in different processes. Test: binderRpcTest Test: binderLibTest Bug: 182914638 Change-Id: I5489516fc92977aca4c98ee2dcdfa8365f8740c9 --- libs/binder/RpcServer.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libs/binder/RpcServer.cpp') diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp index dc10d1c524..9cc6e7fe04 100644 --- a/libs/binder/RpcServer.cpp +++ b/libs/binder/RpcServer.cpp @@ -272,8 +272,26 @@ void RpcServer::onSessionTerminating(const sp& session) { } bool RpcServer::hasServer() { + LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!"); std::lock_guard _l(mLock); return mServer.ok(); } +unique_fd RpcServer::releaseServer() { + LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!"); + std::lock_guard _l(mLock); + return std::move(mServer); +} + +bool RpcServer::setupExternalServer(base::unique_fd serverFd) { + LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!"); + std::lock_guard _l(mLock); + if (mServer.ok()) { + ALOGE("Each RpcServer can only have one server."); + return false; + } + mServer = std::move(serverFd); + return true; +} + } // namespace android -- cgit v1.2.3-59-g8ed1b