Add internet connectivity check to network monitor.

PiperOrigin-RevId: 739495202
This commit is contained in:
Francis Tsui
2025-03-22 09:33:41 -07:00
committed by Copybara-Service
parent cf271d55b7
commit 51ef2273ca
14 changed files with 79 additions and 43 deletions
@@ -29,6 +29,7 @@ class MockNetworkMonitor : public nearby::api::NetworkMonitor {
~MockNetworkMonitor() override = default;
MOCK_METHOD(bool, IsLanConnected, (), (override));
MOCK_METHOD(bool, IsInternetConnected, (), (override));
MOCK_METHOD(ConnectionType, GetCurrentConnection, (), (override));
};
+6 -5
View File
@@ -56,11 +56,12 @@ class MockSharingPlatform : public SharingPlatform {
MOCK_METHOD(void, UpdateLoggingLevel, (), (override));
MOCK_METHOD(
std::unique_ptr<nearby::api::NetworkMonitor>, CreateNetworkMonitor,
(std::function<void(nearby::api::NetworkMonitor::ConnectionType, bool)>
callback),
(override));
MOCK_METHOD(std::unique_ptr<nearby::api::NetworkMonitor>,
CreateNetworkMonitor,
(std::function<void(nearby::api::NetworkMonitor::ConnectionType,
bool, bool)>
callback),
(override));
MOCK_METHOD(nearby::sharing::api::BluetoothAdapter&, GetBluetoothAdapter, (),
(override));
+10 -3
View File
@@ -38,21 +38,28 @@ class NetworkMonitor {
kLast = k5G
};
explicit NetworkMonitor(std::function<void(ConnectionType, bool)> callback) {
// Registers a callback for connection changes. The callback will be called
// with the current connection type, whether the device is connected to a
// LAN network and whether the device is connected to internet.
explicit NetworkMonitor(
std::function<void(ConnectionType, bool, bool)> callback) {
callback_ = std::move(callback);
}
virtual ~NetworkMonitor() = default;
// Returns true if connected to an AP (Access Point), not necessarily
// connected to the internet
// connected to the internet.
virtual bool IsLanConnected() = 0;
// Returns true if connected to internet.
virtual bool IsInternetConnected() = 0;
// Returns the type of connection used currently to access the internet
virtual ConnectionType GetCurrentConnection() = 0;
protected:
std::function<void(ConnectionType, bool)> callback_;
std::function<void(ConnectionType, bool, bool)> callback_;
};
} // namespace api
+2 -1
View File
@@ -57,7 +57,8 @@ class SharingPlatform {
virtual void UpdateLoggingLevel() = 0;
virtual std::unique_ptr<nearby::api::NetworkMonitor> CreateNetworkMonitor(
std::function<void(nearby::api::NetworkMonitor::ConnectionType, bool)>
std::function<void(nearby::api::NetworkMonitor::ConnectionType, bool,
bool)>
callback) = 0;
virtual BluetoothAdapter& GetBluetoothAdapter() = 0;