adb: Prevent registering usb_disconnect twice
adbd can receive multiple AUTH_RSAPUBLICKEY packets. This happens for
example when booting with usb attached when we retry authenticating
after the framework is done booting. Make sure usb_disconnect is only
registered once, otherwise this creates a loop in the disconnects list.
Bug: 8504991
Change-Id: Ia1f9a37005dd17b7eefee1493d622e1679263eea
diff --git a/adb/adb_auth_client.c b/adb/adb_auth_client.c
index efc49eb..763b448 100644
--- a/adb/adb_auth_client.c
+++ b/adb/adb_auth_client.c
@@ -161,7 +161,7 @@
static void usb_disconnected(void* unused, atransport* t)
{
- D("USB disconnect");
+ D("USB disconnect\n");
remove_transport_disconnect(usb_transport, &usb_disconnect);
usb_transport = NULL;
needs_retry = false;
@@ -175,7 +175,7 @@
if (events & FDE_READ) {
ret = unix_read(fd, response, sizeof(response));
if (ret < 0) {
- D("Framework disconnect");
+ D("Framework disconnect\n");
if (usb_transport)
fdevent_remove(&usb_transport->auth_fde);
framework_fd = -1;
@@ -192,8 +192,10 @@
char msg[MAX_PAYLOAD];
int ret;
- usb_transport = t;
- add_transport_disconnect(t, &usb_disconnect);
+ if (!usb_transport) {
+ usb_transport = t;
+ add_transport_disconnect(t, &usb_disconnect);
+ }
if (framework_fd < 0) {
D("Client not connected\n");