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

Commit 99262d27 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

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

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


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

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


        return true;
        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);
          port);
    return false;
    return false;
}
}
+7 −1
Original line number Original line Diff line number Diff line
@@ -72,8 +72,14 @@ public:
     * Set |port| to 0 to pick an ephemeral port; see discussion of
     * 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|
     * /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.
     * 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.
     * If setup*Server has been successful, return true. Otherwise return false.
+3 −2
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ using std::string_view_literals::operator""sv;


namespace {
namespace {


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


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


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


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


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