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

Commit 639490b9 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Binder unique_fd

Test: mma
Bug: 302723053
Change-Id: I52f14cadb027b3f854946d5315dce3d23aa21b19
parent 8f331666
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
../../libs/binder/include/binder/unique_fd.h
 No newline at end of file
+7 −7
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
#include <atomic>
#include <set>

#include <android-base/unique_fd.h>
#include <binder/BpBinder.h>
#include <binder/IInterface.h>
#include <binder/IPCThreadState.h>
@@ -28,6 +27,7 @@
#include <binder/Parcel.h>
#include <binder/RecordedTransaction.h>
#include <binder/RpcServer.h>
#include <binder/unique_fd.h>
#include <pthread.h>

#include <inttypes.h>
@@ -43,6 +43,8 @@

namespace android {

using android::binder::unique_fd;

constexpr uid_t kUidRoot = 0;

// Service implementations inherit from BBinder and IBinder, and this is frozen
@@ -167,8 +169,7 @@ status_t IBinder::getDebugPid(pid_t* out) {
    return OK;
}

status_t IBinder::setRpcClientDebug(android::base::unique_fd socketFd,
                                    const sp<IBinder>& keepAliveBinder) {
status_t IBinder::setRpcClientDebug(unique_fd socketFd, const sp<IBinder>& keepAliveBinder) {
    if (!kEnableRpcDevServers) {
        ALOGW("setRpcClientDebug disallowed because RPC is not enabled");
        return INVALID_OPERATION;
@@ -273,7 +274,7 @@ public:
    std::set<sp<RpcServerLink>> mRpcServerLinks;
    BpBinder::ObjectManager mObjects;

    android::base::unique_fd mRecordingFd;
    unique_fd mRecordingFd;
};

// ---------------------------------------------------------------------------
@@ -640,7 +641,7 @@ status_t BBinder::setRpcClientDebug(const Parcel& data) {
    }
    status_t status;
    bool hasSocketFd;
    android::base::unique_fd clientFd;
    unique_fd clientFd;

    if (status = data.readBool(&hasSocketFd); status != OK) return status;
    if (hasSocketFd) {
@@ -652,8 +653,7 @@ status_t BBinder::setRpcClientDebug(const Parcel& data) {
    return setRpcClientDebug(std::move(clientFd), keepAliveBinder);
}

status_t BBinder::setRpcClientDebug(android::base::unique_fd socketFd,
                                    const sp<IBinder>& keepAliveBinder) {
status_t BBinder::setRpcClientDebug(unique_fd socketFd, const sp<IBinder>& keepAliveBinder) {
    if (!kEnableRpcDevServers) {
        ALOGW("%s: disallowed because RPC is not enabled", __PRETTY_FUNCTION__);
        return INVALID_OPERATION;
+3 −1
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@

namespace android {

using android::binder::unique_fd;

// ---------------------------------------------------------------------------

RpcMutex BpBinder::sTrackingLock;
@@ -318,7 +320,7 @@ status_t BpBinder::pingBinder()
    return transact(PING_TRANSACTION, data, &reply);
}

status_t BpBinder::startRecordingBinder(const android::base::unique_fd& fd) {
status_t BpBinder::startRecordingBinder(const unique_fd& fd) {
    Parcel send, reply;
    send.writeUniqueFileDescriptor(fd);
    return transact(START_RECORDING_TRANSACTION, send, &reply);
+2 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@

#include <binder/Functional.h>

#include "FdUtils.h"
#include "RpcState.h"
#include "Utils.h"

@@ -33,7 +34,7 @@ using namespace android::binder::impl;
std::unique_ptr<FdTrigger> FdTrigger::make() {
    auto ret = std::make_unique<FdTrigger>();
#ifndef BINDER_RPC_SINGLE_THREADED
    if (!android::base::Pipe(&ret->mRead, &ret->mWrite)) {
    if (!binder::Pipe(&ret->mRead, &ret->mWrite)) {
        ALOGE("Could not create pipe %s", strerror(errno));
        return nullptr;
    }
+3 −3
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@

#include <memory>

#include <android-base/unique_fd.h>
#include <utils/Errors.h>

#include <binder/RpcTransport.h>
#include <binder/unique_fd.h>

namespace android {

@@ -61,8 +61,8 @@ private:
#ifdef BINDER_RPC_SINGLE_THREADED
    bool mTriggered = false;
#else
    base::unique_fd mWrite;
    base::unique_fd mRead;
    binder::unique_fd mWrite;
    binder::unique_fd mRead;
#endif
};
} // namespace android
Loading