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

Commit 4f622fec authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: RpcSession - hide RPC address format

FAQ for this change.

- Why does RpcSession still have sendDecStrong(uint64_t)?

    This is used by RpcState to send dec strongs on local (non-BpBinder)
    binders. This is needed because if a client has the last strong ref
    of a binder which is local to the corresponding server, the client
    needs to transfer ownership of this binder to the server using the
    call.

- Why is RpcSession::sendDecStrong(BpBinder) public?

    It may be useful for testing, especially in situations where
    ~BpBinder would be hard to call.

- Why does BpBinder have a private accessor, but RpcState is friends
  with some other Rpc* classes?

    I would like to have as few friends as possible (in regards to C++
    classes!), but it takes quite a bit of boilerplate to avoid this. I
    want to avoid the Rpc stuff introspecting into the standard binder
    stuff, but I'm not currently concerned about their interactions
    between each other.

Bug: 167966510
Test: binderRpcTest
Change-Id: I89e4de2e3a042a4531e2fd41deeb9bab1c11ff94
parent 99157624
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -510,7 +510,7 @@ void BpBinder::onLastStrongRef(const void* /*id*/)
{
    ALOGV("onLastStrongRef BpBinder %p handle %d\n", this, binderHandle());
    if (CC_UNLIKELY(isRpcBinder())) {
        (void)rpcSession()->sendDecStrong(rpcAddress());
        (void)rpcSession()->sendDecStrong(this);
        return;
    }
    IF_ALOGV() {
+5 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <android-base/hex.h>
#include <android-base/macros.h>
#include <android_runtime/vm.h>
#include <binder/BpBinder.h>
#include <binder/Parcel.h>
#include <binder/RpcServer.h>
#include <binder/RpcTransportRaw.h>
@@ -226,6 +227,10 @@ status_t RpcSession::transact(const sp<IBinder>& binder, uint32_t code, const Pa
                             sp<RpcSession>::fromExisting(this), reply, flags);
}

status_t RpcSession::sendDecStrong(const BpBinder* binder) {
    return sendDecStrong(binder->getPrivateAccessor().rpcAddress());
}

status_t RpcSession::sendDecStrong(uint64_t address) {
    ExclusiveConnection connection;
    status_t status = ExclusiveConnection::find(sp<RpcSession>::fromExisting(this),
+1 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ public:
        friend class BpBinder;
        friend class ::android::Parcel;
        friend class ::android::ProcessState;
        friend class ::android::RpcSession;
        friend class ::android::RpcState;
        explicit PrivateAccessor(const BpBinder* binder) : mBinder(binder) {}

+9 −1
Original line number Diff line number Diff line
@@ -153,7 +153,13 @@ public:

    [[nodiscard]] status_t transact(const sp<IBinder>& binder, uint32_t code, const Parcel& data,
                                    Parcel* reply, uint32_t flags);
    [[nodiscard]] status_t sendDecStrong(uint64_t address);

    /**
     * Generally, you should not call this, unless you are testing error
     * conditions, as this is called automatically by BpBinders when they are
     * deleted (this is also why a raw pointer is used here)
     */
    [[nodiscard]] status_t sendDecStrong(const BpBinder* binder);

    ~RpcSession();

@@ -172,6 +178,8 @@ private:
    friend RpcState;
    explicit RpcSession(std::unique_ptr<RpcTransportCtx> ctx);

    [[nodiscard]] status_t sendDecStrong(uint64_t address);

    class EventListener : public virtual RefBase {
    public:
        virtual void onSessionAllIncomingThreadsEnded(const sp<RpcSession>& session) = 0;