diff options
Diffstat (limited to 'adb/transport_local.cpp')
-rw-r--r-- | adb/transport_local.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
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 | ||
435 | std::string getEmulatorSerialString(int console_port) | ||
436 | { | ||
437 | return android::base::StringPrintf("emulator-%d", console_port); | ||
438 | } | ||
439 | |||
434 | atransport* find_emulator_transport_by_adb_port(int adb_port) | 440 | atransport* 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 | ||
447 | atransport* 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. */ |
442 | int get_available_local_transport_index_locked() | 454 | int get_available_local_transport_index_locked() |
443 | { | 455 | { |