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

Commit 7b8bc4c6 authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: RpcSession exposes sp<RpcServer>

This object guarantees a strong pointer IFF it is associated with a
server. The wp<> return type here previously was for convenience (idk?)
but users of it shouldn't be concerned with the underlying memory
situation.

Bug: 167966510
Test: binderRpcTest
Change-Id: I6578c3a4246e1bd07f7697c11d4b56899b50245b
parent 19fc9f79
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -312,8 +312,13 @@ void RpcSession::join(sp<RpcSession>&& session, PreJoinSetupResult&& setupResult
    }
}

wp<RpcServer> RpcSession::server() {
    return mForServer;
sp<RpcServer> RpcSession::server() {
    RpcServer* unsafeServer = mForServer.unsafe_get();
    sp<RpcServer> server = mForServer.promote();

    LOG_ALWAYS_FATAL_IF((unsafeServer == nullptr) != (server == nullptr),
                        "wp<> is to avoid strong cycle only");
    return server;
}

bool RpcSession::setupSocketClient(const RpcSocketAddress& addr) {
+1 −1
Original line number Diff line number Diff line
@@ -741,7 +741,7 @@ processTransactInternalTailCall:
                    break;
                }
                default: {
                    sp<RpcServer> server = session->server().promote();
                    sp<RpcServer> server = session->server();
                    if (server) {
                        switch (transaction->code) {
                            case RPC_SPECIAL_TRANSACT_GET_ROOT: {
+5 −1
Original line number Diff line number Diff line
@@ -118,7 +118,11 @@ public:

    ~RpcSession();

    wp<RpcServer> server();
    /**
     * Server if this session is created as part of a server (symmetrical to
     * client servers). Otherwise, nullptr.
     */
    sp<RpcServer> server();

    // internal only
    const std::unique_ptr<RpcState>& state() { return mState; }