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

Commit 4f06ef96 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "RPC binder: expose session to per-client roots" am: 232cbe5f am:...

Merge "RPC binder: expose session to per-client roots" am: 232cbe5f am: 68dfe215 am: e1fac3eb am: a4a964db am: b3d77732 am: c86dab2a

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2603309



Change-Id: Ic9530102b402170f01ad90b8a4e11b2c43742371
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 78d7ddd5 c86dab2a
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@ void RpcServer::setRootObjectWeak(const wp<IBinder>& binder) {
    mRootObjectWeak = binder;
}
void RpcServer::setPerSessionRootObject(
        std::function<sp<IBinder>(const void*, size_t)>&& makeObject) {
        std::function<sp<IBinder>(wp<RpcSession> session, const void*, size_t)>&& makeObject) {
    RpcMutexLockGuard _l(mLock);
    mRootObject.clear();
    mRootObjectWeak.clear();
@@ -515,7 +515,8 @@ void RpcServer::establishConnection(
            // if null, falls back to server root
            sp<IBinder> sessionSpecificRoot;
            if (server->mRootObjectFactory != nullptr) {
                sessionSpecificRoot = server->mRootObjectFactory(addr.data(), addrLen);
                sessionSpecificRoot =
                        server->mRootObjectFactory(wp<RpcSession>(session), addr.data(), addrLen);
                if (sessionSpecificRoot == nullptr) {
                    ALOGE("Warning: server returned null from root object factory");
                }
+12 −8
Original line number Diff line number Diff line
@@ -163,14 +163,18 @@ public:
     * Allows a root object to be created for each session.
     *
     * Takes one argument: a callable that is invoked once per new session.
     * The callable takes two arguments: a type-erased pointer to an OS- and
     * transport-specific address structure, e.g., sockaddr_vm for vsock, and
     * an integer representing the size in bytes of that structure. The
     * callable should validate the size, then cast the type-erased pointer
     * to a pointer to the actual type of the address, e.g., const void* to
     * const sockaddr_vm*.
     * The callable takes three arguments:
     * - a weak pointer to the session. If you want to hold onto this in the root object, then
     *   you should keep a weak pointer, and promote it when needed. For instance, if you refer
     *   to this from the root object, then you could get ahold of transport-specific information.
     * - a type-erased pointer to an OS- and transport-specific address structure, e.g.,
     *   sockaddr_vm for vsock
     * - an integer representing the size in bytes of that structure. The callable should
     *   validate the size, then cast the type-erased pointer to a pointer to the actual type of the
     *   address, e.g., const void* to const sockaddr_vm*.
     */
    void setPerSessionRootObject(std::function<sp<IBinder>(const void*, size_t)>&& object);
    void setPerSessionRootObject(
            std::function<sp<IBinder>(wp<RpcSession> session, const void*, size_t)>&& object);
    sp<IBinder> getRootObject();

    /**
@@ -272,7 +276,7 @@ private:

    sp<IBinder> mRootObject;
    wp<IBinder> mRootObjectWeak;
    std::function<sp<IBinder>(const void*, size_t)> mRootObjectFactory;
    std::function<sp<IBinder>(wp<RpcSession>, const void*, size_t)> mRootObjectFactory;
    std::function<bool(const void*, size_t)> mConnectionFilter;
    std::function<void(base::borrowed_fd)> mServerSocketModifier;
    std::map<std::vector<uint8_t>, sp<RpcSession>> mSessions;
+6 −1
Original line number Diff line number Diff line
@@ -164,7 +164,12 @@ int main(int argc, char* argv[]) {
        }
    }

    server->setPerSessionRootObject([&](const void* addrPtr, size_t len) {
    server->setPerSessionRootObject([&](wp<RpcSession> session, const void* addrPtr, size_t len) {
        {
            sp<RpcSession> spSession = session.promote();
            CHECK_NE(nullptr, spSession.get());
        }

        // UNIX sockets with abstract addresses return
        // sizeof(sa_family_t)==2 in addrlen
        CHECK_GE(len, sizeof(sa_family_t));
+9 −8
Original line number Diff line number Diff line
@@ -93,7 +93,8 @@ int main(void) {
        if (!serverInfo.server->setProtocolVersion(serverVersion)) {
            return EXIT_FAILURE;
        }
        serverInfo.server->setPerSessionRootObject([=](const void* /*addrPtr*/, size_t /*len*/) {
        serverInfo.server->setPerSessionRootObject(
                [=](wp<RpcSession> /*session*/, const void* /*addrPtr*/, size_t /*len*/) {
                    auto service = sp<MyBinderRpcTestTrusty>::make();
                    // Assign a unique connection identifier to service->port so
                    // getClientPort returns a unique value per connection
+2 −1
Original line number Diff line number Diff line
@@ -68,7 +68,8 @@ public:
    }
    void setRootObject(const sp<IBinder>& binder) { mRpcServer->setRootObject(binder); }
    void setRootObjectWeak(const wp<IBinder>& binder) { mRpcServer->setRootObjectWeak(binder); }
    void setPerSessionRootObject(std::function<sp<IBinder>(const void*, size_t)>&& object) {
    void setPerSessionRootObject(
            std::function<sp<IBinder>(wp<RpcSession> session, const void*, size_t)>&& object) {
        mRpcServer->setPerSessionRootObject(std::move(object));
    }
    sp<IBinder> getRootObject() { return mRpcServer->getRootObject(); }