summaryrefslogtreecommitdiffstats
path: root/adbconnection/adbconnection.cc
diff options
context:
space:
mode:
authorAlex Light <allight@google.com>2021-02-01 19:25:35 -0800
committerAlex Light <allight@google.com>2021-02-03 17:54:23 +0000
commitf51d182c3d797bd14bcc66a3c0bf1fc6f9adf8ee (patch)
tree12921f3bfd788a0dc2a8b5937ebf0ed13af220e5 /adbconnection/adbconnection.cc
parent3098e36d2935ad7ce9995ef5fb7395d035383047 (diff)
downloadplatform_art-f51d182c3d797bd14bcc66a3c0bf1fc6f9adf8ee.tar.gz
platform_art-f51d182c3d797bd14bcc66a3c0bf1fc6f9adf8ee.tar.bz2
platform_art-f51d182c3d797bd14bcc66a3c0bf1fc6f9adf8ee.zip
Fix DDMS-JDWP race
DDMS would race against the JDWP-Handshake in some circumstances causing clients to become confused as DDMS packets were recieved before the handshake reply. Test: atest CtsJdwpTunnelHostTestCases Test: ./tools/dt_fds_forward.py Bug: 178655046 Change-Id: Iabeb68829455ee4d2682f0a14591c8b7b0f4fc5f
Diffstat (limited to 'adbconnection/adbconnection.cc')
-rw-r--r--adbconnection/adbconnection.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/adbconnection/adbconnection.cc b/adbconnection/adbconnection.cc
index ced2252d090..cca4485cdde 100644
--- a/adbconnection/adbconnection.cc
+++ b/adbconnection/adbconnection.cc
@@ -24,6 +24,7 @@
#include "android-base/endian.h"
#include "android-base/stringprintf.h"
#include "base/file_utils.h"
+#include "base/globals.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/mutex.h"
@@ -61,6 +62,7 @@ using dt_fd_forward::kListenStartMessage;
using dt_fd_forward::kListenEndMessage;
using dt_fd_forward::kAcceptMessage;
using dt_fd_forward::kCloseMessage;
+using dt_fd_forward::kHandshakeCompleteMessage;
// Messages sent to the transport
using dt_fd_forward::kPerformHandshakeMessage;
@@ -344,7 +346,7 @@ void AdbConnectionState::SendDdmPacket(uint32_t id,
art::ArrayRef<const uint8_t> data) {
// Get the write_event early to fail fast.
ScopedEventFdLock lk(adb_write_event_fd_);
- if (adb_connection_socket_ == -1) {
+ if (adb_connection_socket_ == -1 || !performed_handshake_) {
VLOG(jdwp) << "Not sending ddms data of type "
<< StringPrintf("%c%c%c%c",
static_cast<char>(type >> 24),
@@ -580,6 +582,10 @@ void AdbConnectionState::RunPollLoop(art::Thread* self) {
}
} else if (memcmp(kListenEndMessage, buf, sizeof(kListenEndMessage)) == 0) {
agent_listening_ = false;
+ } else if (memcmp(kHandshakeCompleteMessage, buf, sizeof(kHandshakeCompleteMessage)) == 0) {
+ if (agent_has_socket_) {
+ performed_handshake_ = true;
+ }
} else if (memcmp(kCloseMessage, buf, sizeof(kCloseMessage)) == 0) {
CloseFds();
agent_has_socket_ = false;