Add WifiLan validation check

PiperOrigin-RevId: 452402734
This commit is contained in:
hai007
2022-06-01 15:51:06 -07:00
committed by Copybara-Service
parent 5cf5ee2048
commit 6ebf3731c8
6 changed files with 29 additions and 1 deletions
@@ -170,6 +170,9 @@ class WifiLanMedium : public api::WifiLanMedium {
WifiLanMedium();
~WifiLanMedium() override;
// Check if a network connection to a primary router exist.
bool IsNetworkConnected() const override { return true; }
// Starts WifiLan advertising.
//
// nsd_service_info - NsdServiceInfo data that's advertised through mDNS
@@ -139,6 +139,9 @@ class WifiLanMedium : public api::WifiLanMedium {
WifiLanMedium(const WifiLanMedium&) = delete;
WifiLanMedium& operator=(const WifiLanMedium&) = delete;
// Check if a network connection to a primary router exist.
bool IsNetworkConnected() const override { return true; }
// api::WifiLanMedium:
bool StartAdvertising(const NsdServiceInfo& nsd_service_info) override
ABSL_LOCKS_EXCLUDED(mutex_);
@@ -76,6 +76,9 @@ class WifiLanMedium {
public:
virtual ~WifiLanMedium() = default;
// Check if a network connection to a primary router exist.
virtual bool IsNetworkConnected() const = 0;
// Starts WifiLan advertising.
//
// nsd_service_info - NsdServiceInfo data that's advertised through mDNS
@@ -218,6 +218,9 @@ class WifiLanMedium : public api::WifiLanMedium {
public:
~WifiLanMedium() override = default;
// Check if a network connection to a primary router exist.
bool IsNetworkConnected() const override;
// Starts to advertising
bool StartAdvertising(const NsdServiceInfo& nsd_service_info) override;
@@ -36,6 +36,14 @@ namespace location {
namespace nearby {
namespace windows {
bool WifiLanMedium::IsNetworkConnected() const {
// connection_profile will be null when there's no network adapter or
// connection to a network. For example, WiFi isn't connected to an AP/hotspot
// and ethernet isn't connected to a router/hub/switch.
auto connection_profile = NetworkInformation::GetInternetConnectionProfile();
return connection_profile != nullptr;
}
bool WifiLanMedium::StartAdvertising(const NsdServiceInfo& nsd_service_info) {
absl::MutexLock lock(&mutex_);