Refactor should_use_libusb
The function used to be called before libusb was setup.
Now is it a prompt for the state of the USB backend.
Test: NA
Bug: NA
Change-Id: Ib9be4ddb0282c9101c0362684d27b676047813eb
diff --git a/adb.cpp b/adb.cpp
index ab4e6c4..54d1854 100644
--- a/adb.cpp
+++ b/adb.cpp
@@ -1327,7 +1327,7 @@
if (service == "server-status") {
adb::proto::AdbServerStatus status;
- if (should_use_libusb()) {
+ if (is_libusb_enabled()) {
status.set_usb_backend(adb::proto::AdbServerStatus::LIBUSB);
} else {
status.set_usb_backend(adb::proto::AdbServerStatus::NATIVE);
@@ -1400,7 +1400,7 @@
if (service == "host-features") {
FeatureSet features = supported_features();
// Abuse features to report libusb status.
- if (should_use_libusb()) {
+ if (is_libusb_enabled()) {
features.emplace_back(kFeatureLibusb);
}
features.emplace_back(kFeaturePushSync);
diff --git a/client/main.cpp b/client/main.cpp
index 818d305..1530828 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -137,7 +137,7 @@
}
if (!getenv("ADB_USB") || strcmp(getenv("ADB_USB"), "0") != 0) {
- if (should_use_libusb()) {
+ if (is_libusb_enabled()) {
libusb::usb_init();
} else {
usb_init();
diff --git a/client/transport_usb.cpp b/client/transport_usb.cpp
index 998f73c..58d5025 100644
--- a/client/transport_usb.cpp
+++ b/client/transport_usb.cpp
@@ -177,7 +177,7 @@
return false;
}
-bool should_use_libusb() {
+bool is_libusb_enabled() {
bool enable = true;
#if defined(_WIN32)
enable = false;
diff --git a/client/usb.h b/client/usb.h
index 0ccc057..b12e7c6 100644
--- a/client/usb.h
+++ b/client/usb.h
@@ -37,7 +37,7 @@
// USB device detection.
bool is_adb_interface(int usb_class, int usb_subclass, int usb_protocol);
-bool should_use_libusb();
+bool is_libusb_enabled();
namespace libusb {
void usb_init();
diff --git a/client/usb_linux.cpp b/client/usb_linux.cpp
index 77f5a2e..96d7a8a 100644
--- a/client/usb_linux.cpp
+++ b/client/usb_linux.cpp
@@ -643,7 +643,7 @@
}
void usb_cleanup() {
- if (should_use_libusb()) {
+ if (is_libusb_enabled()) {
VLOG(USB) << "Linux libusb cleanup";
close_usb_devices();
}
diff --git a/client/usb_windows.cpp b/client/usb_windows.cpp
index 453c23b..b17c480 100644
--- a/client/usb_windows.cpp
+++ b/client/usb_windows.cpp
@@ -256,7 +256,7 @@
void usb_cleanup() {
// On Windows, shutting down the server without releasing USB interfaces makes claiming
// them again unstable upon next startup.
- if (should_use_libusb()) {
+ if (is_libusb_enabled()) {
VLOG(USB) << "Windows libusb cleanup";
close_usb_devices();
}
diff --git a/transport.cpp b/transport.cpp
index dfd6992..b99e8bc 100644
--- a/transport.cpp
+++ b/transport.cpp
@@ -732,7 +732,7 @@
static bool usb_devices_start_detached() {
static const char* env = getenv("ADB_LIBUSB_START_DETACHED");
static bool result = env && strcmp("1", env) == 0;
- return should_use_libusb() && result;
+ return is_libusb_enabled() && result;
}
#endif
@@ -1077,7 +1077,7 @@
D("%s: attach", serial.c_str());
fdevent_check_looper();
- if (!should_use_libusb()) {
+ if (!is_libusb_enabled()) {
*error = "attach/detach only implemented for libusb backend";
return false;
}
@@ -1104,7 +1104,7 @@
D("%s: detach", serial.c_str());
fdevent_check_looper();
- if (!should_use_libusb()) {
+ if (!is_libusb_enabled()) {
*error = "attach/detach only implemented for libusb backend";
return false;
}