mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Add WifiLan validation check
PiperOrigin-RevId: 452402734
This commit is contained in:
@@ -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_);
|
||||
|
||||
|
||||
@@ -192,7 +192,15 @@ class WifiLanMedium {
|
||||
return impl_->GetDynamicPortRange();
|
||||
}
|
||||
|
||||
bool IsValid() const { return impl_ != nullptr; }
|
||||
// Both SW and HW support WifiLan Medium
|
||||
bool IsValid() const {
|
||||
// When impl_ is not nullptr, it means platform layer SW is implemented for
|
||||
// this Medium
|
||||
if (impl_ == nullptr) return false;
|
||||
// A network connection to a primary router exist, also implied that HW is
|
||||
// exist and enabled
|
||||
return impl_->IsNetworkConnected();
|
||||
}
|
||||
|
||||
api::WifiLanMedium& GetImpl() { return *impl_; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user