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

Commit 5a2cdd41 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9406101 from 7d089caa to udc-release

Change-Id: Ia2b1e1cc0769b7d3efbe49f8f0b1fd6f18bce633
parents 361f1c01 7d089caa
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -70,11 +70,8 @@ status_t RpcServer::setupUnixDomainServer(const char* path) {
    return setupSocketServer(UnixSocketAddress(path));
}

status_t RpcServer::setupVsockServer(unsigned int port) {
    // realizing value w/ this type at compile time to avoid ubsan abort
    constexpr unsigned int kAnyCid = VMADDR_CID_ANY;

    return setupSocketServer(VsockSocketAddress(kAnyCid, port));
status_t RpcServer::setupVsockServer(unsigned int bindCid, unsigned int port) {
    return setupSocketServer(VsockSocketAddress(bindCid, port));
}

status_t RpcServer::setupInetServer(const char* address, unsigned int port,
@@ -157,6 +154,12 @@ void RpcServer::setPerSessionRootObject(
    mRootObjectFactory = std::move(makeObject);
}

void RpcServer::setConnectionFilter(std::function<bool(const void*, size_t)>&& filter) {
    RpcMutexLockGuard _l(mLock);
    LOG_ALWAYS_FATAL_IF(mShutdownTrigger != nullptr, "Already joined");
    mConnectionFilter = std::move(filter);
}

sp<IBinder> RpcServer::getRootObject() {
    RpcMutexLockGuard _l(mLock);
    bool hasWeak = mRootObjectWeak.unsafe_get();
@@ -242,13 +245,19 @@ void RpcServer::join() {
        if (mAcceptFn(*this, &clientSocket) != OK) {
            continue;
        }

        LOG_RPC_DETAIL("accept on fd %d yields fd %d", mServer.fd.get(), clientSocket.fd.get());

        if (getpeername(clientSocket.fd.get(), reinterpret_cast<sockaddr*>(addr.data()),
                        &addrLen)) {
            ALOGE("Could not getpeername socket: %s", strerror(errno));
            continue;
        }

        LOG_RPC_DETAIL("accept on fd %d yields fd %d", mServer.fd.get(), clientSocket.fd.get());
        if (mConnectionFilter != nullptr && !mConnectionFilter(addr.data(), addrLen)) {
            ALOGE("Dropped client connection fd %d", clientSocket.fd.get());
            continue;
        }

        {
            RpcMutexLockGuard _l(mLock);
+5 −3
Original line number Diff line number Diff line
@@ -63,12 +63,14 @@ public:
        if (pfd.revents & POLLERR) {
            return DEAD_OBJECT;
        }
        if (pfd.revents & POLLHUP) {
            return DEAD_OBJECT;
        }
        if (pfd.revents & POLLIN) {
            // Copied from FdTrigger.cpp: Even though POLLHUP may also be set,
            // treat it as a success condition to ensure data is drained.
            return OK;
        }
        if (pfd.revents & POLLHUP) {
            return DEAD_OBJECT;
        }

        return WOULD_BLOCK;
    }
+2 −1
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ public:
     * a system property, or in the case of services in the VINTF manifest, it can be checked
     * with isDeclared).
     */
    [[deprecated("this polls for 5s, prefer waitForService or checkService")]]
    virtual sp<IBinder> getService(const String16& name) const = 0;

    /**
+13 −2
Original line number Diff line number Diff line
@@ -81,9 +81,9 @@ public:
    [[nodiscard]] status_t setupRawSocketServer(base::unique_fd socket_fd);

    /**
     * Creates an RPC server at the current port.
     * Creates an RPC server binding to the given CID at the given port.
     */
    [[nodiscard]] status_t setupVsockServer(unsigned int port);
    [[nodiscard]] status_t setupVsockServer(unsigned int bindCid, unsigned int port);

    /**
     * Creates an RPC server at the current port using IPv4.
@@ -170,6 +170,16 @@ public:
    void setPerSessionRootObject(std::function<sp<IBinder>(const void*, size_t)>&& object);
    sp<IBinder> getRootObject();

    /**
     * Set optional filter of incoming connections based on the peer's address.
     *
     * Takes one argument: a callable that is invoked on each accept()-ed
     * connection and returns false if the connection should be dropped.
     * See the description of setPerSessionRootObject() for details about
     * the callable's arguments.
     */
    void setConnectionFilter(std::function<bool(const void*, size_t)>&& filter);

    /**
     * See RpcTransportCtx::getCertificate
     */
@@ -253,6 +263,7 @@ private:
    sp<IBinder> mRootObject;
    wp<IBinder> mRootObjectWeak;
    std::function<sp<IBinder>(const void*, size_t)> mRootObjectFactory;
    std::function<bool(const void*, size_t)> mConnectionFilter;
    std::map<std::vector<uint8_t>, sp<RpcSession>> mSessions;
    std::unique_ptr<FdTrigger> mShutdownTrigger;
    RpcConditionVariable mShutdownCv;
+5 −1
Original line number Diff line number Diff line
@@ -25,9 +25,13 @@ struct AIBinder;
struct ARpcServer;

// Starts an RPC server on a given port and a given root IBinder object.
// The server will only accept connections from the given CID.
// Set `cid` to VMADDR_CID_ANY to accept connections from any client.
// Set `cid` to VMADDR_CID_LOCAL to only bind to the local vsock interface.
// Returns an opaque handle to the running server instance, or null if the server
// could not be started.
[[nodiscard]] ARpcServer* ARpcServer_newVsock(AIBinder* service, unsigned int port);
[[nodiscard]] ARpcServer* ARpcServer_newVsock(AIBinder* service, unsigned int cid,
                                              unsigned int port);

// Starts a Unix domain RPC server with a given init-managed Unix domain `name`
// and a given root IBinder object.
Loading