Loading libs/binder/RpcServer.cpp +5 −6 Original line number Diff line number Diff line Loading @@ -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; } Loading @@ -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; } Loading libs/binder/include/binder/RpcServer.h +7 −1 Original line number Diff line number Diff line Loading @@ -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. Loading libs/binder/servicedispatcher.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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; } Loading Loading @@ -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; } Loading libs/binder/tests/binderLibTest.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -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 {}; } Loading libs/binder/tests/binderRpcTest.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } Loading Loading @@ -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(); Loading Loading
libs/binder/RpcServer.cpp +5 −6 Original line number Diff line number Diff line Loading @@ -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; } Loading @@ -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; } Loading
libs/binder/include/binder/RpcServer.h +7 −1 Original line number Diff line number Diff line Loading @@ -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. Loading
libs/binder/servicedispatcher.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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; } Loading Loading @@ -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; } Loading
libs/binder/tests/binderLibTest.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -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 {}; } Loading
libs/binder/tests/binderRpcTest.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } Loading Loading @@ -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(); Loading