Loading adb/adb.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -1198,9 +1198,9 @@ HostRequestResult handle_host_request(std::string_view service, TransportType ty FeatureSet features = supported_features(); // Abuse features to report libusb status. if (should_use_libusb()) { features.insert(kFeatureLibusb); features.emplace_back(kFeatureLibusb); } features.insert(kFeaturePushSync); features.emplace_back(kFeaturePushSync); SendOkay(reply_fd, FeatureSetToString(features)); return HostRequestResult::Handled; } Loading adb/client/adb_client.cpp +9 −12 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ #include <vector> #include <android-base/file.h> #include <android-base/no_destructor.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <android-base/thread_annotations.h> Loading Loading @@ -415,18 +416,14 @@ std::string format_host_command(const char* command) { return android::base::StringPrintf("%s:%s", prefix, command); } bool adb_get_feature_set(FeatureSet* feature_set, std::string* error) { static FeatureSet* features = nullptr; if (!features) { const FeatureSet& adb_get_feature_set() { static const android::base::NoDestructor<FeatureSet> features([] { std::string result; if (adb_query(format_host_command("features"), &result, error)) { features = new FeatureSet(StringToFeatureSet(result)); if (!adb_query(format_host_command("features"), &result, &result)) { fprintf(stderr, "failed to get feature set: %s\n", result.c_str()); return FeatureSet{}; } } if (features) { *feature_set = *features; return true; } feature_set->clear(); return false; return StringToFeatureSet(result); }()); return *features; } adb/client/adb_client.h +1 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ bool adb_status(borrowed_fd fd, std::string* _Nonnull error); std::string format_host_command(const char* _Nonnull command); // Get the feature set of the current preferred transport. bool adb_get_feature_set(FeatureSet* _Nonnull feature_set, std::string* _Nonnull error); const FeatureSet& adb_get_feature_set(); #if defined(__linux__) // Get the path of a file containing the path to the server executable, if the socket spec set via Loading adb/client/adb_install.cpp +2 −4 Original line number Diff line number Diff line Loading @@ -57,10 +57,8 @@ enum class CmdlineOption { None, Enable, Disable }; } static bool can_use_feature(const char* feature) { FeatureSet features; std::string error; if (!adb_get_feature_set(&features, &error)) { fprintf(stderr, "error: %s\n", error.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return false; } return CanUseFeature(features, feature); Loading adb/client/commandline.cpp +12 −24 Original line number Diff line number Diff line Loading @@ -672,10 +672,8 @@ static int RemoteShell(bool use_shell_protocol, const std::string& type_arg, cha } static int adb_shell(int argc, const char** argv) { FeatureSet features; std::string error_message; if (!adb_get_feature_set(&features, &error_message)) { fprintf(stderr, "error: %s\n", error_message.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return 1; } Loading Loading @@ -779,13 +777,10 @@ static int adb_shell(int argc, const char** argv) { } static int adb_abb(int argc, const char** argv) { FeatureSet features; std::string error_message; if (!adb_get_feature_set(&features, &error_message)) { fprintf(stderr, "error: %s\n", error_message.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return 1; } if (!CanUseFeature(features, kFeatureAbb)) { error_exit("abb is not supported by the device"); } Loading Loading @@ -1164,9 +1159,8 @@ int send_shell_command(const std::string& command, bool disable_shell_protocol, // Use shell protocol if it's supported and the caller doesn't explicitly // disable it. if (!disable_shell_protocol) { FeatureSet features; std::string error; if (adb_get_feature_set(&features, &error)) { auto&& features = adb_get_feature_set(); if (!features.empty()) { use_shell_protocol = CanUseFeature(features, kFeatureShell2); } else { // Device was unreachable. Loading Loading @@ -1816,10 +1810,8 @@ int adb_commandline(int argc, const char** argv) { } return adb_connect_command(android::base::StringPrintf("tcpip:%d", port)); } else if (!strcmp(argv[0], "remount")) { FeatureSet features; std::string error; if (!adb_get_feature_set(&features, &error)) { fprintf(stderr, "error: %s\n", error.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return 1; } Loading Loading @@ -2042,10 +2034,8 @@ int adb_commandline(int argc, const char** argv) { } else if (!strcmp(argv[0], "track-jdwp")) { return adb_connect_command("track-jdwp"); } else if (!strcmp(argv[0], "track-app")) { FeatureSet features; std::string error; if (!adb_get_feature_set(&features, &error)) { fprintf(stderr, "error: %s\n", error.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return 1; } if (!CanUseFeature(features, kFeatureTrackApp)) { Loading Loading @@ -2074,10 +2064,8 @@ int adb_commandline(int argc, const char** argv) { return 0; } else if (!strcmp(argv[0], "features")) { // Only list the features common to both the adb client and the device. FeatureSet features; std::string error; if (!adb_get_feature_set(&features, &error)) { fprintf(stderr, "error: %s\n", error.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return 1; } Loading Loading
adb/adb.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -1198,9 +1198,9 @@ HostRequestResult handle_host_request(std::string_view service, TransportType ty FeatureSet features = supported_features(); // Abuse features to report libusb status. if (should_use_libusb()) { features.insert(kFeatureLibusb); features.emplace_back(kFeatureLibusb); } features.insert(kFeaturePushSync); features.emplace_back(kFeaturePushSync); SendOkay(reply_fd, FeatureSetToString(features)); return HostRequestResult::Handled; } Loading
adb/client/adb_client.cpp +9 −12 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ #include <vector> #include <android-base/file.h> #include <android-base/no_destructor.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <android-base/thread_annotations.h> Loading Loading @@ -415,18 +416,14 @@ std::string format_host_command(const char* command) { return android::base::StringPrintf("%s:%s", prefix, command); } bool adb_get_feature_set(FeatureSet* feature_set, std::string* error) { static FeatureSet* features = nullptr; if (!features) { const FeatureSet& adb_get_feature_set() { static const android::base::NoDestructor<FeatureSet> features([] { std::string result; if (adb_query(format_host_command("features"), &result, error)) { features = new FeatureSet(StringToFeatureSet(result)); if (!adb_query(format_host_command("features"), &result, &result)) { fprintf(stderr, "failed to get feature set: %s\n", result.c_str()); return FeatureSet{}; } } if (features) { *feature_set = *features; return true; } feature_set->clear(); return false; return StringToFeatureSet(result); }()); return *features; }
adb/client/adb_client.h +1 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ bool adb_status(borrowed_fd fd, std::string* _Nonnull error); std::string format_host_command(const char* _Nonnull command); // Get the feature set of the current preferred transport. bool adb_get_feature_set(FeatureSet* _Nonnull feature_set, std::string* _Nonnull error); const FeatureSet& adb_get_feature_set(); #if defined(__linux__) // Get the path of a file containing the path to the server executable, if the socket spec set via Loading
adb/client/adb_install.cpp +2 −4 Original line number Diff line number Diff line Loading @@ -57,10 +57,8 @@ enum class CmdlineOption { None, Enable, Disable }; } static bool can_use_feature(const char* feature) { FeatureSet features; std::string error; if (!adb_get_feature_set(&features, &error)) { fprintf(stderr, "error: %s\n", error.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return false; } return CanUseFeature(features, feature); Loading
adb/client/commandline.cpp +12 −24 Original line number Diff line number Diff line Loading @@ -672,10 +672,8 @@ static int RemoteShell(bool use_shell_protocol, const std::string& type_arg, cha } static int adb_shell(int argc, const char** argv) { FeatureSet features; std::string error_message; if (!adb_get_feature_set(&features, &error_message)) { fprintf(stderr, "error: %s\n", error_message.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return 1; } Loading Loading @@ -779,13 +777,10 @@ static int adb_shell(int argc, const char** argv) { } static int adb_abb(int argc, const char** argv) { FeatureSet features; std::string error_message; if (!adb_get_feature_set(&features, &error_message)) { fprintf(stderr, "error: %s\n", error_message.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return 1; } if (!CanUseFeature(features, kFeatureAbb)) { error_exit("abb is not supported by the device"); } Loading Loading @@ -1164,9 +1159,8 @@ int send_shell_command(const std::string& command, bool disable_shell_protocol, // Use shell protocol if it's supported and the caller doesn't explicitly // disable it. if (!disable_shell_protocol) { FeatureSet features; std::string error; if (adb_get_feature_set(&features, &error)) { auto&& features = adb_get_feature_set(); if (!features.empty()) { use_shell_protocol = CanUseFeature(features, kFeatureShell2); } else { // Device was unreachable. Loading Loading @@ -1816,10 +1810,8 @@ int adb_commandline(int argc, const char** argv) { } return adb_connect_command(android::base::StringPrintf("tcpip:%d", port)); } else if (!strcmp(argv[0], "remount")) { FeatureSet features; std::string error; if (!adb_get_feature_set(&features, &error)) { fprintf(stderr, "error: %s\n", error.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return 1; } Loading Loading @@ -2042,10 +2034,8 @@ int adb_commandline(int argc, const char** argv) { } else if (!strcmp(argv[0], "track-jdwp")) { return adb_connect_command("track-jdwp"); } else if (!strcmp(argv[0], "track-app")) { FeatureSet features; std::string error; if (!adb_get_feature_set(&features, &error)) { fprintf(stderr, "error: %s\n", error.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return 1; } if (!CanUseFeature(features, kFeatureTrackApp)) { Loading Loading @@ -2074,10 +2064,8 @@ int adb_commandline(int argc, const char** argv) { return 0; } else if (!strcmp(argv[0], "features")) { // Only list the features common to both the adb client and the device. FeatureSet features; std::string error; if (!adb_get_feature_set(&features, &error)) { fprintf(stderr, "error: %s\n", error.c_str()); auto&& features = adb_get_feature_set(); if (features.empty()) { return 1; } Loading