libbinder: RPC sock addr associated with RpcServer

This is in preparation for RpcServer having a single thread which loops
w/ accept4. With this CL, since this is moved, there is no way to
identify which thread comes with which client, so the ability to have
multiple clients is temporarily limited (fixed in CL above this). Either
way, nothing currently needs this functionality.

Bug: 185167543
Test: binderRpcTest
Change-Id: I48821970f7cbcb3fec0df00465296072d96db608
diff --git a/libs/binder/tests/binderRpcBenchmark.cpp b/libs/binder/tests/binderRpcBenchmark.cpp
index b3282ff..ce47c0d 100644
--- a/libs/binder/tests/binderRpcBenchmark.cpp
+++ b/libs/binder/tests/binderRpcBenchmark.cpp
@@ -121,12 +121,8 @@
     std::thread([addr]() {
         sp<RpcServer> server = RpcServer::make();
         server->setRootObject(sp<MyBinderRpcBenchmark>::make());
-
         server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction();
-
-        sp<RpcConnection> connection = server->addClientConnection();
-        CHECK(connection->setupUnixDomainServer(addr.c_str()));
-
+        CHECK(server->setupUnixDomainServer(addr.c_str()));
         server->join();
     }).detach();
 
diff --git a/libs/binder/tests/binderRpcTest.cpp b/libs/binder/tests/binderRpcTest.cpp
index f3ec904..d23df8e 100644
--- a/libs/binder/tests/binderRpcTest.cpp
+++ b/libs/binder/tests/binderRpcTest.cpp
@@ -78,7 +78,7 @@
 
 class MyBinderRpcTest : public BnBinderRpcTest {
 public:
-    sp<RpcConnection> connection;
+    wp<RpcServer> server;
 
     Status sendString(const std::string& str) override {
         (void)str;
@@ -89,13 +89,23 @@
         return Status::ok();
     }
     Status countBinders(int32_t* out) override {
-        if (connection == nullptr) {
+        sp<RpcServer> spServer = server.promote();
+        if (spServer == nullptr) {
             return Status::fromExceptionCode(Status::EX_NULL_POINTER);
         }
-        *out = connection->state()->countBinders();
-        if (*out != 1) {
-            connection->state()->dump();
+        size_t count = 0;
+        for (auto connection : spServer->listConnections()) {
+            count += connection->state()->countBinders();
         }
+        // help debugging if we don't have one binder (this call is always made
+        // in this test when exactly one binder is held, which is held only to
+        // call this method - all other binders should be cleaned up)
+        if (count != 1) {
+            for (auto connection : spServer->listConnections()) {
+                connection->state()->dump();
+            }
+        }
+        *out = count;
         return Status::ok();
     }
     Status pingMe(const sp<IBinder>& binder, int32_t* out) override {
@@ -296,8 +306,7 @@
     // This creates a new process serving an interface on a certain number of
     // threads.
     ProcessConnection createRpcTestSocketServerProcess(
-            size_t numThreads,
-            const std::function<void(const sp<RpcServer>&, const sp<RpcConnection>&)>& configure) {
+            size_t numThreads, const std::function<void(const sp<RpcServer>&)>& configure) {
         SocketType socketType = GetParam();
 
         std::string addr = allocateSocketAddress();
@@ -312,21 +321,18 @@
                     server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction();
                     server->setMaxThreads(numThreads);
 
-                    // server supporting one client on one socket
-                    sp<RpcConnection> connection = server->addClientConnection();
-
                     switch (socketType) {
                         case SocketType::UNIX:
-                            CHECK(connection->setupUnixDomainServer(addr.c_str())) << addr;
+                            CHECK(server->setupUnixDomainServer(addr.c_str())) << addr;
                             break;
 #ifdef __BIONIC__
                         case SocketType::VSOCK:
-                            CHECK(connection->setupVsockServer(vsockPort));
+                            CHECK(server->setupVsockServer(vsockPort));
                             break;
 #endif // __BIONIC__
                         case SocketType::INET: {
                             unsigned int outPort = 0;
-                            CHECK(connection->setupInetServer(0, &outPort));
+                            CHECK(server->setupInetServer(0, &outPort));
                             CHECK_NE(0, outPort);
                             CHECK(android::base::WriteFully(pipe->writeEnd(), &outPort,
                                                             sizeof(outPort)));
@@ -336,7 +342,7 @@
                             LOG_ALWAYS_FATAL("Unknown socket type");
                     }
 
-                    configure(server, connection);
+                    configure(server);
 
                     server->join();
                 }),
@@ -379,13 +385,11 @@
     BinderRpcTestProcessConnection createRpcTestSocketServerProcess(size_t numThreads) {
         BinderRpcTestProcessConnection ret{
                 .proc = createRpcTestSocketServerProcess(numThreads,
-                                                         [&](const sp<RpcServer>& server,
-                                                             const sp<RpcConnection>& connection) {
+                                                         [&](const sp<RpcServer>& server) {
                                                              sp<MyBinderRpcTest> service =
                                                                      new MyBinderRpcTest;
                                                              server->setRootObject(service);
-                                                             service->connection =
-                                                                     connection; // for testing only
+                                                             service->server = server;
                                                          }),
         };
 
@@ -397,12 +401,10 @@
 };
 
 TEST_P(BinderRpc, RootObjectIsNull) {
-    auto proc = createRpcTestSocketServerProcess(1,
-                                                 [](const sp<RpcServer>& server,
-                                                    const sp<RpcConnection>&) {
-                                                     // this is the default, but to be explicit
-                                                     server->setRootObject(nullptr);
-                                                 });
+    auto proc = createRpcTestSocketServerProcess(1, [](const sp<RpcServer>& server) {
+        // this is the default, but to be explicit
+        server->setRootObject(nullptr);
+    });
 
     // retrieved by getRootObject when process is created above
     EXPECT_EQ(nullptr, proc.rootBinder);