Merge "[fidl] Finish fitx::result migration"
diff --git a/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl b/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl
index 451b9f3..3568c76 100644
--- a/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl
+++ b/shared/GoldfishAddressSpace/include/goldfish_address_space_fuchsia.impl
@@ -33,7 +33,7 @@
 #include <unordered_map>
 
 #define GET_STATUS_SAFE(result, member) \
-    ((result).ok() ? ((result).Unwrap_NEW()->member) : ZX_OK)
+    ((result).ok() ? ((result)->member) : ZX_OK)
 
 using android::base::guest::AutoLock;
 using android::base::guest::Lock;
@@ -131,12 +131,12 @@
     const fidl::WireSyncClient<AddressSpaceChildDriver>& driver = provider->m_child_driver;
 
     auto result = driver->AllocateBlock(size);
-    if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+    if (!result.ok() || result->res != ZX_OK) {
         ALOGE("%s: allocate block failed: %d:%d", __func__, result.status(), GET_STATUS_SAFE(result, res));
         return false;
     }
-    m_phys_addr = result.Unwrap_NEW()->paddr;
-    m_vmo = result.Unwrap_NEW()->vmo.release();
+    m_phys_addr = result->paddr;
+    m_vmo = result->vmo.release();
 
     m_size = size;
     m_offset = 0;
@@ -225,13 +225,13 @@
             abort();
             // int32_t res = ZX_OK;
             // auto result = m_driver->UnclaimShared(m_offset);
