Fix WiFiLan discovery failure problem

PiperOrigin-RevId: 426014146
This commit is contained in:
hai007
2022-02-02 17:10:26 -08:00
committed by Copybara-Service
parent f5fcd35ced
commit b66e7aa6d8
2 changed files with 26 additions and 2 deletions
@@ -263,7 +263,7 @@ class WifiLanMedium : public api::WifiLanMedium {
static constexpr std::string_view MDNS_DEVICE_SELECTOR_FORMAT =
"System.Devices.AepService.ProtocolId:=\"{4526e8c1-8aac-4153-9b16-"
"55e86ada0e54}\" "
"AND System.Devices.Dnssd.ServiceName:=\"%s._tcp\" AND "
"AND System.Devices.Dnssd.ServiceName:=\"%s\" AND "
"System.Devices.Dnssd.Domain:=\"local\"";
// Nsd status
@@ -194,8 +194,17 @@ bool WifiLanMedium::StartDiscovery(const std::string& service_type,
return false;
}
// In WifiLan::StartDiscovery(), service_type is appended with "._tcp." for
// ios and android platform. For windows, this has to be removed because
// "._tcp" will be appended in following "selector"
std::string service_type_trim = service_type;
if (service_type.size() > 5 &&
(service_type.rfind("_tcp.") == service_type.size() - 5)) {
service_type_trim.resize(service_type_trim.size() - 1);
}
std::string selector =
absl::StrFormat(MDNS_DEVICE_SELECTOR_FORMAT.data(), service_type);
absl::StrFormat(MDNS_DEVICE_SELECTOR_FORMAT.data(), service_type_trim);
std::vector<winrt::hstring> requestedProperties{
L"System.Devices.IpAddress",
@@ -345,6 +354,21 @@ NsdServiceInfo WifiLanMedium::GetNsdServiceInformation(
}
nsd_service_info.SetServiceName(InspectableReader::ReadString(inspectable));
// Service type information
inspectable = properties.TryLookup(L"System.Devices.Dnssd.ServiceName");
if (inspectable == nullptr) {
NEARBY_LOGS(WARNING)
<< "no service type information in device information.";
return nsd_service_info;
}
// In WifiLan::StartDiscovery(), service_type is appended with "._tcp." for
// ios and android platform. For windows, we only have "._tcp" as appendix.
// Here "." is added back to match the upper layer service_type, because
// service_type is used to get the corresponding call back function.
nsd_service_info.SetServiceType(
(InspectableReader::ReadString(inspectable)).append("."));
// IP Address information
inspectable = properties.TryLookup(L"System.Devices.IPAddress");
if (inspectable == nullptr) {