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

Commit 138409c3 authored by Devin Moore's avatar Devin Moore Committed by Automerger Merge Worker
Browse files

Merge "binder RPC add IP address argument when setting up Inet socket" am:...

Merge "binder RPC add IP address argument when setting up Inet socket" am: a5c24dce am: daa4d918 am: 99262d27

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

Change-Id: I5f5bd7d09e275f97f0069daa9442050ccaaf7e4f
parents 1d83f209 99262d27
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -61,14 +61,13 @@ bool RpcServer::setupVsockServer(unsigned int port) {
    return setupSocketServer(VsockSocketAddress(kAnyCid, port));
}

bool RpcServer::setupInetServer(unsigned int port, unsigned int* assignedPort) {
    const char* kAddr = "127.0.0.1";

bool RpcServer::setupInetServer(const char* address, unsigned int port,
                                unsigned int* assignedPort) {
    if (assignedPort != nullptr) *assignedPort = 0;
    auto aiStart = InetSocketAddress::getAddrInfo(kAddr, port);
    auto aiStart = InetSocketAddress::getAddrInfo(address, port);
    if (aiStart == nullptr) return false;
    for (auto ai = aiStart.get(); ai != nullptr; ai = ai->ai_next) {
        InetSocketAddress socketAddress(ai->ai_addr, ai->ai_addrlen, kAddr, port);
        InetSocketAddress socketAddress(ai->ai_addr, ai->ai_addrlen, address, port);
        if (!setupSocketServer(socketAddress)) {
            continue;
        }
@@ -95,7 +94,7 @@ bool RpcServer::setupInetServer(unsigned int port, unsigned int* assignedPort) {

        return true;
    }
    ALOGE("None of the socket address resolved for %s:%u can be set up as inet server.", kAddr,
    ALOGE("None of the socket address resolved for %s:%u can be set up as inet server.", address,
          port);
    return false;
}
+7 −1
Original line number Diff line number Diff line
@@ -72,8 +72,14 @@ public:
     * Set |port| to 0 to pick an ephemeral port; see discussion of
     * /proc/sys/net/ipv4/ip_local_port_range in ip(7). In this case, |assignedPort|
     * will be set to the picked port number, if it is not null.
     *
     * Set the IPv4 address for the socket to be listening on.
     * "127.0.0.1" allows for local connections from the same device.
     * "0.0.0.0" allows for connections on any IP address that the device may
     * have
     */
    [[nodiscard]] bool setupInetServer(unsigned int port, unsigned int* assignedPort);
    [[nodiscard]] bool setupInetServer(const char* address, unsigned int port,
                                       unsigned int* assignedPort);

    /**
     * If setup*Server has been successful, return true. Otherwise return false.
+3 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ using std::string_view_literals::operator""sv;

namespace {

const char* kLocalInetAddress = "127.0.0.1";
using ServiceRetriever = decltype(&android::IServiceManager::checkService);

int Usage(const char* program) {
@@ -86,7 +87,7 @@ int Dispatch(const char* name, const ServiceRetriever& serviceRetriever) {
    }
    rpcServer->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction();
    unsigned int port;
    if (!rpcServer->setupInetServer(0, &port)) {
    if (!rpcServer->setupInetServer(kLocalInetAddress, 0, &port)) {
        LOG(ERROR) << "setupInetServer failed";
        return EX_SOFTWARE;
    }
@@ -199,7 +200,7 @@ int wrapServiceManager(const ServiceRetriever& serviceRetriever) {
    rpcServer->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction();
    rpcServer->setRootObject(service);
    unsigned int port;
    if (!rpcServer->setupInetServer(0, &port)) {
    if (!rpcServer->setupInetServer(kLocalInetAddress, 0, &port)) {
        LOG(ERROR) << "Unable to set up inet server";
        return EX_SOFTWARE;
    }
+1 −1
Original line number Diff line number Diff line
@@ -1192,7 +1192,7 @@ public:
        if (rpcServer == nullptr) return {};
        rpcServer->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction();
        unsigned int port;
        if (!rpcServer->setupInetServer(0, &port)) {
        if (!rpcServer->setupInetServer("127.0.0.1", 0, &port)) {
            ADD_FAILURE() << "setupInetServer failed";
            return {};
        }
+3 −2
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ namespace android {

static_assert(RPC_WIRE_PROTOCOL_VERSION + 1 == RPC_WIRE_PROTOCOL_VERSION_NEXT ||
              RPC_WIRE_PROTOCOL_VERSION == RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL);
const char* kLocalInetAddress = "127.0.0.1";

TEST(BinderRpcParcel, EntireParcelFormatted) {
    Parcel p;
@@ -439,7 +440,7 @@ public:
                            CHECK(server->setupVsockServer(vsockPort));
                            break;
                        case SocketType::INET: {
                            CHECK(server->setupInetServer(0, &outPort));
                            CHECK(server->setupInetServer(kLocalInetAddress, 0, &outPort));
                            CHECK_NE(0, outPort);
                            break;
                        }
@@ -1253,7 +1254,7 @@ TEST(BinderRpc, Java) {
    auto rpcServer = RpcServer::make();
    rpcServer->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction();
    unsigned int port;
    ASSERT_TRUE(rpcServer->setupInetServer(0, &port));
    ASSERT_TRUE(rpcServer->setupInetServer(kLocalInetAddress, 0, &port));
    auto socket = rpcServer->releaseServer();

    auto keepAlive = sp<BBinder>::make();