[goldfish-pipe] Use Controller FIDL

Use the new Controller FIDL to access the goldfish PipeDevice.

Bug: fuchsia:112355
Change-Id: I1479931312724c6dce61905af76b98c894d9e5fa
diff --git a/system/OpenglSystemCommon/ProcessPipe.cpp b/system/OpenglSystemCommon/ProcessPipe.cpp
index c02bd5f..280f171 100644
--- a/system/OpenglSystemCommon/ProcessPipe.cpp
+++ b/system/OpenglSystemCommon/ProcessPipe.cpp
@@ -76,16 +76,28 @@
 static void processPipeInitOnce() {
     initSeqno();
 
-    fidl::ClientEnd<fuchsia_hardware_goldfish::PipeDevice> channel{
+    fidl::ClientEnd<fuchsia_hardware_goldfish::Controller> controller_channel{
         zx::channel(GetConnectToServiceFunction()(QEMU_PIPE_PATH))};
-    if (!channel) {
+    if (!controller_channel) {
         ALOGE("%s: failed to open " QEMU_PIPE_PATH,
               __FUNCTION__);
         return;
     }
+    fidl::WireSyncClient controller(std::move(controller_channel));
+    zx::result pipe_device_ends =
+        fidl::CreateEndpoints<fuchsia_hardware_goldfish::PipeDevice>();
+    if (pipe_device_ends.is_error()) {
+        ALOGE("%s: zx_channel_create failed: %s", __FUNCTION__, pipe_device_ends.status_string());
+        return;
+    }
 
-    fidl::WireSyncClient<fuchsia_hardware_goldfish::PipeDevice> device(
-        std::move(channel));
+    if (fidl::Status result = controller->OpenSession(std::move(pipe_device_ends->server));
+        !result.ok()) {
+        ALOGE("%s: failed to open session: %s", __FUNCTION__, result.status_string());
+        return;
+    }
+
+    fidl::WireSyncClient device(std::move(pipe_device_ends->client));
 
     auto pipe_ends =
         fidl::CreateEndpoints<::fuchsia_hardware_goldfish::Pipe>();
@@ -94,8 +106,7 @@
         return;
     }
 
-    fidl::WireSyncClient<fuchsia_hardware_goldfish::Pipe> pipe(
-        std::move(pipe_ends->client));
+    fidl::WireSyncClient pipe(std::move(pipe_ends->client));
     device->OpenPipe(std::move(pipe_ends->server));
 
     zx::vmo vmo;
diff --git a/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp b/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
index 20f1d97..4e47a46 100644
--- a/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
+++ b/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
@@ -72,17 +72,30 @@
 
 int QemuPipeStream::connect(void)
 {
-    fidl::ClientEnd<fuchsia_hardware_goldfish::PipeDevice> channel{
+    fidl::ClientEnd<fuchsia_hardware_goldfish::Controller> controller_channel{
         zx::channel(GetConnectToServiceFunction()(QEMU_PIPE_PATH))};
-    if (!channel) {
-        ALOGE("%s: failed to get service handle for " QEMU_PIPE_PATH,
+    if (!controller_channel) {
+        ALOGE("%s: failed to open " QEMU_PIPE_PATH,
               __FUNCTION__);
         return -1;
     }
+    fidl::WireSyncClient controller(std::move(controller_channel));
+    zx::result pipe_device_ends =
+        fidl::CreateEndpoints<fuchsia_hardware_goldfish::PipeDevice>();
+    if (pipe_device_ends.is_error()) {
+        ALOGE("%s: zx_channel_create failed: %s", __FUNCTION__, pipe_device_ends.status_string());
+        return -1;
+    }
+
+    if (fidl::Status result = controller->OpenSession(std::move(pipe_device_ends->server));
+        !result.ok()) {
+        ALOGE("%s: failed to open session: %s", __FUNCTION__, result.status_string());
+        return -1;
+    }
 
     m_device = std::make_unique<
         fidl::WireSyncClient<fuchsia_hardware_goldfish::PipeDevice>>(
-        std::move(channel));
+        std::move(pipe_device_ends->client));
 
     auto pipe_ends =
         fidl::CreateEndpoints<::fuchsia_hardware_goldfish::Pipe>();