[adb client] Add "adb mdns check" command.
This command will check if the mdns daemon is available on the host
machine.
Bug: 152510294
Test: pkill -9 mdnsd; adb mdns check; mdnsd; adb mdns check;
Test: test_adb.py
Change-Id: If644678a339763817a8a7adcbdc545626d161aba
diff --git a/adb/adb.cpp b/adb/adb.cpp
index 06fdb69..aced079 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -1076,6 +1076,20 @@
g_reject_kill_server = value;
}
+static bool handle_mdns_request(std::string_view service, int reply_fd) {
+ if (!android::base::ConsumePrefix(&service, "mdns:")) {
+ return false;
+ }
+
+ if (service == "check") {
+ std::string check = mdns_check();
+ SendOkay(reply_fd, check);
+ return true;
+ }
+
+ return false;
+}
+
HostRequestResult handle_host_request(std::string_view service, TransportType type,
const char* serial, TransportId transport_id, int reply_fd,
asocket* s) {
@@ -1320,6 +1334,10 @@
return HostRequestResult::Handled;
}
+ if (handle_mdns_request(service, reply_fd)) {
+ return HostRequestResult::Handled;
+ }
+
return HostRequestResult::Unhandled;
}