diff --git a/adb/daemon/file_sync_service.cpp b/adb/daemon/file_sync_service.cpp index 7ae806a0e..8c39a20fa 100644 --- a/adb/daemon/file_sync_service.cpp +++ b/adb/daemon/file_sync_service.cpp @@ -527,7 +527,7 @@ static bool handle_sync_command(int fd, std::vector& buffer) { return true; } -void file_sync_service(android::base::unique_fd fd) { +void file_sync_service(unique_fd fd) { std::vector 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 01081d298..f300e7b3a 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 +#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 9a620ab7f..8d28c49a3 100644 --- a/adb/daemon/framebuffer_service.cpp +++ b/adb/daemon/framebuffer_service.cpp @@ -57,7 +57,7 @@ struct fbinfo { 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 d99c6fe14..264da597e 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 +#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 1bb2fbb3a..76a1452a0 100644 --- a/adb/daemon/remount_service.cpp +++ b/adb/daemon/remount_service.cpp @@ -215,7 +215,7 @@ static void reboot_for_remount(int fd, bool need_fsck) { 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 @@ void remount_service(android::base::unique_fd fd, const std::string& cmd) { 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 45821eef2..e4e2550d4 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 -#include +#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 0f804e933..8c98c2d74 100644 --- a/adb/daemon/set_verity_enable_state_service.cpp +++ b/adb/daemon/set_verity_enable_state_service.cpp @@ -132,7 +132,7 @@ static bool set_avb_verity_enabled_state(int fd, AvbOps* ops, bool enable_verity 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 9f84f35ea..c1413c8e0 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 +#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 f04960eff..639bb463a 100644 --- a/adb/services.cpp +++ b/adb/services.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #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 func, - android::base::unique_fd fd) { +void service_bootstrap_func(std::string service_name, std::function 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 @@ void restart_root_service(android::base::unique_fd fd) { 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 @@ void restart_unroot_service(android::base::unique_fd fd) { 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 @@ void restart_tcp_service(android::base::unique_fd fd, int port) { 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 @@ bool reboot_service_impl(android::base::unique_fd fd, const std::string& arg) { 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 reboot_service(android::base::unique_fd fd, const std::string& arg) { } } -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 @@ int ShellService(const std::string& args, const atransport* transport) { #endif // !ADB_HOST -android::base::unique_fd create_service_thread(const char* service_name, - std::function func) { +unique_fd create_service_thread(const char* service_name, std::function 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 @@ android::base::unique_fd create_service_thread(const char* service_name, } #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 @@ void connect_emulator(const std::string& port_spec, std::string* response) { } } -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);