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

Commit 024727b2 authored by Andrei Homescu's avatar Andrei Homescu
Browse files

libbinder: add makeDefaultRpcTransportCtxFactory

Add a new OS-specific function that creates a new
instance of the default RpcTransportCtxFactory.
This is needed because Android and Trusty have
different default transports: RpcTransportRaw and
RpcTransportTipcTrusty, respectively.

Bug: 230135749
Test: presubmit
Change-Id: I4abd443fe9a08c1fa0cc41dfca7ef1cdb69fe0fb
parent b125642b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "OS.h"

#include <android-base/file.h>
#include <binder/RpcTransportRaw.h>
#include <string.h>

using android::base::ErrnoError;
@@ -58,4 +59,8 @@ status_t dupFileDescriptor(int oldFd, int* newFd) {
    return OK;
}

std::unique_ptr<RpcTransportCtxFactory> makeDefaultRpcTransportCtxFactory() {
    return RpcTransportCtxFactoryRaw::make();
}

} // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

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

namespace android {
@@ -30,4 +31,6 @@ status_t getRandomBytes(uint8_t* data, size_t size);

status_t dupFileDescriptor(int oldFd, int* newFd);

std::unique_ptr<RpcTransportCtxFactory> makeDefaultRpcTransportCtxFactory();

} // namespace android
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ RpcServer::~RpcServer() {
sp<RpcServer> RpcServer::make(std::unique_ptr<RpcTransportCtxFactory> rpcTransportCtxFactory) {
    // Default is without TLS.
    if (rpcTransportCtxFactory == nullptr)
        rpcTransportCtxFactory = RpcTransportCtxFactoryRaw::make();
        rpcTransportCtxFactory = makeDefaultRpcTransportCtxFactory();
    auto ctx = rpcTransportCtxFactory->newServerCtx();
    if (ctx == nullptr) return nullptr;
    return sp<RpcServer>::make(std::move(ctx));
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ RpcSession::~RpcSession() {

sp<RpcSession> RpcSession::make() {
    // Default is without TLS.
    return make(RpcTransportCtxFactoryRaw::make());
    return make(makeDefaultRpcTransportCtxFactory());
}

sp<RpcSession> RpcSession::make(std::unique_ptr<RpcTransportCtxFactory> rpcTransportCtxFactory) {
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
#include <lib/rand/rand.h>
#endif

#include <binder/RpcTransportTipcTrusty.h>

#include "../OS.h"

using android::base::Result;
@@ -46,4 +48,8 @@ status_t dupFileDescriptor(int oldFd, int* newFd) {
    return INVALID_OPERATION;
}

std::unique_ptr<RpcTransportCtxFactory> makeDefaultRpcTransportCtxFactory() {
    return RpcTransportCtxFactoryTipcTrusty::make();
}

} // namespace android