adb: use adb's unique_fd instead of android::base.

Replace all usages of android::base::unique_fd with the unique_fd from
adb_unique_fd.h, which calls adb_close instead of close on Windows.

Most of these changes are no-ops, except for the ones to
create_service_thread, which was probably pretty broken on Windows.

Test: python test_device.py
Test: adb_test
Test: wine adb_test.exe
Change-Id: Ia4d03f9e2e7ddc88c97dc64172d721f93f3bf853
diff --git a/adb/daemon/file_sync_service.cpp b/adb/daemon/file_sync_service.cpp
index 7ae806a..8c39a20 100644
--- a/adb/daemon/file_sync_service.cpp
+++ b/adb/daemon/file_sync_service.cpp
@@ -527,7 +527,7 @@
     return true;
 }
 
-void file_sync_service(android::base::unique_fd fd) {
+void file_sync_service(unique_fd fd) {
     std::vector<char> buffer(SYNC_DATA_MAX);
 
     while (handle_sync_command(fd.get(), buffer)) {
diff --git a/adb/daemon/file_sync_service.h b/adb/daemon/file_sync_service.h
index 01081d2..f300e7b 100644
--- a/adb/daemon/file_sync_service.h
+++ b/adb/daemon/file_sync_service.h
@@ -1,5 +1,3 @@
-#pragma once
-
 /*
  * Copyright (C) 2018 The Android Open Source Project
  *
@@ -16,6 +14,8 @@
  * limitations under the License.
  */
 
-#include <android-base/unique_fd.h>
+#pragma once
 
-void file_sync_service(android::base::unique_fd fd);
+#include "adb_unique_fd.h"
+
+void file_sync_service(unique_fd fd);
diff --git a/adb/daemon/framebuffer_service.cpp b/adb/daemon/framebuffer_service.cpp
index 9a620ab..8d28c49 100644
--- a/adb/daemon/framebuffer_service.cpp
+++ b/adb/daemon/framebuffer_service.cpp
@@ -57,7 +57,7 @@
     unsigned int alpha_length;
 } __attribute__((packed));
 
-void framebuffer_service(android::base::unique_fd fd) {
+void framebuffer_service(unique_fd fd) {
     struct fbinfo fbinfo;
     unsigned int i, bsize;
     char buf[640];
diff --git a/adb/daemon/framebuffer_service.h b/adb/daemon/framebuffer_service.h
index d99c6fe..264da59 100644
--- a/adb/daemon/framebuffer_service.h
+++ b/adb/daemon/framebuffer_service.h
@@ -14,11 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef _DAEMON_FRAMEBUFFER_SERVICE_H_
-#define _DAEMON_FRAMEBUFFER_SERVICE_H_
+#pragma once
 
-#include <android-base/unique_fd.h>
+#include "adb_unique_fd.h"
 
-void framebuffer_service(android::base::unique_fd fd);
-
-#endif  // _DAEMON_FRAMEBUFFER_SERVICE_H_
+void framebuffer_service(unique_fd fd);
diff --git a/adb/daemon/remount_service.cpp b/adb/daemon/remount_service.cpp
index 1bb2fbb..76a1452 100644
--- a/adb/daemon/remount_service.cpp
+++ b/adb/daemon/remount_service.cpp
@@ -215,7 +215,7 @@
     android::base::SetProperty(ANDROID_RB_PROPERTY, reboot_cmd.c_str());
 }
 
-void remount_service(android::base::unique_fd fd, const std::string& cmd) {
+void remount_service(unique_fd fd, const std::string& cmd) {
     bool user_requested_reboot = cmd != "-R";
 
     if (getuid() != 0) {
@@ -251,7 +251,7 @@
     if (user_requested_reboot) {
         if (!dedup.empty() || verity_enabled) {
             if (verity_enabled) {
-                set_verity_enabled_state_service(android::base::unique_fd(dup(fd.get())), false);
+                set_verity_enabled_state_service(unique_fd(dup(fd.get())), false);
             }
             reboot_for_remount(fd.get(), !dedup.empty());
             return;
diff --git a/adb/daemon/remount_service.h b/adb/daemon/remount_service.h
index 45821ee..e4e2550 100644
--- a/adb/daemon/remount_service.h
+++ b/adb/daemon/remount_service.h
@@ -14,14 +14,11 @@
  * limitations under the License.
  */
 
-#ifndef _REMOUNT_SERVICE_H_
-#define _REMOUNT_SERVICE_H_
+#pragma once
 
 #include <string>
 
-#include <android-base/unique_fd.h>
+#include "adb_unique_fd.h"
 
 bool make_block_device_writable(const std::string&);
-void remount_service(android::base::unique_fd, const std::string&);
-
-#endif
+void remount_service(unique_fd, const std::string&);
diff --git a/adb/daemon/set_verity_enable_state_service.cpp b/adb/daemon/set_verity_enable_state_service.cpp
index 0f804e9..8c98c2d 100644
--- a/adb/daemon/set_verity_enable_state_service.cpp
+++ b/adb/daemon/set_verity_enable_state_service.cpp
@@ -132,7 +132,7 @@
     return true;
 }
 
-void set_verity_enabled_state_service(android::base::unique_fd fd, bool enable) {
+void set_verity_enabled_state_service(unique_fd fd, bool enable) {
     bool any_changed = false;
 
     // Figure out if we're using VB1.0 or VB2.0 (aka AVB) - by
diff --git a/adb/daemon/set_verity_enable_state_service.h b/adb/daemon/set_verity_enable_state_service.h
index 9f84f35..c1413c8 100644
--- a/adb/daemon/set_verity_enable_state_service.h
+++ b/adb/daemon/set_verity_enable_state_service.h
@@ -14,11 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef _DAEMON_SET_VERITY_ENABLED_STATE_SERVICE_H_
-#define _DAEMON_SET_VERITY_ENABLED_STATE_SERVICE_H_
+#pragma once
 
-#include <android-base/unique_fd.h>
+#include "adb_unique_fd.h"
 
-void set_verity_enabled_state_service(android::base::unique_fd fd, bool enable);
-
-#endif  // _DAEMON_SET_VERITY_ENABLED_STATE_SERVICE_H_
+void set_verity_enabled_state_service(unique_fd fd, bool enable);
diff --git a/adb/services.cpp b/adb/services.cpp
index f04960e..639bb46 100644
--- a/adb/services.cpp
+++ b/adb/services.cpp
@@ -37,7 +37,6 @@
 #include <android-base/parsenetaddress.h>
 #include <android-base/stringprintf.h>
 #include <android-base/strings.h>
-#include <android-base/unique_fd.h>
 #include <cutils/sockets.h>
 
 #if !ADB_HOST
@@ -49,6 +48,7 @@
 
 #include "adb.h"
 #include "adb_io.h"
+#include "adb_unique_fd.h"
 #include "adb_utils.h"
 #if !ADB_HOST
 #include "daemon/file_sync_service.h"
@@ -64,16 +64,15 @@
 
 namespace {
 
-void service_bootstrap_func(std::string service_name,
-                            std::function<void(android::base::unique_fd)> func,
-                            android::base::unique_fd fd) {
+void service_bootstrap_func(std::string service_name, std::function<void(unique_fd)> func,
+                            unique_fd fd) {
     adb_thread_setname(android::base::StringPrintf("%s svc %d", service_name.c_str(), fd.get()));
     func(std::move(fd));
 }
 
 #if !ADB_HOST
 
-void restart_root_service(android::base::unique_fd fd) {
+void restart_root_service(unique_fd fd) {
     if (getuid() == 0) {
         WriteFdExactly(fd.get(), "adbd is already running as root\n");
         return;
@@ -87,7 +86,7 @@
     WriteFdExactly(fd.get(), "restarting adbd as root\n");
 }
 
-void restart_unroot_service(android::base::unique_fd fd) {
+void restart_unroot_service(unique_fd fd) {
     if (getuid() != 0) {
         WriteFdExactly(fd.get(), "adbd not running as root\n");
         return;
@@ -96,7 +95,7 @@
     WriteFdExactly(fd.get(), "restarting adbd as non root\n");
 }
 
-void restart_tcp_service(android::base::unique_fd fd, int port) {
+void restart_tcp_service(unique_fd fd, int port) {
     if (port <= 0) {
         WriteFdFmt(fd.get(), "invalid port %d\n", port);
         return;
@@ -106,12 +105,12 @@
     WriteFdFmt(fd.get(), "restarting in TCP mode port: %d\n", port);
 }
 
-void restart_usb_service(android::base::unique_fd fd) {
+void restart_usb_service(unique_fd fd) {
     android::base::SetProperty("service.adb.tcp.port", "0");
     WriteFdExactly(fd.get(), "restarting in USB mode\n");
 }
 
-bool reboot_service_impl(android::base::unique_fd fd, const std::string& arg) {
+bool reboot_service_impl(unique_fd fd, const std::string& arg) {
     std::string reboot_arg = arg;
     bool auto_reboot = false;
 
@@ -152,7 +151,7 @@
     return true;
 }
 
-void reboot_service(android::base::unique_fd fd, const std::string& arg) {
+void reboot_service(unique_fd fd, const std::string& arg) {
     if (!reboot_service_impl(std::move(fd), arg)) {
         return;
     }
@@ -163,7 +162,7 @@
     }
 }
 
-void reconnect_service(android::base::unique_fd fd, atransport* t) {
+void reconnect_service(unique_fd fd, atransport* t) {
     WriteFdExactly(fd, "done");
     kick_transport(t);
 }
@@ -223,12 +222,11 @@
 
 #endif  // !ADB_HOST
 
-android::base::unique_fd create_service_thread(const char* service_name,
-                                               std::function<void(android::base::unique_fd)> func) {
+unique_fd create_service_thread(const char* service_name, std::function<void(unique_fd)> func) {
     int s[2];
     if (adb_socketpair(s)) {
         printf("cannot create service socket pair\n");
-        return android::base::unique_fd();
+        return unique_fd();
     }
     D("socketpair: (%d,%d)", s[0], s[1]);
 
@@ -241,10 +239,10 @@
     }
 #endif // !ADB_HOST
 
-    std::thread(service_bootstrap_func, service_name, func, android::base::unique_fd(s[1])).detach();
+    std::thread(service_bootstrap_func, service_name, func, unique_fd(s[1])).detach();
 
     D("service thread started, %d:%d",s[0], s[1]);
-    return android::base::unique_fd(s[0]);
+    return unique_fd(s[0]);
 }
 
 }  // namespace
@@ -407,7 +405,7 @@
     }
 }
 
-static void connect_service(android::base::unique_fd fd, std::string host) {
+static void connect_service(unique_fd fd, std::string host) {
     std::string response;
     if (!strncmp(host.c_str(), "emu:", 4)) {
         connect_emulator(host.c_str() + 4, &response);