adb: remove incorrect use of RTTI.
We were dynamic_casting to UsbConnection to check for USB connections,
but the actual type was a BlockingConnectionAdapter wrapping a
UsbConnection, with the result that unplugging an inaccessible (due to
permissions) device on Linux wouldn't make the device go away.
Test: manual
Change-Id: Icb4acea5fd3c3baa9691698686213e122e898e4a
diff --git a/adb/Android.bp b/adb/Android.bp
index ae8e386..fd68bc3 100644
--- a/adb/Android.bp
+++ b/adb/Android.bp
@@ -24,7 +24,6 @@
"-Wno-missing-field-initializers",
"-Wvla",
],
- rtti: true,
use_version_lib: true,
diff --git a/adb/transport.cpp b/adb/transport.cpp
index 8741654..f59a135 100644
--- a/adb/transport.cpp
+++ b/adb/transport.cpp
@@ -1305,11 +1305,7 @@
void unregister_usb_transport(usb_handle* usb) {
std::lock_guard<std::recursive_mutex> lock(transport_lock);
transport_list.remove_if([usb](atransport* t) {
- auto connection = t->connection();
- if (auto usb_connection = dynamic_cast<UsbConnection*>(connection.get())) {
- return usb_connection->handle_ == usb && t->GetConnectionState() == kCsNoPerm;
- }
- return false;
+ return t->GetUsbHandle() == usb && t->GetConnectionState() == kCsNoPerm;
});
}
#endif
diff --git a/adb/transport.h b/adb/transport.h
index d593700..790004f 100644
--- a/adb/transport.h
+++ b/adb/transport.h
@@ -37,6 +37,7 @@
#include "adb.h"
#include "adb_unique_fd.h"
+#include "usb.h"
typedef std::unordered_set<std::string> FeatureSet;
@@ -242,6 +243,9 @@
return connection_;
}
+ void SetUsbHandle(usb_handle* h) { usb_handle_ = h; }
+ usb_handle* GetUsbHandle() { return usb_handle_; }
+
const TransportId id;
size_t ref_count = 0;
bool online = false;
@@ -333,6 +337,9 @@
// The underlying connection object.
std::shared_ptr<Connection> connection_ GUARDED_BY(mutex_);
+ // USB handle for the connection, if available.
+ usb_handle* usb_handle_ = nullptr;
+
// A callback that will be invoked when the atransport needs to reconnect.
ReconnectCallback reconnect_;
diff --git a/adb/transport_usb.cpp b/adb/transport_usb.cpp
index c471bf9..2e5918a 100644
--- a/adb/transport_usb.cpp
+++ b/adb/transport_usb.cpp
@@ -180,6 +180,7 @@
auto connection = std::make_unique<UsbConnection>(h);
t->SetConnection(std::make_unique<BlockingConnectionAdapter>(std::move(connection)));
t->type = kTransportUsb;
+ t->SetUsbHandle(h);
}
int is_adb_interface(int usb_class, int usb_subclass, int usb_protocol) {