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

Commit 0514efd7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "libbinder: RPC big 'session' rename" am: f817a62d am: 7d3ff4f6

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

Change-Id: Ie507881ee293cd52eaaa3ff5245b76388e0220df
parents 3cb8d2b8 7d3ff4f6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ cc_library {
        "PersistableBundle.cpp",
        "ProcessState.cpp",
        "RpcAddress.cpp",
        "RpcConnection.cpp",
        "RpcSession.cpp",
        "RpcServer.cpp",
        "RpcState.cpp",
        "Static.cpp",
+14 −14
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@

#include <binder/IPCThreadState.h>
#include <binder/IResultReceiver.h>
#include <binder/RpcConnection.h>
#include <binder/RpcSession.h>
#include <binder/Stability.h>
#include <cutils/compiler.h>
#include <utils/Log.h>
@@ -136,15 +136,15 @@ sp<BpBinder> BpBinder::create(int32_t handle) {
    return sp<BpBinder>::make(BinderHandle{handle}, trackedUid);
}

sp<BpBinder> BpBinder::create(const sp<RpcConnection>& connection, const RpcAddress& address) {
    LOG_ALWAYS_FATAL_IF(connection == nullptr, "BpBinder::create null connection");
sp<BpBinder> BpBinder::create(const sp<RpcSession>& session, const RpcAddress& address) {
    LOG_ALWAYS_FATAL_IF(session == nullptr, "BpBinder::create null session");

    // These are not currently tracked, since there is no UID or other
    // identifier to track them with. However, if similar functionality is
    // needed, connection objects keep track of all BpBinder objects on a
    // per-connection basis.
    // needed, session objects keep track of all BpBinder objects on a
    // per-session basis.

    return sp<BpBinder>::make(SocketHandle{connection, address});
    return sp<BpBinder>::make(RpcHandle{session, address});
}

BpBinder::BpBinder(Handle&& handle)
@@ -165,20 +165,20 @@ BpBinder::BpBinder(BinderHandle&& handle, int32_t trackedUid) : BpBinder(Handle(
    IPCThreadState::self()->incWeakHandle(this->binderHandle(), this);
}

BpBinder::BpBinder(SocketHandle&& handle) : BpBinder(Handle(handle)) {
    LOG_ALWAYS_FATAL_IF(rpcConnection() == nullptr, "BpBinder created w/o connection object");
BpBinder::BpBinder(RpcHandle&& handle) : BpBinder(Handle(handle)) {
    LOG_ALWAYS_FATAL_IF(rpcSession() == nullptr, "BpBinder created w/o session object");
}

bool BpBinder::isRpcBinder() const {
    return std::holds_alternative<SocketHandle>(mHandle);
    return std::holds_alternative<RpcHandle>(mHandle);
}

const RpcAddress& BpBinder::rpcAddress() const {
    return std::get<SocketHandle>(mHandle).address;
    return std::get<RpcHandle>(mHandle).address;
}

const sp<RpcConnection>& BpBinder::rpcConnection() const {
    return std::get<SocketHandle>(mHandle).connection;
const sp<RpcSession>& BpBinder::rpcSession() const {
    return std::get<RpcHandle>(mHandle).session;
}

int32_t BpBinder::binderHandle() const {
@@ -273,7 +273,7 @@ status_t BpBinder::transact(

        status_t status;
        if (CC_UNLIKELY(isRpcBinder())) {
            status = rpcConnection()->transact(rpcAddress(), code, data, reply, flags);
            status = rpcSession()->transact(rpcAddress(), code, data, reply, flags);
        } else {
            status = IPCThreadState::self()->transact(binderHandle(), code, data, reply, flags);
        }
@@ -479,7 +479,7 @@ void BpBinder::onLastStrongRef(const void* /*id*/)
{
    ALOGV("onLastStrongRef BpBinder %p handle %d\n", this, binderHandle());
    if (CC_UNLIKELY(isRpcBinder())) {
        (void)rpcConnection()->sendDecStrong(rpcAddress());
        (void)rpcSession()->sendDecStrong(rpcAddress());
        return;
    }
    IF_ALOGV() {
+9 −10
Original line number Diff line number Diff line
@@ -202,7 +202,7 @@ status_t Parcel::flattenBinder(const sp<IBinder>& binder)
            status_t status = writeInt32(1); // non-null
            if (status != OK) return status;
            RpcAddress address = RpcAddress::zero();
            status = mConnection->state()->onBinderLeaving(mConnection, binder, &address);
            status = mSession->state()->onBinderLeaving(mSession, binder, &address);
            if (status != OK) return status;
            status = address.writeToParcel(this);
            if (status != OK) return status;
@@ -273,8 +273,7 @@ status_t Parcel::flattenBinder(const sp<IBinder>& binder)
status_t Parcel::unflattenBinder(sp<IBinder>* out) const
{
    if (isForRpc()) {
        LOG_ALWAYS_FATAL_IF(mConnection == nullptr,
                            "RpcConnection required to read from remote parcel");
        LOG_ALWAYS_FATAL_IF(mSession == nullptr, "RpcSession required to read from remote parcel");

        int32_t isNull;
        status_t status = readInt32(&isNull);
@@ -286,7 +285,7 @@ status_t Parcel::unflattenBinder(sp<IBinder>* out) const
            auto addr = RpcAddress::zero();
            status_t status = addr.readFromParcel(*this);
            if (status != OK) return status;
            binder = mConnection->state()->onBinderEntering(mConnection, addr);
            binder = mSession->state()->onBinderEntering(mSession, addr);
        }

        return finishUnflattenBinder(binder, out);
@@ -568,20 +567,20 @@ void Parcel::markForBinder(const sp<IBinder>& binder) {
    LOG_ALWAYS_FATAL_IF(mData != nullptr, "format must be set before data is written");

    if (binder && binder->remoteBinder() && binder->remoteBinder()->isRpcBinder()) {
        markForRpc(binder->remoteBinder()->getPrivateAccessorForId().rpcConnection());
        markForRpc(binder->remoteBinder()->getPrivateAccessorForId().rpcSession());
    }
}

void Parcel::markForRpc(const sp<RpcConnection>& connection) {
void Parcel::markForRpc(const sp<RpcSession>& session) {
    LOG_ALWAYS_FATAL_IF(mData != nullptr && mOwner == nullptr,
                        "format must be set before data is written OR on IPC data");

    LOG_ALWAYS_FATAL_IF(connection == nullptr, "markForRpc requires connection");
    mConnection = connection;
    LOG_ALWAYS_FATAL_IF(session == nullptr, "markForRpc requires session");
    mSession = session;
}

bool Parcel::isForRpc() const {
    return mConnection != nullptr;
    return mSession != nullptr;
}

void Parcel::updateWorkSourceRequestHeaderPosition() const {
@@ -2499,7 +2498,7 @@ void Parcel::initState()
    mDataPos = 0;
    ALOGV("initState Setting data size of %p to %zu", this, mDataSize);
    ALOGV("initState Setting data pos of %p to %zu", this, mDataPos);
    mConnection = nullptr;
    mSession = nullptr;
    mObjects = nullptr;
    mObjectsSize = 0;
    mObjectsCapacity = 0;
+17 −17
Original line number Diff line number Diff line
@@ -149,38 +149,38 @@ void RpcServer::join() {
        {
            std::lock_guard<std::mutex> _l(mLock);

            sp<RpcConnection> connection;
            if (id == RPC_CONNECTION_ID_NEW) {
            sp<RpcSession> session;
            if (id == RPC_SESSION_ID_NEW) {
                // new client!
                LOG_ALWAYS_FATAL_IF(mConnectionIdCounter >= INT32_MAX, "Out of connection IDs");
                mConnectionIdCounter++;
                LOG_ALWAYS_FATAL_IF(mSessionIdCounter >= INT32_MAX, "Out of session IDs");
                mSessionIdCounter++;

                connection = RpcConnection::make();
                connection->setForServer(wp<RpcServer>::fromExisting(this), mConnectionIdCounter);
                session = RpcSession::make();
                session->setForServer(wp<RpcServer>::fromExisting(this), mSessionIdCounter);

                mConnections[mConnectionIdCounter] = connection;
                mSessions[mSessionIdCounter] = session;
            } else {
                auto it = mConnections.find(id);
                if (it == mConnections.end()) {
                    ALOGE("Cannot add thread, no record of connection with ID %d", id);
                auto it = mSessions.find(id);
                if (it == mSessions.end()) {
                    ALOGE("Cannot add thread, no record of session with ID %d", id);
                    continue;
                }
                connection = it->second;
                session = it->second;
            }

            connection->startThread(std::move(clientFd));
            session->startThread(std::move(clientFd));
        }
    }
}

std::vector<sp<RpcConnection>> RpcServer::listConnections() {
std::vector<sp<RpcSession>> RpcServer::listSessions() {
    std::lock_guard<std::mutex> _l(mLock);
    std::vector<sp<RpcConnection>> connections;
    for (auto& [id, connection] : mConnections) {
    std::vector<sp<RpcSession>> sessions;
    for (auto& [id, session] : mSessions) {
        (void)id;
        connections.push_back(connection);
        sessions.push_back(session);
    }
    return connections;
    return sessions;
}

bool RpcServer::setupSocketServer(const RpcSocketAddress& addr) {
+376 −0

File changed and moved.

Preview size limit exceeded, changes collapsed.

Loading