adb: add track-devices-l service.

Add a way to get the full `devices -l` output on a continuous basis.

Test: manual
Change-Id: I2270cc0a0d7e1384ce19631724ddf2462d963ade
This commit is contained in:
Josh Gao 2017-08-14 18:57:54 -07:00
parent b122b17555
commit b0c1802615
3 changed files with 12 additions and 8 deletions

View file

@ -441,7 +441,9 @@ static void connect_service(int fd, void* data) {
#if ADB_HOST
asocket* host_service_to_socket(const char* name, const char* serial, TransportId transport_id) {
if (!strcmp(name,"track-devices")) {
return create_device_tracker();
return create_device_tracker(false);
} else if (!strcmp(name, "track-devices-l")) {
return create_device_tracker(true);
} else if (android::base::StartsWith(name, "wait-for-")) {
name += strlen("wait-for-");

View file

@ -329,7 +329,8 @@ static fdevent transport_registration_fde;
*/
struct device_tracker {
asocket socket;
int update_needed;
bool update_needed;
bool long_output;
device_tracker* next;
};
@ -386,15 +387,15 @@ static void device_tracker_ready(asocket* socket) {
// We want to send the device list when the tracker connects
// for the first time, even if no update occurred.
if (tracker->update_needed > 0) {
tracker->update_needed = 0;
if (tracker->update_needed) {
tracker->update_needed = false;
std::string transports = list_transports(false);
std::string transports = list_transports(tracker->long_output);
device_tracker_send(tracker, transports);
}
}
asocket* create_device_tracker(void) {
asocket* create_device_tracker(bool long_output) {
device_tracker* tracker = reinterpret_cast<device_tracker*>(calloc(1, sizeof(*tracker)));
if (tracker == nullptr) fatal("cannot allocate device tracker");
@ -403,7 +404,8 @@ asocket* create_device_tracker(void) {
tracker->socket.enqueue = device_tracker_enqueue;
tracker->socket.ready = device_tracker_ready;
tracker->socket.close = device_tracker_close;
tracker->update_needed = 1;
tracker->update_needed = true;
tracker->long_output = long_output;
tracker->next = device_tracker_list;
device_tracker_list = tracker;

View file

@ -233,6 +233,6 @@ void close_usb_devices(std::function<bool(const atransport*)> predicate);
void send_packet(apacket* p, atransport* t);
asocket* create_device_tracker(void);
asocket* create_device_tracker(bool long_output);
#endif /* __TRANSPORT_H */