Merge "[fidl] Fix the last usages of raw channels"
diff --git a/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl b/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl
index 312889c..37f9d00 100644
--- a/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl
+++ b/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl
@@ -50,7 +50,8 @@
         abort();
     }
 
-    zx::channel channel(GetConnectToServiceFunction()(GOLDFISH_ADDRESS_SPACE_DEVICE_NAME));
+    fidl::ClientEnd<AddressSpaceDevice> channel{
+        zx::channel(GetConnectToServiceFunction()(GOLDFISH_ADDRESS_SPACE_DEVICE_NAME))};
     if (!channel) {
         ALOGE("%s: failed to get service handle for " GOLDFISH_ADDRESS_SPACE_DEVICE_NAME,
               __FUNCTION__);
@@ -300,7 +301,8 @@
 }
 
 address_space_handle_t goldfish_address_space_open() {
-    zx::channel channel(GetConnectToServiceFunction()(GOLDFISH_ADDRESS_SPACE_DEVICE_NAME));
+    fidl::ClientEnd<AddressSpaceDevice> channel{
+        zx::channel(GetConnectToServiceFunction()(GOLDFISH_ADDRESS_SPACE_DEVICE_NAME))};
     if (!channel) {
         ALOGE("%s: failed to get service handle for " GOLDFISH_ADDRESS_SPACE_DEVICE_NAME,
               __FUNCTION__);
diff --git a/system/OpenglSystemCommon/ProcessPipe.cpp b/system/OpenglSystemCommon/ProcessPipe.cpp
index 5a7b4d6..f08ca25 100644
--- a/system/OpenglSystemCommon/ProcessPipe.cpp
+++ b/system/OpenglSystemCommon/ProcessPipe.cpp
@@ -75,7 +75,8 @@
 static void processPipeInitOnce() {
     initSeqno();
 
-    zx::channel channel(GetConnectToServiceFunction()(QEMU_PIPE_PATH));
+    fidl::ClientEnd<llcpp::fuchsia::hardware::goldfish::PipeDevice> channel{
+        zx::channel(GetConnectToServiceFunction()(QEMU_PIPE_PATH))};
     if (!channel) {
         ALOGE("%s: failed to open " QEMU_PIPE_PATH,
               __FUNCTION__);
diff --git a/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp b/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
index d53ee0b..4bc74fe 100644
--- a/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
+++ b/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
@@ -72,7 +72,8 @@
 
 int QemuPipeStream::connect(void)
 {
-    zx::channel channel(GetConnectToServiceFunction()(QEMU_PIPE_PATH));
+    fidl::ClientEnd<llcpp::fuchsia::hardware::goldfish::PipeDevice> channel{
+        zx::channel(GetConnectToServiceFunction()(QEMU_PIPE_PATH))};
     if (!channel) {
         ALOGE("%s: failed to get service handle for " QEMU_PIPE_PATH,
               __FUNCTION__);
diff --git a/system/vulkan/goldfish_vulkan.cpp b/system/vulkan/goldfish_vulkan.cpp
index d518800..76ed9f3 100644
--- a/system/vulkan/goldfish_vulkan.cpp
+++ b/system/vulkan/goldfish_vulkan.cpp
@@ -894,25 +894,31 @@
 };
 
 void VulkanDevice::InitLogger() {
-   zx_handle_t channel = GetConnectToServiceFunction()("/svc/fuchsia.logger.LogSink");
-   if (channel == ZX_HANDLE_INVALID)
-      return;
+  auto log_service = ([] () -> std::optional<zx::socket> {
+    fidl::ClientEnd<llcpp::fuchsia::logger::LogSink> channel{zx::channel{
+      GetConnectToServiceFunction()("/svc/fuchsia.logger.LogSink")}};
+    if (!channel.is_valid())
+      return std::nullopt;
 
-  zx::socket local_socket, remote_socket;
-  zx_status_t status = zx::socket::create(ZX_SOCKET_DATAGRAM, &local_socket, &remote_socket);
-  if (status != ZX_OK)
-    return;
+    zx::socket local_socket, remote_socket;
+    zx_status_t status = zx::socket::create(ZX_SOCKET_DATAGRAM, &local_socket, &remote_socket);
+    if (status != ZX_OK)
+      return std::nullopt;
 
-  auto result = llcpp::fuchsia::logger::LogSink::Call::Connect(
-      zx::unowned_channel(channel), std::move(remote_socket));
-  zx_handle_close(channel);
+    auto result = llcpp::fuchsia::logger::LogSink::Call::Connect(
+        channel, std::move(remote_socket));
 
-  if (result.status() != ZX_OK)
+    if (!result.ok())
+      return std::nullopt;
+
+    return local_socket;
+  })();
+  if (!log_service)
     return;
 
   fx_logger_config_t config = {.min_severity = FX_LOG_INFO,
                                .console_fd = -1,
-                               .log_service_channel = local_socket.release(),
+                               .log_service_channel = log_service->release(),
                                .tags = nullptr,
                                .num_tags = 0};
 
diff --git a/system/vulkan_enc/ResourceTracker.cpp b/system/vulkan_enc/ResourceTracker.cpp
index 09947a5..acfe9bf 100644
--- a/system/vulkan_enc/ResourceTracker.cpp
+++ b/system/vulkan_enc/ResourceTracker.cpp
@@ -921,7 +921,8 @@
 
 #ifdef VK_USE_PLATFORM_FUCHSIA
         if (mFeatureInfo->hasVulkan) {
-            zx::channel channel(GetConnectToServiceFunction()("/dev/class/goldfish-control/000"));
+            fidl::ClientEnd<llcpp::fuchsia::hardware::goldfish::ControlDevice> channel{
+                zx::channel(GetConnectToServiceFunction()("/dev/class/goldfish-control/000"))};
             if (!channel) {
                 ALOGE("failed to open control device");
                 abort();
@@ -930,7 +931,8 @@
                 llcpp::fuchsia::hardware::goldfish::ControlDevice::SyncClient>(
                 std::move(channel));
 
-            zx::channel sysmem_channel(GetConnectToServiceFunction()("/svc/fuchsia.sysmem.Allocator"));
+            fidl::ClientEnd<llcpp::fuchsia::sysmem::Allocator> sysmem_channel{
+                zx::channel(GetConnectToServiceFunction()("/svc/fuchsia.sysmem.Allocator"))};
             if (!sysmem_channel) {
                 ALOGE("failed to open sysmem connection");
             }