Remove confusing variable HOST.
First, HOST is always 0 in adbd, which matches ADB_HOST=0.
Second, HOST is always 1 when adb_main is called, which matches ADB_HOST=1.
For adb client that doesn't call adb_main, it never touches local_init(),
init_transport_registration() and fdevent_loop(). So the changes in adb.cpp,
services.cpp and transport_local.cpp do nothing with it.
As a conclusion, I think we can remove HOST and use ADB_HOST instead.
Change-Id: Ide0e0eca7468b6c3c130f6b50974406280678b2e
diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp
index 650e5ea..6a17497 100644
--- a/adb/transport_local.cpp
+++ b/adb/transport_local.cpp
@@ -120,10 +120,9 @@
return -1;
}
-
+#if ADB_HOST
static void *client_socket_thread(void *x)
{
-#if ADB_HOST
D("transport: client_socket_thread() starting\n");
while (true) {
int port = DEFAULT_ADB_LOCAL_TRANSPORT_PORT;
@@ -135,10 +134,11 @@
}
sleep(1);
}
-#endif
return 0;
}
+#else // ADB_HOST
+
static void *server_socket_thread(void * arg)
{
int serverfd, fd;
@@ -175,7 +175,6 @@
}
/* This is relevant only for ADB daemon running inside the emulator. */
-#if !ADB_HOST
/*
* Redefine open and write for qemu_pipe.h that contains inlined references
* to those routines. We will redifine them back after qemu_pipe.h inclusion.
@@ -287,31 +286,29 @@
void local_init(int port)
{
void* (*func)(void *);
+ const char* debug_name = "";
- if(HOST) {
- func = client_socket_thread;
- } else {
#if ADB_HOST
- func = server_socket_thread;
+ func = client_socket_thread;
+ debug_name = "client";
#else
- /* For the adbd daemon in the system image we need to distinguish
- * between the device, and the emulator. */
- char is_qemu[PROPERTY_VALUE_MAX];
- property_get("ro.kernel.qemu", is_qemu, "");
- if (!strcmp(is_qemu, "1")) {
- /* Running inside the emulator: use QEMUD pipe as the transport. */
- func = qemu_socket_thread;
- } else {
- /* Running inside the device: use TCP socket as the transport. */
- func = server_socket_thread;
- }
-#endif // !ADB_HOST
+ /* For the adbd daemon in the system image we need to distinguish
+ * between the device, and the emulator. */
+ char is_qemu[PROPERTY_VALUE_MAX];
+ property_get("ro.kernel.qemu", is_qemu, "");
+ if (!strcmp(is_qemu, "1")) {
+ /* Running inside the emulator: use QEMUD pipe as the transport. */
+ func = qemu_socket_thread;
+ } else {
+ /* Running inside the device: use TCP socket as the transport. */
+ func = server_socket_thread;
}
+ debug_name = "server";
+#endif // !ADB_HOST
- D("transport: local %s init\n", HOST ? "client" : "server");
-
+ D("transport: local %s init\n", debug_name);
if (!adb_thread_create(func, (void *) (uintptr_t) port)) {
- fatal_errno("cannot create local socket %s thread", HOST ? "client" : "server");
+ fatal_errno("cannot create local socket %s thread", debug_name);
}
}
@@ -323,17 +320,15 @@
adb_close(fd);
#if ADB_HOST
- if(HOST) {
- int nn;
- adb_mutex_lock( &local_transports_lock );
- for (nn = 0; nn < ADB_LOCAL_TRANSPORT_MAX; nn++) {
- if (local_transports[nn] == t) {
- local_transports[nn] = NULL;
- break;
- }
+ int nn;
+ adb_mutex_lock( &local_transports_lock );
+ for (nn = 0; nn < ADB_LOCAL_TRANSPORT_MAX; nn++) {
+ if (local_transports[nn] == t) {
+ local_transports[nn] = NULL;
+ break;
}
- adb_mutex_unlock( &local_transports_lock );
}
+ adb_mutex_unlock( &local_transports_lock );
#endif
}
@@ -404,7 +399,7 @@
t->adb_port = 0;
#if ADB_HOST
- if (HOST && local) {
+ if (local) {
adb_mutex_lock( &local_transports_lock );
{
t->adb_port = adb_port;