diff options
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/binder/RpcServer.cpp | 8 | ||||
| -rw-r--r-- | libs/binder/include/binder/RpcServer.h | 17 |
2 files changed, 10 insertions, 15 deletions
diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp index 1fa37bacb3..6dc4f95307 100644 --- a/libs/binder/RpcServer.cpp +++ b/libs/binder/RpcServer.cpp @@ -48,16 +48,20 @@ sp<RpcConnection> RpcServer::addClientConnection() { auto connection = RpcConnection::make(); connection->setForServer(sp<RpcServer>::fromExisting(this)); - mConnections.push_back(connection); + { + std::lock_guard<std::mutex> _l(mLock); + mConnections.push_back(connection); + } return connection; } void RpcServer::setRootObject(const sp<IBinder>& binder) { - LOG_ALWAYS_FATAL_IF(mRootObject != nullptr, "There can only be one root object"); + std::lock_guard<std::mutex> _l(mLock); mRootObject = binder; } sp<IBinder> RpcServer::getRootObject() { + std::lock_guard<std::mutex> _l(mLock); return mRootObject; } diff --git a/libs/binder/include/binder/RpcServer.h b/libs/binder/include/binder/RpcServer.h index d29b651f0b..a665fad43a 100644 --- a/libs/binder/include/binder/RpcServer.h +++ b/libs/binder/include/binder/RpcServer.h @@ -21,6 +21,8 @@ #include <utils/Errors.h> #include <utils/RefBase.h> +#include <mutex> + // WARNING: This is a feature which is still in development, and it is subject // to radical change. Any production use of this may subject your code to any // number of problems. @@ -30,9 +32,6 @@ namespace android { /** * This represents a server of an interface, which may be connected to by any * number of clients over sockets. - * - * This object is not (currently) thread safe. All calls to it are expected to - * happen at process startup. */ class RpcServer final : public virtual RefBase { public: @@ -51,16 +50,8 @@ public: sp<RpcConnection> addClientConnection(); /** - * Allowing a server to explicitly drop clients would be easy to add here, - * but it is not currently implemented, since users of this functionality - * could not use similar functionality if they are running under real - * binder. - */ - // void drop(const sp<RpcConnection>& connection); - - /** * The root object can be retrieved by any client, without any - * authentication. + * authentication. TODO(b/183988761) */ void setRootObject(const sp<IBinder>& binder); @@ -77,8 +68,8 @@ private: bool mAgreedExperimental = false; + std::mutex mLock; sp<IBinder> mRootObject; - std::vector<sp<RpcConnection>> mConnections; // per-client }; |