Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 379dbd1c authored by Steven Moreland's avatar Steven Moreland Committed by Gerrit Code Review
Browse files

Merge "RpcServer: be thread safe"

parents ea5434d3 ebafe331
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -48,16 +48,20 @@ sp<RpcConnection> RpcServer::addClientConnection() {

    auto connection = RpcConnection::make();
    connection->setForServer(sp<RpcServer>::fromExisting(this));
    {
        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;
}

+4 −13
Original line number Diff line number Diff line
@@ -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:
@@ -50,17 +49,9 @@ 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
};