-            // if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+            // if (!result.ok() || result->res != ZX_OK) {
             //     ALOGE("%s: unclaim shared block failed: %d:%d", __func__,
             //           result.status(), GET_STATUS_SAFE(result, res));
             // }
         } else {
             auto result = (*m_driver)->DeallocateBlock(m_phys_addr);
-            if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+            if (!result.ok() || result->res != ZX_OK) {
                 ALOGE("%s: deallocate block failed: %d:%d", __func__,
                       result.status(), GET_STATUS_SAFE(result, res));
             }
@@ -359,12 +359,12 @@
 
     zx::vmo vmo;
     auto result = deviceSync->AllocateBlock(size);
-    if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+    if (!result.ok() || result->res != ZX_OK) {
         ALOGE("%s: allocate block failed: %d:%d", __func__, result.status(), GET_STATUS_SAFE(result, res));
         return false;
     }
-    *phys_addr = result.Unwrap_NEW()->paddr;
-    vmo = std::move(result.Unwrap_NEW()->vmo);
+    *phys_addr = result->paddr;
+    vmo = std::move(result->vmo);
 
     *offset = 0;
 
@@ -388,7 +388,7 @@
             fidl::WireSyncClient<AddressSpaceChildDriver>*>(handle);
 
     auto result = deviceSync->DeallocateBlock(info.phys_addr);
-    if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+    if (!result.ok() || result->res != ZX_OK) {
         ALOGE("%s: deallocate block failed: %d:%d", __func__, result.status(), GET_STATUS_SAFE(result, res));
         return false;
     }
@@ -405,11 +405,11 @@
 
     zx::vmo vmo;
     auto result = deviceSync->ClaimSharedBlock(offset, size);
-    if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+    if (!result.ok() || result->res != ZX_OK) {
         ALOGE("%s: claim shared failed: %d:%d", __func__, result.status(), GET_STATUS_SAFE(result, res));
         return false;
     }
-    vmo = std::move(result.Unwrap_NEW()->vmo);
+    vmo = std::move(result->vmo);
 
     VmoStore::Info info = {
         vmo.release(),
@@ -427,7 +427,7 @@
             fidl::WireSyncClient<AddressSpaceChildDriver>*>(handle);
 
     auto result = deviceSync->UnclaimSharedBlock(offset);
-    if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+    if (!result.ok() || result->res != ZX_OK) {
         ALOGE("%s: unclaim shared failed: %d:%d", __func__, result.status(), GET_STATUS_SAFE(result, res));
         return false;
     }
@@ -474,10 +474,10 @@
 
     AddressSpaceChildDriverPingMessage res;
     auto result = deviceSync->Ping(fuchsiaPing);
-    if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+    if (!result.ok() || result->res != ZX_OK) {
         return false;
     }
-    res = std::move(result.Unwrap_NEW()->ping);
+    res = std::move(result->ping);
 
     *ping = *(struct address_space_ping*)(&res);
     return true;
diff --git a/system/OpenglSystemCommon/ProcessPipe.cpp b/system/OpenglSystemCommon/ProcessPipe.cpp
index 0b98fdc..5198d57 100644
--- a/system/OpenglSystemCommon/ProcessPipe.cpp
+++ b/system/OpenglSystemCommon/ProcessPipe.cpp
@@ -35,7 +35,7 @@
 #include "services/service_connector.h"
 
 #define GET_STATUS_SAFE(result, member) \
-    ((result).ok() ? ((result).Unwrap_NEW()->member) : ZX_OK)
+    ((result).ok() ? ((result)->member) : ZX_OK)
 
 static QEMU_PIPE_HANDLE   sProcDevice = 0;
 #else // __Fuchsia__
@@ -101,12 +101,12 @@
     zx::vmo vmo;
     {
         auto result = pipe->GetBuffer();
-        if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+        if (!result.ok() || result->res != ZX_OK) {
             ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__,
                   result.status(), GET_STATUS_SAFE(result, res));
             return;
         }
-        vmo = std::move(result.Unwrap_NEW()->vmo);
+        vmo = std::move(result->vmo);
     }
 
     size_t len = strlen("pipe:GLProcessPipe");
@@ -118,7 +118,7 @@
 
     {
         auto result = pipe->Write(len + 1, 0);
-        if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+        if (!result.ok() || result->res != ZX_OK) {
             ALOGD("%s: connecting to pipe service failed: %d:%d", __FUNCTION__,
                   result.status(), GET_STATUS_SAFE(result, res));
             return;
@@ -135,7 +135,7 @@
 
     {
         auto result = pipe->DoCall(sizeof(confirmInt), 0, sizeof(sProcUID), 0);
-        if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+        if (!result.ok() || result->res != ZX_OK) {
             ALOGD("%s: failed to get per-process ID: %d:%d", __FUNCTION__,
                   result.status(), GET_STATUS_SAFE(result, res));
             return;
diff --git a/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp b/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
index cbf0514..20f1d97 100644
--- a/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
+++ b/system/OpenglSystemCommon/QemuPipeStreamFuchsia.cpp
@@ -29,7 +29,7 @@
 #include "services/service_connector.h"
 
 #define GET_STATUS_SAFE(result, member) \
-    ((result).ok() ? ((result).Unwrap_NEW()->member) : ZX_OK)
+    ((result).ok() ? ((result)->member) : ZX_OK)
 
 constexpr size_t kReadSize = 512 * 1024;
 constexpr size_t kWriteOffset = kReadSize;
@@ -131,7 +131,7 @@
 
     {
         auto result = m_pipe->Write(len + 1, 0);
-        if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+        if (!result.ok() || result->res != ZX_OK) {
             ALOGD("%s: connecting to pipe service failed: %d:%d", __FUNCTION__,
                   result.status(), GET_STATUS_SAFE(result, res));
             return -1;
@@ -166,7 +166,7 @@
 
     {
         auto result = m_pipe->SetBufferSize(allocSize);
-        if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+        if (!result.ok() || result->res != ZX_OK) {
             ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__,
                   result.status(), GET_STATUS_SAFE(result, res));
             return nullptr;
@@ -176,12 +176,12 @@
     zx::vmo vmo;
     {
         auto result = m_pipe->GetBuffer();
-        if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+        if (!result.ok() || result->res != ZX_OK) {
             ALOGE("%s: failed to get buffer: %d:%d", __FUNCTION__,
                   result.status(), GET_STATUS_SAFE(result, res));
             return nullptr;
         }
-        vmo = std::move(result.Unwrap_NEW()->vmo);
+        vmo = std::move(result->vmo);
     }
 
     zx_vaddr_t mapped_addr;
@@ -204,7 +204,7 @@
     if (size == 0) return 0;
 
     auto result = m_pipe->DoCall(size, kWriteOffset, 0, 0);
-    if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+    if (!result.ok() || result->res != ZX_OK) {
         ALOGD("%s: Pipe call failed: %d:%d", __FUNCTION__, result.status(),
               GET_STATUS_SAFE(result, res));
         return -1;
@@ -269,8 +269,8 @@
     }
 
     // Updated buffered read size.
-    if (result.Unwrap_NEW()->actual) {
-        m_read = m_readLeft = result.Unwrap_NEW()->actual;
+    if (result->actual) {
+        m_read = m_readLeft = result->actual;
     }
 
     // Consume buffered read and read more if neccessary.
@@ -292,13 +292,13 @@
             return nullptr;
         }
 
-        if (result.Unwrap_NEW()->actual) {
-            m_read = m_readLeft = result.Unwrap_NEW()->actual;
+        if (result->actual) {
+            m_read = m_readLeft = result->actual;
             continue;
         }
-        if (result.Unwrap_NEW()->res != ZX_ERR_SHOULD_WAIT) {
+        if (result->res != ZX_ERR_SHOULD_WAIT) {
             ALOGD("%s: Error reading from pipe: %d", __FUNCTION__,
-                  result.Unwrap_NEW()->res);
+                  result->res);
             return nullptr;
         }
 
diff --git a/system/vulkan_enc/ResourceTracker.cpp b/system/vulkan_enc/ResourceTracker.cpp
index 2ae573f..91e4b30 100644
--- a/system/vulkan_enc/ResourceTracker.cpp
+++ b/system/vulkan_enc/ResourceTracker.cpp
@@ -50,7 +50,7 @@
 #endif
 
 #define GET_STATUS_SAFE(result, member) \
-    ((result).ok() ? ((result).Unwrap_NEW()->member) : ZX_OK)
+    ((result).ok() ? ((result)->member) : ZX_OK)
 
 #else
 
@@ -1934,9 +1934,9 @@
                 result.status());
             return VK_ERROR_INITIALIZATION_FAILED;
         }
-        if (result.value_NEW().is_ok()) {
-            memoryProperty = result.value_NEW().value()->info.memory_property();
-        } else if (result.value_NEW().error_value() == ZX_ERR_NOT_FOUND) {
+        if (result.value().is_ok()) {
+            memoryProperty = result.value().value()->info.memory_property();
+        } else if (result.value().error_value() == ZX_ERR_NOT_FOUND) {
             // If an VMO is allocated while ColorBuffer/Buffer is not created,
             // it must be a device-local buffer, since for host-visible buffers,
             // ColorBuffer/Buffer is created at sysmem allocation time.
@@ -1947,7 +1947,7 @@
             // VkMemoryZirconHandlePropertiesFUCHSIA with no available
             // memoryType bits should be enough for clients. See fxbug.dev/24225
             // for other issues this this flow.
-            ALOGW("GetBufferHandleInfo failed: %d", result.value_NEW().error_value());
+            ALOGW("GetBufferHandleInfo failed: %d", result.value().error_value());
             pProperties->memoryTypeBits = 0;
             return VK_SUCCESS;
         }
@@ -3199,13 +3199,13 @@
             collection);
 
         auto result = sysmem_collection->WaitForBuffersAllocated();
-        if (!result.ok() || result.Unwrap_NEW()->status != ZX_OK) {
+        if (!result.ok() || result->status != ZX_OK) {
             ALOGE("Failed wait for allocation: %d %d", result.status(),
                   GET_STATUS_SAFE(result, status));
             return VK_ERROR_INITIALIZATION_FAILED;
         }
         fuchsia_sysmem::wire::BufferCollectionInfo2 info =
-            std::move(result.Unwrap_NEW()->buffer_collection_info);
+            std::move(result->buffer_collection_info);
 
         bool is_host_visible =
             info.settings.buffer_settings.heap ==
@@ -3431,13 +3431,13 @@
             fidl::WireSyncClient<fuchsia_sysmem::BufferCollection>*>(collection);
 
         auto result = sysmem_collection->WaitForBuffersAllocated();
-        if (!result.ok() || result.Unwrap_NEW()->status != ZX_OK) {
+        if (!result.ok() || result->status != ZX_OK) {
             ALOGE("Failed wait for allocation: %d %d", result.status(),
                   GET_STATUS_SAFE(result, status));
             return VK_ERROR_INITIALIZATION_FAILED;
         }
         fuchsia_sysmem::wire::BufferCollectionInfo2 info =
-            std::move(result.Unwrap_NEW()->buffer_collection_info);
+            std::move(result->buffer_collection_info);
 
         bool is_host_visible = info.settings.buffer_settings.heap ==
                                fuchsia_sysmem::wire::HeapType::kGoldfishHostVisible;
@@ -4095,13 +4095,13 @@
                 fidl::WireSyncClient<fuchsia_sysmem::BufferCollection>*>(
                 importBufferCollectionInfoPtr->collection);
             auto result = collection->WaitForBuffersAllocated();
-            if (!result.ok() || result.Unwrap_NEW()->status != ZX_OK) {
+            if (!result.ok() || result->status != ZX_OK) {
                 ALOGE("WaitForBuffersAllocated failed: %d %d", result.status(),
                       GET_STATUS_SAFE(result, status));
                 _RETURN_FAILURE_WITH_DEVICE_MEMORY_REPORT(VK_ERROR_INITIALIZATION_FAILED);
             }
             fuchsia_sysmem::wire::BufferCollectionInfo2& info =
-                result.Unwrap_NEW()->buffer_collection_info;
+                result->buffer_collection_info;
             uint32_t index = importBufferCollectionInfoPtr->index;
             if (info.buffer_count < index) {
                 ALOGE("Invalid buffer index: %d %d", index);
@@ -4115,14 +4115,14 @@
                 fidl::WireSyncClient<fuchsia_sysmem::BufferCollection>*>(
                 importBufferCollectionInfoPtrX->collection);
             auto result = collection->WaitForBuffersAllocated();
-            if (!result.ok() || result.Unwrap_NEW()->status != ZX_OK) {
+            if (!result.ok() || result->status != ZX_OK) {
                 ALOGE("WaitForBuffersAllocated failed: %d %d", result.status(),
                       GET_STATUS_SAFE(result, status));
                 _RETURN_FAILURE_WITH_DEVICE_MEMORY_REPORT(
                     VK_ERROR_INITIALIZATION_FAILED);
             }
             fuchsia_sysmem::wire::BufferCollectionInfo2& info =
-                result.Unwrap_NEW()->buffer_collection_info;
+                result->buffer_collection_info;
             uint32_t index = importBufferCollectionInfoPtrX->index;
             if (info.buffer_count < index) {
                 ALOGE("Invalid buffer index: %d %d", index);
@@ -4267,9 +4267,9 @@
 
                 {
                     auto result = collection->WaitForBuffersAllocated();
-                    if (result.ok() && result.Unwrap_NEW()->status == ZX_OK) {
+                    if (result.ok() && result->status == ZX_OK) {
                         fuchsia_sysmem::wire::BufferCollectionInfo2& info =
-                            result.Unwrap_NEW()->buffer_collection_info;
+                            result->buffer_collection_info;
                         if (!info.buffer_count) {
                             ALOGE(
                                 "WaitForBuffersAllocated returned "
@@ -4362,9 +4362,9 @@
 
                         auto result = mControlDevice->CreateColorBuffer2(
                             std::move(vmo_copy), std::move(createParams));
-                        if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+                        if (!result.ok() || result->res != ZX_OK) {
                             if (result.ok() &&
-                                result.Unwrap_NEW()->res == ZX_ERR_ALREADY_EXISTS) {
+                                result->res == ZX_ERR_ALREADY_EXISTS) {
                                 ALOGD(
                                     "CreateColorBuffer: color buffer already "
                                     "exists\n");
@@ -4389,7 +4389,7 @@
 
                     auto result =
                         mControlDevice->CreateBuffer2(std::move(vmo_copy), std::move(createParams));
-                    if (!result.ok() || result.Unwrap_NEW()->is_error()) {
+                    if (!result.ok() || result->is_error()) {
                         ALOGE("CreateBuffer2 failed: %d:%d", result.status(),
                               GET_STATUS_SAFE(result, error_value()));
                         abort();
@@ -4410,13 +4410,13 @@
             zx_status_t status2 = ZX_OK;
 
             auto result = mControlDevice->GetBufferHandle(std::move(vmo_copy));
-            if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+            if (!result.ok() || result->res != ZX_OK) {
                 ALOGE("GetBufferHandle failed: %d:%d", result.status(),
                       GET_STATUS_SAFE(result, res));
             } else {
                 fuchsia_hardware_goldfish::wire::BufferHandleType
-                    handle_type = result.Unwrap_NEW()->type;
-                uint32_t buffer_handle = result.Unwrap_NEW()->id;
+                    handle_type = result->type;
+                uint32_t buffer_handle = result->id;
 
                 if (handle_type == fuchsia_hardware_goldfish::wire::
                                        BufferHandleType::kBuffer) {
@@ -4954,8 +4954,8 @@
             fuchsia_sysmem::wire::BufferCollectionInfo2 info;
 
             auto result = collection->WaitForBuffersAllocated();
-            if (result.ok() && result.Unwrap_NEW()->status == ZX_OK) {
-                info = std::move(result.Unwrap_NEW()->buffer_collection_info);
+            if (result.ok() && result->status == ZX_OK) {
+                info = std::move(result->buffer_collection_info);
                 if (index < info.buffer_count && info.settings.has_image_format_constraints) {
                     vmo = std::move(info.buffers[index].vmo);
                 }
@@ -4978,16 +4978,16 @@
                           buffer_handle_result.status());
                     abort();
                 }
-                if (buffer_handle_result.value_NEW().res == ZX_OK) {
+                if (buffer_handle_result.value().res == ZX_OK) {
                     // Buffer handle already exists.
                     // If it is a ColorBuffer, no-op; Otherwise return error.
-                    if (buffer_handle_result.value_NEW().type !=
+                    if (buffer_handle_result.value().type !=
                         fuchsia_hardware_goldfish::wire::BufferHandleType::kColorBuffer) {
                         ALOGE("%s: BufferHandle %u is not a ColorBuffer", __func__,
-                              buffer_handle_result.value_NEW().id);
+                              buffer_handle_result.value().id);
                         return VK_ERROR_OUT_OF_HOST_MEMORY;
                     }
-                } else if (buffer_handle_result.value_NEW().res == ZX_ERR_NOT_FOUND) {
+                } else if (buffer_handle_result.value().res == ZX_ERR_NOT_FOUND) {
                     // Buffer handle not found. Create ColorBuffer based on buffer settings.
                     auto format =
                         info.settings.image_format_constraints.pixel_format.type ==
@@ -5013,10 +5013,10 @@
 
                     auto result =
                         mControlDevice->CreateColorBuffer2(std::move(vmo), std::move(createParams));
-                    if (result.ok() && result.Unwrap_NEW()->res == ZX_ERR_ALREADY_EXISTS) {
+                    if (result.ok() && result->res == ZX_ERR_ALREADY_EXISTS) {
                         ALOGD(
                             "CreateColorBuffer: color buffer already exists\n");
-                    } else if (!result.ok() || result.Unwrap_NEW()->res != ZX_OK) {
+                    } else if (!result.ok() || result->res != ZX_OK) {
                         ALOGE("CreateColorBuffer failed: %d:%d", result.status(),
                             GET_STATUS_SAFE(result, res));
                     }
@@ -6060,8 +6060,8 @@
             uint32_t index = extBufferCollectionPtr->index;
 
             auto result = collection->WaitForBuffersAllocated();
-            if (result.ok() && result.Unwrap_NEW()->status == ZX_OK) {
-                auto& info = result.Unwrap_NEW()->buffer_collection_info;
+            if (result.ok() && result->status == ZX_OK) {
+                auto& info = result->buffer_collection_info;
                 if (index < info.buffer_count) {
                     vmo = android::base::makeOptional(
                             std::move(info.buffers[index].vmo));
@@ -6081,8 +6081,8 @@
                 auto result =
                     mControlDevice->CreateBuffer2(std::move(*vmo), createParams);
                 if (!result.ok() ||
-                    (result.Unwrap_NEW()->is_error() != ZX_OK &&
-                     result.Unwrap_NEW()->error_value() != ZX_ERR_ALREADY_EXISTS)) {
+                    (result->is_error() != ZX_OK &&
+                     result->error_value() != ZX_ERR_ALREADY_EXISTS)) {
                     ALOGE("CreateBuffer2 failed: %d:%d", result.status(),
                           GET_STATUS_SAFE(result, error_value()));
                 }