RpcServer: expose server fd

Add a few functions that allows to expose the socket()
fd, because socket() and accept() may be called
in different processes.

Test: binderRpcTest
Test: binderLibTest
Bug: 182914638
Change-Id: I5489516fc92977aca4c98ee2dcdfa8365f8740c9
diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp
index dc10d1c..9cc6e7f 100644
--- a/libs/binder/RpcServer.cpp
+++ b/libs/binder/RpcServer.cpp
@@ -272,8 +272,26 @@
 }
 
 bool RpcServer::hasServer() {
+    LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
     std::lock_guard<std::mutex> _l(mLock);
     return mServer.ok();
 }
 
+unique_fd RpcServer::releaseServer() {
+    LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
+    std::lock_guard<std::mutex> _l(mLock);
+    return std::move(mServer);
+}
+
+bool RpcServer::setupExternalServer(base::unique_fd serverFd) {
+    LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
+    std::lock_guard<std::mutex> _l(mLock);
+    if (mServer.ok()) {
+        ALOGE("Each RpcServer can only have one server.");
+        return false;
+    }
+    mServer = std::move(serverFd);
+    return true;
+}
+
 } // namespace android