diff options
author | Josh Gao | 2018-07-25 18:51:59 -0500 |
---|---|---|
committer | Josh Gao | 2018-07-25 20:08:45 -0500 |
commit | 73a5ee4df5628681899f0e2e81ff77d768599e4d (patch) | |
tree | 1ac209cb5cbe6aa93cdee907616ff81a0160e522 | |
parent | 2deb787ee25f202f0a68d7cd7460f922d8cdbf9c (diff) | |
download | platform-system-core-73a5ee4df5628681899f0e2e81ff77d768599e4d.tar.gz platform-system-core-73a5ee4df5628681899f0e2e81ff77d768599e4d.tar.xz platform-system-core-73a5ee4df5628681899f0e2e81ff77d768599e4d.zip |
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
-rw-r--r-- | adb/daemon/file_sync_service.cpp | 2 | ||||
-rw-r--r-- | adb/daemon/file_sync_service.h | 8 | ||||
-rw-r--r-- | adb/daemon/framebuffer_service.cpp | 2 | ||||
-rw-r--r-- | adb/daemon/framebuffer_service.h | 9 | ||||
-rw-r--r-- | adb/daemon/remount_service.cpp | 4 | ||||
-rw-r--r-- | adb/daemon/remount_service.h | 9 | ||||
-rw-r--r-- | adb/daemon/set_verity_enable_state_service.cpp | 2 | ||||
-rw-r--r-- | adb/daemon/set_verity_enable_state_service.h | 9 | ||||
-rw-r--r-- | adb/services.cpp | 32 |
9 files changed, 33 insertions, 44 deletions
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<char>& buffer) { | |||
527 | return true; | 527 | return true; |
528 | } | 528 | } |
529 | 529 | ||
530 | void file_sync_service(android::base::unique_fd fd) { | 530 | void file_sync_service(unique_fd fd) { |
531 | std::vector<char> buffer(SYNC_DATA_MAX); | 531 | std::vector<char> buffer(SYNC_DATA_MAX); |
532 | 532 | ||
533 | while (handle_sync_command(fd.get(), buffer)) { | 533 | 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 @@ | |||
1 | #pragma once | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (C) 2018 The Android Open Source Project | 2 | * Copyright (C) 2018 The Android Open Source Project |
5 | * | 3 | * |
@@ -16,6 +14,8 @@ | |||
16 | * limitations under the License. | 14 | * limitations under the License. |
17 | */ | 15 | */ |
18 | 16 | ||
19 | #include <android-base/unique_fd.h> | 17 | #pragma once |
18 | |||
19 | #include "adb_unique_fd.h" | ||
20 | 20 | ||
21 | void file_sync_service(android::base::unique_fd fd); | 21 | 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 { | |||
57 | unsigned int alpha_length; | 57 | unsigned int alpha_length; |
58 | } __attribute__((packed)); | 58 | } __attribute__((packed)); |
59 | 59 | ||
60 | void framebuffer_service(android::base::unique_fd fd) { | 60 | void framebuffer_service(unique_fd fd) { |
61 | struct fbinfo fbinfo; | 61 | struct fbinfo fbinfo; |
62 | unsigned int i, bsize; | 62 | unsigned int i, bsize; |
63 | char buf[640]; | 63 | 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 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef _DAEMON_FRAMEBUFFER_SERVICE_H_ | 17 | #pragma once |
18 | #define _DAEMON_FRAMEBUFFER_SERVICE_H_ | ||
19 | 18 | ||
20 | #include <android-base/unique_fd.h> | 19 | #include "adb_unique_fd.h" |
21 | 20 | ||
22 | void framebuffer_service(android::base::unique_fd fd); | 21 | void framebuffer_service(unique_fd fd); |
23 | |||
24 | #endif // _DAEMON_FRAMEBUFFER_SERVICE_H_ | ||
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) { | |||
215 | android::base::SetProperty(ANDROID_RB_PROPERTY, reboot_cmd.c_str()); | 215 | android::base::SetProperty(ANDROID_RB_PROPERTY, reboot_cmd.c_str()); |
216 | } | 216 | } |
217 | 217 | ||
218 | void remount_service(android::base::unique_fd fd, const std::string& cmd) { | 218 | void remount_service(unique_fd fd, const std::string& cmd) { |
219 | bool user_requested_reboot = cmd != "-R"; | 219 | bool user_requested_reboot = cmd != "-R"; |
220 | 220 | ||
221 | if (getuid() != 0) { | 221 | if (getuid() != 0) { |
@@ -251,7 +251,7 @@ void remount_service(android::base::unique_fd fd, const std::string& cmd) { | |||
251 | if (user_requested_reboot) { | 251 | if (user_requested_reboot) { |
252 | if (!dedup.empty() || verity_enabled) { | 252 | if (!dedup.empty() || verity_enabled) { |
253 | if (verity_enabled) { | 253 | if (verity_enabled) { |
254 | set_verity_enabled_state_service(android::base::unique_fd(dup(fd.get())), false); | 254 | set_verity_enabled_state_service(unique_fd(dup(fd.get())), false); |
255 | } | 255 | } |
256 | reboot_for_remount(fd.get(), !dedup.empty()); | 256 | reboot_for_remount(fd.get(), !dedup.empty()); |
257 | return; | 257 | 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 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef _REMOUNT_SERVICE_H_ | 17 | #pragma once |
18 | #define _REMOUNT_SERVICE_H_ | ||
19 | 18 | ||
20 | #include <string> | 19 | #include <string> |
21 | 20 | ||
22 | #include <android-base/unique_fd.h> | 21 | #include "adb_unique_fd.h" |
23 | 22 | ||
24 | bool make_block_device_writable(const std::string&); | 23 | bool make_block_device_writable(const std::string&); |
25 | void remount_service(android::base::unique_fd, const std::string&); | 24 | void remount_service(unique_fd, const std::string&); |
26 | |||
27 | #endif | ||
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 | |||
132 | return true; | 132 | return true; |
133 | } | 133 | } |
134 | 134 | ||
135 | void set_verity_enabled_state_service(android::base::unique_fd fd, bool enable) { | 135 | void set_verity_enabled_state_service(unique_fd fd, bool enable) { |
136 | bool any_changed = false; | 136 | bool any_changed = false; |
137 | 137 | ||
138 | // Figure out if we're using VB1.0 or VB2.0 (aka AVB) - by | 138 | // 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 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef _DAEMON_SET_VERITY_ENABLED_STATE_SERVICE_H_ | 17 | #pragma once |
18 | #define _DAEMON_SET_VERITY_ENABLED_STATE_SERVICE_H_ | ||
19 | 18 | ||
20 | #include <android-base/unique_fd.h> | 19 | #include "adb_unique_fd.h" |
21 | 20 | ||
22 | void set_verity_enabled_state_service(android::base::unique_fd fd, bool enable); | 21 | void set_verity_enabled_state_service(unique_fd fd, bool enable); |
23 | |||
24 | #endif // _DAEMON_SET_VERITY_ENABLED_STATE_SERVICE_H_ | ||
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 @@ | |||
37 | #include <android-base/parsenetaddress.h> | 37 | #include <android-base/parsenetaddress.h> |
38 | #include <android-base/stringprintf.h> | 38 | #include <android-base/stringprintf.h> |
39 | #include <android-base/strings.h> | 39 | #include <android-base/strings.h> |
40 | #include <android-base/unique_fd.h> | ||
41 | #include <cutils/sockets.h> | 40 | #include <cutils/sockets.h> |
42 | 41 | ||
43 | #if !ADB_HOST | 42 | #if !ADB_HOST |
@@ -49,6 +48,7 @@ | |||
49 | 48 | ||
50 | #include "adb.h" | 49 | #include "adb.h" |
51 | #include "adb_io.h" | 50 | #include "adb_io.h" |
51 | #include "adb_unique_fd.h" | ||
52 | #include "adb_utils.h" | 52 | #include "adb_utils.h" |
53 | #if !ADB_HOST | 53 | #if !ADB_HOST |
54 | #include "daemon/file_sync_service.h" | 54 | #include "daemon/file_sync_service.h" |
@@ -64,16 +64,15 @@ | |||
64 | 64 | ||
65 | namespace { | 65 | namespace { |
66 | 66 | ||
67 | void service_bootstrap_func(std::string service_name, | 67 | void service_bootstrap_func(std::string service_name, std::function<void(unique_fd)> func, |
68 | std::function<void(android::base::unique_fd)> func, | 68 | unique_fd fd) { |
69 | android::base::unique_fd fd) { | ||
70 | adb_thread_setname(android::base::StringPrintf("%s svc %d", service_name.c_str(), fd.get())); | 69 | adb_thread_setname(android::base::StringPrintf("%s svc %d", service_name.c_str(), fd.get())); |
71 | func(std::move(fd)); | 70 | func(std::move(fd)); |
72 | } | 71 | } |
73 | 72 | ||
74 | #if !ADB_HOST | 73 | #if !ADB_HOST |
75 | 74 | ||
76 | void restart_root_service(android::base::unique_fd fd) { | 75 | void restart_root_service(unique_fd fd) { |
77 | if (getuid() == 0) { | 76 | if (getuid() == 0) { |
78 | WriteFdExactly(fd.get(), "adbd is already running as root\n"); | 77 | WriteFdExactly(fd.get(), "adbd is already running as root\n"); |
79 | return; | 78 | return; |
@@ -87,7 +86,7 @@ void restart_root_service(android::base::unique_fd fd) { | |||
87 | WriteFdExactly(fd.get(), "restarting adbd as root\n"); | 86 | WriteFdExactly(fd.get(), "restarting adbd as root\n"); |
88 | } | 87 | } |
89 | 88 | ||
90 | void restart_unroot_service(android::base::unique_fd fd) { | 89 | void restart_unroot_service(unique_fd fd) { |
91 | if (getuid() != 0) { | 90 | if (getuid() != 0) { |
92 | WriteFdExactly(fd.get(), "adbd not running as root\n"); | 91 | WriteFdExactly(fd.get(), "adbd not running as root\n"); |
93 | return; | 92 | return; |
@@ -96,7 +95,7 @@ void restart_unroot_service(android::base::unique_fd fd) { | |||
96 | WriteFdExactly(fd.get(), "restarting adbd as non root\n"); | 95 | WriteFdExactly(fd.get(), "restarting adbd as non root\n"); |
97 | } | 96 | } |
98 | 97 | ||
99 | void restart_tcp_service(android::base::unique_fd fd, int port) { | 98 | void restart_tcp_service(unique_fd fd, int port) { |
100 | if (port <= 0) { | 99 | if (port <= 0) { |
101 | WriteFdFmt(fd.get(), "invalid port %d\n", port); | 100 | WriteFdFmt(fd.get(), "invalid port %d\n", port); |
102 | return; | 101 | return; |
@@ -106,12 +105,12 @@ void restart_tcp_service(android::base::unique_fd fd, int port) { | |||
106 | WriteFdFmt(fd.get(), "restarting in TCP mode port: %d\n", port); | 105 | WriteFdFmt(fd.get(), "restarting in TCP mode port: %d\n", port); |
107 | } | 106 | } |
108 | 107 | ||
109 | void restart_usb_service(android::base::unique_fd fd) { | 108 | void restart_usb_service(unique_fd fd) { |
110 | android::base::SetProperty("service.adb.tcp.port", "0"); | 109 | android::base::SetProperty("service.adb.tcp.port", "0"); |
111 | WriteFdExactly(fd.get(), "restarting in USB mode\n"); | 110 | WriteFdExactly(fd.get(), "restarting in USB mode\n"); |
112 | } | 111 | } |
113 | 112 | ||
114 | bool reboot_service_impl(android::base::unique_fd fd, const std::string& arg) { | 113 | bool reboot_service_impl(unique_fd fd, const std::string& arg) { |
115 | std::string reboot_arg = arg; | 114 | std::string reboot_arg = arg; |
116 | bool auto_reboot = false; | 115 | bool auto_reboot = false; |
117 | 116 | ||
@@ -152,7 +151,7 @@ bool reboot_service_impl(android::base::unique_fd fd, const std::string& arg) { | |||
152 | return true; | 151 | return true; |
153 | } | 152 | } |
154 | 153 | ||
155 | void reboot_service(android::base::unique_fd fd, const std::string& arg) { | 154 | void reboot_service(unique_fd fd, const std::string& arg) { |
156 | if (!reboot_service_impl(std::move(fd), arg)) { | 155 | if (!reboot_service_impl(std::move(fd), arg)) { |
157 | return; | 156 | return; |
158 | } | 157 | } |
@@ -163,7 +162,7 @@ void reboot_service(android::base::unique_fd fd, const std::string& arg) { | |||
163 | } | 162 | } |
164 | } | 163 | } |
165 | 164 | ||
166 | void reconnect_service(android::base::unique_fd fd, atransport* t) { | 165 | void reconnect_service(unique_fd fd, atransport* t) { |
167 | WriteFdExactly(fd, "done"); | 166 | WriteFdExactly(fd, "done"); |
168 | kick_transport(t); | 167 | kick_transport(t); |
169 | } | 168 | } |
@@ -223,12 +222,11 @@ int ShellService(const std::string& args, const atransport* transport) { | |||
223 | 222 | ||
224 | #endif // !ADB_HOST | 223 | #endif // !ADB_HOST |
225 | 224 | ||
226 | android::base::unique_fd create_service_thread(const char* service_name, | 225 | unique_fd create_service_thread(const char* service_name, std::function<void(unique_fd)> func) { |
227 | std::function<void(android::base::unique_fd)> func) { | ||
228 | int s[2]; | 226 | int s[2]; |
229 | if (adb_socketpair(s)) { | 227 | if (adb_socketpair(s)) { |
230 | printf("cannot create service socket pair\n"); | 228 | printf("cannot create service socket pair\n"); |
231 | return android::base::unique_fd(); | 229 | return unique_fd(); |
232 | } | 230 | } |
233 | D("socketpair: (%d,%d)", s[0], s[1]); | 231 | D("socketpair: (%d,%d)", s[0], s[1]); |
234 | 232 | ||
@@ -241,10 +239,10 @@ android::base::unique_fd create_service_thread(const char* service_name, | |||
241 | } | 239 | } |
242 | #endif // !ADB_HOST | 240 | #endif // !ADB_HOST |
243 | 241 | ||
244 | std::thread(service_bootstrap_func, service_name, func, android::base::unique_fd(s[1])).detach(); | 242 | std::thread(service_bootstrap_func, service_name, func, unique_fd(s[1])).detach(); |
245 | 243 | ||
246 | D("service thread started, %d:%d",s[0], s[1]); | 244 | D("service thread started, %d:%d",s[0], s[1]); |
247 | return android::base::unique_fd(s[0]); | 245 | return unique_fd(s[0]); |
248 | } | 246 | } |
249 | 247 | ||
250 | } // namespace | 248 | } // namespace |
@@ -407,7 +405,7 @@ void connect_emulator(const std::string& port_spec, std::string* response) { | |||
407 | } | 405 | } |
408 | } | 406 | } |
409 | 407 | ||
410 | static void connect_service(android::base::unique_fd fd, std::string host) { | 408 | static void connect_service(unique_fd fd, std::string host) { |
411 | std::string response; | 409 | std::string response; |
412 | if (!strncmp(host.c_str(), "emu:", 4)) { | 410 | if (!strncmp(host.c_str(), "emu:", 4)) { |
413 | connect_emulator(host.c_str() + 4, &response); | 411 | connect_emulator(host.c_str() + 4, &response); |