summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2016-10-11 19:25:10 -0500
committerGerrit Code Review2016-10-11 19:25:11 -0500
commitf7a1c476ff33d38d4653cc0a11865f70299296ef (patch)
tree60fab55db935ab82718bb12a14f4086c216b8dce
parentbd6c6eb0e46794873a77a5bdf07e2abd3f6b1664 (diff)
parent1197952e71cffe5fab91625e49670083ead78712 (diff)
downloadplatform-system-core-f7a1c476ff33d38d4653cc0a11865f70299296ef.tar.gz
platform-system-core-f7a1c476ff33d38d4653cc0a11865f70299296ef.tar.xz
platform-system-core-f7a1c476ff33d38d4653cc0a11865f70299296ef.zip
Merge "Fix adb flakiness on reboot"
-rw-r--r--adb/adb.h2
-rw-r--r--adb/transport_local.cpp16
2 files changed, 16 insertions, 2 deletions
diff --git a/adb/adb.h b/adb/adb.h
index 2797f6b54..df59aaaa9 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -139,8 +139,10 @@ int get_available_local_transport_index();
139int init_socket_transport(atransport *t, int s, int port, int local); 139int init_socket_transport(atransport *t, int s, int port, int local);
140void init_usb_transport(atransport *t, usb_handle *usb, ConnectionState state); 140void init_usb_transport(atransport *t, usb_handle *usb, ConnectionState state);
141 141
142std::string getEmulatorSerialString(int console_port);
142#if ADB_HOST 143#if ADB_HOST
143atransport* find_emulator_transport_by_adb_port(int adb_port); 144atransport* find_emulator_transport_by_adb_port(int adb_port);
145atransport* find_emulator_transport_by_console_port(int console_port);
144#endif 146#endif
145 147
146int service_to_fd(const char* name, const atransport* transport); 148int service_to_fd(const char* name, const atransport* transport);
diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp
index a94b41efa..ea2bf7747 100644
--- a/adb/transport_local.cpp
+++ b/adb/transport_local.cpp
@@ -103,7 +103,8 @@ int local_connect_arbitrary_ports(int console_port, int adb_port, std::string* e
103 int fd = -1; 103 int fd = -1;
104 104
105#if ADB_HOST 105#if ADB_HOST
106 if (find_emulator_transport_by_adb_port(adb_port) != nullptr) { 106 if (find_emulator_transport_by_adb_port(adb_port) != nullptr ||
107 find_emulator_transport_by_console_port(console_port) != nullptr) {
107 return -1; 108 return -1;
108 } 109 }
109 110
@@ -120,7 +121,7 @@ int local_connect_arbitrary_ports(int console_port, int adb_port, std::string* e
120 D("client: connected on remote on fd %d", fd); 121 D("client: connected on remote on fd %d", fd);
121 close_on_exec(fd); 122 close_on_exec(fd);
122 disable_tcp_nagle(fd); 123 disable_tcp_nagle(fd);
123 std::string serial = android::base::StringPrintf("emulator-%d", console_port); 124 std::string serial = getEmulatorSerialString(console_port);
124 if (register_socket_transport(fd, serial.c_str(), adb_port, 1) == 0) { 125 if (register_socket_transport(fd, serial.c_str(), adb_port, 1) == 0) {
125 return 0; 126 return 0;
126 } 127 }
@@ -431,6 +432,11 @@ static atransport* find_emulator_transport_by_adb_port_locked(int adb_port)
431 return NULL; 432 return NULL;
432} 433}
433 434
435std::string getEmulatorSerialString(int console_port)
436{
437 return android::base::StringPrintf("emulator-%d", console_port);
438}
439
434atransport* find_emulator_transport_by_adb_port(int adb_port) 440atransport* find_emulator_transport_by_adb_port(int adb_port)
435{ 441{
436 std::lock_guard<std::mutex> lock(local_transports_lock); 442 std::lock_guard<std::mutex> lock(local_transports_lock);
@@ -438,6 +444,12 @@ atransport* find_emulator_transport_by_adb_port(int adb_port)
438 return result; 444 return result;
439} 445}
440 446
447atransport* find_emulator_transport_by_console_port(int console_port)
448{
449 return find_transport(getEmulatorSerialString(console_port).c_str());
450}
451
452
441/* Only call this function if you already hold local_transports_lock. */ 453/* Only call this function if you already hold local_transports_lock. */
442int get_available_local_transport_index_locked() 454int get_available_local_transport_index_locked()
443{ 455{