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
This commit is contained in:
Josh Gao 2018-07-25 16:51:59 -07:00
parent 2deb787ee2
commit 73a5ee4df5
9 changed files with 33 additions and 44 deletions

View file

@ -527,7 +527,7 @@ static bool handle_sync_command(int fd, std::vector<char>& buffer) {
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)) {

View file

@ -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);

View file

@ -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];

View file

@ -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);

View file

@ -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;

View file

@ -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&);

View file

@ -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

View file

@ -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);

View file

@ -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 @@ 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<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 @@ 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);