From 04398a9b23a688102ec4a295d94b39b2f6b187b6 Mon Sep 17 00:00:00 2001 From: Artem Iglikov Date: Sun, 17 Dec 2017 10:56:07 +0000 Subject: [PATCH] Sort devices list before output. Makes copy of the transport list and sorts it by type and serial before printing. Bug: 70748433 Test: adb devices displays all connected devices Change-Id: I917728a102972f2f38f2e370a0c6011c1eb883c7 --- adb/transport.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/adb/transport.cpp b/adb/transport.cpp index 5cf2450a6..f2217859c 100644 --- a/adb/transport.cpp +++ b/adb/transport.cpp @@ -952,10 +952,18 @@ static void append_transport(const atransport* t, std::string* result, bool long } std::string list_transports(bool long_listing) { - std::string result; - std::lock_guard lock(transport_lock); - for (const auto& t : transport_list) { + + auto sorted_transport_list = transport_list; + sorted_transport_list.sort([](atransport*& x, atransport*& y) { + if (x->type != y->type) { + return x->type < y->type; + } + return strcmp(x->serial, y->serial) < 0; + }); + + std::string result; + for (const auto& t : sorted_transport_list) { append_transport(t, &result, long_listing); } return result;