mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Split Lan and Internet connected callbacks.
PiperOrigin-RevId: 816845853
This commit is contained in:
committed by
Copybara-Service
parent
2143967802
commit
382f607d3d
+1
-1
@@ -569,7 +569,7 @@ cc_test(
|
||||
"//internal/test",
|
||||
"//sharing/common:enum",
|
||||
"//sharing/flags/generated:generated_flags",
|
||||
"//sharing/internal/public:types",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/internal/test:nearby_test",
|
||||
"//sharing/proto:enums_cc_proto",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
|
||||
@@ -23,15 +23,13 @@ namespace nearby::sharing::api {
|
||||
|
||||
class MockNetworkMonitor : public nearby::api::NetworkMonitor {
|
||||
public:
|
||||
MockNetworkMonitor() : nearby::api::NetworkMonitor(nullptr) {}
|
||||
MockNetworkMonitor() : nearby::api::NetworkMonitor(nullptr, nullptr) {}
|
||||
MockNetworkMonitor(const MockNetworkMonitor&) = delete;
|
||||
MockNetworkMonitor& operator=(const MockNetworkMonitor&) = delete;
|
||||
~MockNetworkMonitor() override = default;
|
||||
|
||||
MOCK_METHOD(bool, IsLanConnected, (), (override));
|
||||
MOCK_METHOD(bool, IsInternetConnected, (), (override));
|
||||
|
||||
MOCK_METHOD(ConnectionType, GetCurrentConnection, (), (override));
|
||||
};
|
||||
|
||||
} // namespace nearby::sharing::api
|
||||
|
||||
@@ -48,13 +48,12 @@ class MockSharingPlatform : public SharingPlatform {
|
||||
~MockSharingPlatform() override = default;
|
||||
|
||||
MOCK_METHOD(void, InitProductIdGetter,
|
||||
(absl::string_view (*product_id_getter)()), (override));
|
||||
(absl::string_view(*product_id_getter)()), (override));
|
||||
|
||||
MOCK_METHOD(std::unique_ptr<nearby::api::NetworkMonitor>,
|
||||
CreateNetworkMonitor,
|
||||
(std::function<void(nearby::api::NetworkMonitor::ConnectionType,
|
||||
bool, bool)>
|
||||
callback),
|
||||
(std::function<void(bool)> lan_connected_callback,
|
||||
std::function<void(bool)> internet_connected_callback),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(nearby::sharing::api::BluetoothAdapter&, GetBluetoothAdapter, (),
|
||||
|
||||
@@ -15,36 +15,23 @@
|
||||
#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_NETWORK_MONITOR_H_
|
||||
#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_NETWORK_MONITOR_H_
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/functional/any_invocable.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
class NetworkMonitor {
|
||||
public:
|
||||
enum class ConnectionType : int {
|
||||
kUnknown = 0, // A connection exists, but its type is unknown.
|
||||
// Also used as a default value.
|
||||
kEthernet = 1,
|
||||
kWifi = 2,
|
||||
k2G = 3,
|
||||
k3G = 4,
|
||||
k4G = 5,
|
||||
kNone = 6, // No connection.
|
||||
kBluetooth = 7,
|
||||
k5G = 8,
|
||||
kLast = k5G
|
||||
};
|
||||
|
||||
// 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);
|
||||
}
|
||||
// Registers callbacks for connection changes. The callbacks will be called
|
||||
// when device is connected to a LAN network or when the device is connected
|
||||
// to internet.
|
||||
NetworkMonitor(
|
||||
absl::AnyInvocable<void(bool)> lan_connected_callback,
|
||||
absl::AnyInvocable<void(bool)> internet_connected_callback)
|
||||
: lan_connected_callback_(std::move(lan_connected_callback)),
|
||||
internet_connected_callback_(std::move(internet_connected_callback)){}
|
||||
|
||||
virtual ~NetworkMonitor() = default;
|
||||
|
||||
@@ -55,11 +42,9 @@ class NetworkMonitor {
|
||||
// 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, bool)> callback_;
|
||||
absl::AnyInvocable<void(bool)> lan_connected_callback_;
|
||||
absl::AnyInvocable<void(bool)> internet_connected_callback_;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
@@ -48,9 +48,8 @@ class SharingPlatform {
|
||||
absl::string_view (*product_id_getter)()) = 0;
|
||||
|
||||
virtual std::unique_ptr<nearby::api::NetworkMonitor> CreateNetworkMonitor(
|
||||
std::function<void(nearby::api::NetworkMonitor::ConnectionType, bool,
|
||||
bool)>
|
||||
callback) = 0;
|
||||
std::function<void(bool)> lan_connected_callback,
|
||||
std::function<void(bool)> internet_connected_callback) = 0;
|
||||
|
||||
virtual BluetoothAdapter& GetBluetoothAdapter() = 0;
|
||||
|
||||
|
||||
@@ -55,23 +55,20 @@ cc_library(
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":logging",
|
||||
":types",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/network:url",
|
||||
"//internal/platform:types",
|
||||
"//sharing/flags/generated:generated_flags",
|
||||
"//sharing/internal/api:platform",
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/synchronization",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "nearby_context_test",
|
||||
name = "connectivity_manager_impl_test",
|
||||
size = "small",
|
||||
timeout = "short",
|
||||
srcs = [
|
||||
|
||||
@@ -23,35 +23,21 @@ namespace nearby {
|
||||
|
||||
class ConnectivityManager {
|
||||
public:
|
||||
enum class ConnectionType {
|
||||
kUnknown = 0, // A connection exists, but its type is unknown.
|
||||
// Also used as a default value.
|
||||
kEthernet = 1,
|
||||
kWifi = 2,
|
||||
k2G = 3,
|
||||
k3G = 4,
|
||||
k4G = 5,
|
||||
kNone = 6, // No connection.
|
||||
kBluetooth = 7,
|
||||
k5G = 8,
|
||||
kLast = k5G
|
||||
};
|
||||
|
||||
virtual ~ConnectivityManager() = default;
|
||||
|
||||
virtual bool IsLanConnected() = 0;
|
||||
virtual bool IsInternetConnected() = 0;
|
||||
|
||||
virtual ConnectionType GetConnectionType() = 0;
|
||||
|
||||
// Registers a listener for connection changes. The listener 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.
|
||||
virtual void RegisterConnectionListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(ConnectionType, bool, bool)>) = 0;
|
||||
virtual void UnregisterConnectionListener(
|
||||
absl::string_view listener_name) = 0;
|
||||
// when the device is connected to a LAN network or when the device is
|
||||
// connected to internet.
|
||||
virtual void RegisterLanListener(absl::string_view listener_name,
|
||||
std::function<void(bool)>) = 0;
|
||||
virtual void UnregisterLanListener(absl::string_view listener_name) = 0;
|
||||
virtual void RegisterInternetListener(absl::string_view listener_name,
|
||||
std::function<void(bool)>) = 0;
|
||||
virtual void UnregisterInternetListener(absl::string_view listener_name) = 0;
|
||||
|
||||
// Is the device a HP device with Realtek wireless module.
|
||||
virtual bool IsHPRealtekDevice() = 0;
|
||||
};
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
@@ -29,50 +28,27 @@
|
||||
#include "sharing/flags/generated/nearby_sharing_feature_flags.h"
|
||||
#include "sharing/internal/api/network_monitor.h"
|
||||
#include "sharing/internal/api/sharing_platform.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace {
|
||||
|
||||
using ::nearby::sharing::api::SharingPlatform;
|
||||
using ConnectionType = ConnectivityManager::ConnectionType;
|
||||
|
||||
std::string GetConnectionTypeString(ConnectionType connection_type) {
|
||||
switch (connection_type) {
|
||||
case ConnectionType::k2G:
|
||||
return "2G";
|
||||
case ConnectionType::k3G:
|
||||
return "3G";
|
||||
case ConnectionType::k4G:
|
||||
return "4G";
|
||||
case ConnectionType::k5G:
|
||||
return "5G";
|
||||
case ConnectionType::kBluetooth:
|
||||
return "Bluetooth";
|
||||
case ConnectionType::kEthernet:
|
||||
return "Ethernet";
|
||||
case ConnectionType::kWifi:
|
||||
return "WiFi";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ConnectivityManagerImpl::ConnectivityManagerImpl(SharingPlatform& platform)
|
||||
: platform_(platform) {
|
||||
network_monitor_ = platform.CreateNetworkMonitor(
|
||||
[this](api::NetworkMonitor::ConnectionType connection_type,
|
||||
bool is_lan_connected, bool is_internet_connected) {
|
||||
ConnectionType new_connection_type =
|
||||
static_cast<ConnectionType>(connection_type);
|
||||
VLOG(1) << ": New connection type:"
|
||||
<< GetConnectionTypeString(new_connection_type);
|
||||
for (auto& listener : listeners_) {
|
||||
listener.second(new_connection_type, is_lan_connected,
|
||||
is_internet_connected);
|
||||
[this](bool is_lan_connected) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
for (auto& listener : lan_listeners_) {
|
||||
listener.second(is_lan_connected);
|
||||
}
|
||||
},
|
||||
[this](bool is_internet_connected) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
for (auto& listener : internet_listeners_) {
|
||||
listener.second(is_internet_connected);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -113,23 +89,37 @@ bool ConnectivityManagerImpl::IsHPRealtekDevice() {
|
||||
return is_hp_realtek_device_.value();
|
||||
}
|
||||
|
||||
ConnectionType ConnectivityManagerImpl::GetConnectionType() {
|
||||
return static_cast<ConnectionType>(network_monitor_->GetCurrentConnection());
|
||||
void ConnectivityManagerImpl::RegisterLanListener(
|
||||
absl::string_view listener_name, std::function<void(bool)> callback) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
lan_listeners_.emplace(listener_name, std::move(callback));
|
||||
}
|
||||
|
||||
void ConnectivityManagerImpl::RegisterConnectionListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(ConnectionType, bool, bool)> callback) {
|
||||
listeners_.emplace(listener_name, std::move(callback));
|
||||
}
|
||||
|
||||
void ConnectivityManagerImpl::UnregisterConnectionListener(
|
||||
void ConnectivityManagerImpl::UnregisterLanListener(
|
||||
absl::string_view listener_name) {
|
||||
listeners_.erase(listener_name);
|
||||
absl::MutexLock lock(mutex_);
|
||||
lan_listeners_.erase(listener_name);
|
||||
}
|
||||
|
||||
int ConnectivityManagerImpl::GetListenerCount() const {
|
||||
return listeners_.size();
|
||||
void ConnectivityManagerImpl::RegisterInternetListener(
|
||||
absl::string_view listener_name, std::function<void(bool)> callback) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
internet_listeners_.emplace(listener_name, std::move(callback));
|
||||
}
|
||||
|
||||
void ConnectivityManagerImpl::UnregisterInternetListener(
|
||||
absl::string_view listener_name) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
internet_listeners_.erase(listener_name);
|
||||
}
|
||||
|
||||
int ConnectivityManagerImpl::GetLanListenerCountForTests() const {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return lan_listeners_.size();
|
||||
}
|
||||
int ConnectivityManagerImpl::GetInternetListenerCountForTests() const {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return internet_listeners_.size();
|
||||
}
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "sharing/internal/api/network_monitor.h"
|
||||
#include "sharing/internal/api/sharing_platform.h"
|
||||
#include "sharing/internal/api/system_info.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -40,19 +39,22 @@ class ConnectivityManagerImpl : public ConnectivityManager {
|
||||
bool IsLanConnected() override;
|
||||
bool IsInternetConnected() override;
|
||||
bool IsHPRealtekDevice() override;
|
||||
ConnectionType GetConnectionType() override;
|
||||
|
||||
void RegisterConnectionListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(ConnectionType, bool, bool)> callback) override;
|
||||
void UnregisterConnectionListener(absl::string_view listener_name) override;
|
||||
void RegisterLanListener(absl::string_view listener_name,
|
||||
std::function<void(bool)>) override;
|
||||
void UnregisterLanListener(absl::string_view listener_name) override;
|
||||
void RegisterInternetListener(absl::string_view listener_name,
|
||||
std::function<void(bool)>) override;
|
||||
void UnregisterInternetListener(absl::string_view listener_name) override;
|
||||
|
||||
int GetListenerCount() const;
|
||||
int GetLanListenerCountForTests() const;
|
||||
int GetInternetListenerCountForTests() const;
|
||||
|
||||
private:
|
||||
absl::flat_hash_map<std::string,
|
||||
std::function<void(ConnectionType, bool, bool)>>
|
||||
listeners_;
|
||||
absl::flat_hash_map<std::string, std::function<void(bool)>> lan_listeners_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
absl::flat_hash_map<std::string, std::function<void(bool)>>
|
||||
internet_listeners_ ABSL_GUARDED_BY(mutex_);
|
||||
std::unique_ptr<api::NetworkMonitor> network_monitor_;
|
||||
nearby::sharing::api::SharingPlatform& platform_;
|
||||
mutable absl::Mutex mutex_;
|
||||
|
||||
@@ -42,25 +42,24 @@ TEST(ConnectivityManagerImpl, IsLanConnected) {
|
||||
auto network_monitor = std::make_unique<MockNetworkMonitor>();
|
||||
MockNetworkMonitor* mock_network_monitor = network_monitor.get();
|
||||
EXPECT_CALL(*mock_network_monitor, IsLanConnected()).WillOnce(Return(true));
|
||||
EXPECT_CALL(sharing_platform, CreateNetworkMonitor(_))
|
||||
EXPECT_CALL(sharing_platform, CreateNetworkMonitor(_, _))
|
||||
.WillOnce(Return(ByMove(std::move(network_monitor))));
|
||||
|
||||
ConnectivityManagerImpl connectivity_manager_impl(sharing_platform);
|
||||
EXPECT_TRUE(connectivity_manager_impl.IsLanConnected());
|
||||
}
|
||||
|
||||
TEST(ConnectivityManagerImpl, GetConnectionType) {
|
||||
TEST(ConnectivityManagerImpl, IsInternetConnected) {
|
||||
MockSharingPlatform sharing_platform;
|
||||
auto network_monitor = std::make_unique<MockNetworkMonitor>();
|
||||
MockNetworkMonitor* mock_network_monitor = network_monitor.get();
|
||||
EXPECT_CALL(sharing_platform, CreateNetworkMonitor(_))
|
||||
EXPECT_CALL(*mock_network_monitor, IsInternetConnected())
|
||||
.WillOnce(Return(true));
|
||||
EXPECT_CALL(sharing_platform, CreateNetworkMonitor(_, _))
|
||||
.WillOnce(Return(ByMove(std::move(network_monitor))));
|
||||
EXPECT_CALL(*mock_network_monitor, GetCurrentConnection())
|
||||
.WillOnce(Return(MockNetworkMonitor::ConnectionType::kWifi));
|
||||
|
||||
ConnectivityManagerImpl connectivity_manager_impl(sharing_platform);
|
||||
EXPECT_EQ(connectivity_manager_impl.GetConnectionType(),
|
||||
ConnectivityManager::ConnectionType::kWifi);
|
||||
EXPECT_TRUE(connectivity_manager_impl.IsInternetConnected());
|
||||
}
|
||||
|
||||
TEST(ConnectivityManagerImpl, IsHPRealtekDeviceReturnsTrue) {
|
||||
@@ -111,49 +110,43 @@ TEST(ConnectivityManagerImpl, IsHPRealtekDevice_NotRealtekDevice) {
|
||||
EXPECT_FALSE(connectivity_manager_impl.IsHPRealtekDevice());
|
||||
}
|
||||
|
||||
TEST(ConnectivityManagerImpl, RegisterConnectionListener) {
|
||||
std::function<void(ConnectivityManager::ConnectionType, bool, bool)>
|
||||
listener_1 = [](ConnectivityManager::ConnectionType connection_type,
|
||||
bool is_lan_connected, bool is_internet_connected) {};
|
||||
std::function<void(ConnectivityManager::ConnectionType, bool, bool)>
|
||||
listener_2 = [](ConnectivityManager::ConnectionType connection_type,
|
||||
bool is_lan_connected, bool is_internet_connected) {};
|
||||
TEST(ConnectivityManagerImpl, RegisterLanListener) {
|
||||
auto
|
||||
listener_1 = [](bool is_lan_connected) {};
|
||||
auto
|
||||
listener_2 = [](bool is_lan_connected) {};
|
||||
|
||||
MockSharingPlatform sharing_platform;
|
||||
ConnectivityManagerImpl connectivity_manager_impl(sharing_platform);
|
||||
EXPECT_EQ(connectivity_manager_impl.GetListenerCount(), 0);
|
||||
EXPECT_EQ(connectivity_manager_impl.GetLanListenerCountForTests(), 0);
|
||||
|
||||
connectivity_manager_impl.RegisterConnectionListener("listener_1",
|
||||
connectivity_manager_impl.RegisterLanListener("listener_1",
|
||||
listener_1);
|
||||
EXPECT_EQ(connectivity_manager_impl.GetListenerCount(), 1);
|
||||
EXPECT_EQ(connectivity_manager_impl.GetLanListenerCountForTests(), 1);
|
||||
|
||||
connectivity_manager_impl.RegisterConnectionListener("listener_2",
|
||||
connectivity_manager_impl.RegisterLanListener("listener_2",
|
||||
listener_2);
|
||||
EXPECT_EQ(connectivity_manager_impl.GetListenerCount(), 2);
|
||||
EXPECT_EQ(connectivity_manager_impl.GetLanListenerCountForTests(), 2);
|
||||
}
|
||||
|
||||
TEST(ConnectivityManagerImpl, UnregisterConnectionListener) {
|
||||
std::function<void(ConnectivityManager::ConnectionType, bool, bool)>
|
||||
listener_1 = [](ConnectivityManager::ConnectionType connection_type,
|
||||
bool is_lan_connected, bool is_internet_connected) {};
|
||||
std::function<void(ConnectivityManager::ConnectionType, bool, bool)>
|
||||
listener_2 = [](ConnectivityManager::ConnectionType connection_type,
|
||||
bool is_lan_connected, bool is_internet_connected) {};
|
||||
TEST(ConnectivityManagerImpl, UnregisterLanListener) {
|
||||
auto listener_1 = [](bool is_lan_connected) {};
|
||||
auto listener_2 = [](bool is_lan_connected) {};
|
||||
|
||||
MockSharingPlatform sharing_platform;
|
||||
ConnectivityManagerImpl connectivity_manager_impl(sharing_platform);
|
||||
connectivity_manager_impl.RegisterConnectionListener("listener_1",
|
||||
connectivity_manager_impl.RegisterLanListener("listener_1",
|
||||
listener_1);
|
||||
connectivity_manager_impl.RegisterConnectionListener("listener_2",
|
||||
connectivity_manager_impl.RegisterLanListener("listener_2",
|
||||
listener_2);
|
||||
|
||||
EXPECT_EQ(connectivity_manager_impl.GetListenerCount(), 2);
|
||||
EXPECT_EQ(connectivity_manager_impl.GetLanListenerCountForTests(), 2);
|
||||
|
||||
connectivity_manager_impl.UnregisterConnectionListener("listener_1");
|
||||
EXPECT_EQ(connectivity_manager_impl.GetListenerCount(), 1);
|
||||
connectivity_manager_impl.UnregisterLanListener("listener_1");
|
||||
EXPECT_EQ(connectivity_manager_impl.GetLanListenerCountForTests(), 1);
|
||||
|
||||
connectivity_manager_impl.UnregisterConnectionListener("listener_2");
|
||||
EXPECT_EQ(connectivity_manager_impl.GetListenerCount(), 0);
|
||||
connectivity_manager_impl.UnregisterLanListener("listener_2");
|
||||
EXPECT_EQ(connectivity_manager_impl.GetLanListenerCountForTests(), 0);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -31,7 +31,6 @@ cc_library(
|
||||
"fake_connectivity_manager.h",
|
||||
"fake_context.h",
|
||||
"fake_fast_initiation_manager.h",
|
||||
"fake_network_monitor.h",
|
||||
"fake_preference_manager.h",
|
||||
"fake_public_certificate_db.h",
|
||||
],
|
||||
|
||||
@@ -33,52 +33,43 @@ class FakeConnectivityManager : public ConnectivityManager {
|
||||
void SetIsHPRealtekDevice(bool is_hp_realtek_device) {
|
||||
is_hp_realtek_device_ = is_hp_realtek_device;
|
||||
}
|
||||
ConnectionType GetConnectionType() override { return connection_type_; }
|
||||
|
||||
void RegisterConnectionListener(
|
||||
absl::string_view listener_name,
|
||||
std::function<void(ConnectionType, bool, bool)> callback) override {
|
||||
listeners_.emplace(listener_name, std::move(callback));
|
||||
void RegisterLanListener(absl::string_view listener_name,
|
||||
std::function<void(bool)> callback) override {
|
||||
lan_listeners_.emplace(listener_name, std::move(callback));
|
||||
}
|
||||
void UnregisterConnectionListener(absl::string_view listener_name) override {
|
||||
listeners_.erase(listener_name);
|
||||
void UnregisterLanListener(absl::string_view listener_name) override {
|
||||
lan_listeners_.erase(listener_name);
|
||||
}
|
||||
void RegisterInternetListener(absl::string_view listener_name,
|
||||
std::function<void(bool)> callback) override {
|
||||
internet_listeners_.emplace(listener_name, std::move(callback));
|
||||
}
|
||||
void UnregisterInternetListener(absl::string_view listener_name) override {
|
||||
internet_listeners_.erase(listener_name);
|
||||
}
|
||||
|
||||
// Mocks connectivity methods.
|
||||
void SetLanConnected(bool connected) {
|
||||
is_lan_connected_ = connected;
|
||||
for (auto& listener : listeners_) {
|
||||
listener.second(connection_type_, is_lan_connected_,
|
||||
is_internet_connected_);
|
||||
for (auto& listener : lan_listeners_) {
|
||||
listener.second(is_lan_connected_);
|
||||
}
|
||||
}
|
||||
|
||||
void SetInternetConnected(bool connected) {
|
||||
is_internet_connected_ = connected;
|
||||
for (auto& listener : listeners_) {
|
||||
listener.second(connection_type_, is_lan_connected_,
|
||||
is_internet_connected_);
|
||||
for (auto& listener : internet_listeners_) {
|
||||
listener.second(is_internet_connected_);
|
||||
}
|
||||
}
|
||||
|
||||
// Mocks connectivity methods.
|
||||
void SetConnectionType(ConnectionType connection_type) {
|
||||
connection_type_ = connection_type;
|
||||
for (auto& listener : listeners_) {
|
||||
listener.second(connection_type_, is_lan_connected_,
|
||||
is_internet_connected_);
|
||||
}
|
||||
}
|
||||
int GetListenerCount() const { return listeners_.size(); }
|
||||
|
||||
private:
|
||||
bool is_lan_connected_ = true;
|
||||
bool is_internet_connected_ = true;
|
||||
bool is_hp_realtek_device_ = false;
|
||||
ConnectionType connection_type_ = ConnectionType::kWifi;
|
||||
absl::flat_hash_map<std::string,
|
||||
std::function<void(ConnectionType, bool, bool)>>
|
||||
listeners_;
|
||||
absl::flat_hash_map<std::string, std::function<void(bool)>> lan_listeners_;
|
||||
absl::flat_hash_map<std::string, std::function<void(bool)>>
|
||||
internet_listeners_;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "sharing/internal/test/fake_connectivity_manager.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace {
|
||||
@@ -28,40 +27,16 @@ TEST(FakeConnectivityManager, TestIsLanConnected) {
|
||||
EXPECT_FALSE(connection_manager.IsLanConnected());
|
||||
}
|
||||
|
||||
TEST(FakeConnectivityManager, TestGetCurrentConnection) {
|
||||
FakeConnectivityManager connection_manager;
|
||||
ConnectivityManager::ConnectionType connection =
|
||||
connection_manager.GetConnectionType();
|
||||
EXPECT_EQ(connection, ConnectivityManager::ConnectionType::kWifi);
|
||||
connection_manager.SetConnectionType(
|
||||
ConnectivityManager::ConnectionType::kEthernet);
|
||||
EXPECT_EQ(connection_manager.GetConnectionType(),
|
||||
ConnectivityManager::ConnectionType::kEthernet);
|
||||
}
|
||||
|
||||
TEST(FakeConnectivityManager, TestListener) {
|
||||
FakeConnectivityManager connection_manager;
|
||||
ConnectivityManager::ConnectionType connection_type =
|
||||
connection_manager.GetConnectionType();
|
||||
bool is_lan_connected = false;
|
||||
connection_manager.RegisterConnectionListener(
|
||||
"test", [&connection_type, &is_lan_connected](
|
||||
ConnectivityManager::ConnectionType connection,
|
||||
bool connected, bool internet_connected) {
|
||||
connection_type = connection;
|
||||
is_lan_connected = connected;
|
||||
connection_manager.RegisterLanListener(
|
||||
"test", [&is_lan_connected](bool lan_connected) {
|
||||
is_lan_connected = lan_connected;
|
||||
});
|
||||
EXPECT_EQ(connection_manager.GetListenerCount(), 1);
|
||||
connection_manager.SetConnectionType(
|
||||
ConnectivityManager::ConnectionType::kEthernet);
|
||||
connection_manager.SetLanConnected(true);
|
||||
EXPECT_EQ(connection_type, ConnectivityManager::ConnectionType::kEthernet);
|
||||
ASSERT_TRUE(is_lan_connected);
|
||||
connection_manager.UnregisterConnectionListener("test");
|
||||
EXPECT_EQ(connection_manager.GetListenerCount(), 0);
|
||||
connection_manager.SetConnectionType(
|
||||
ConnectivityManager::ConnectionType::kWifi);
|
||||
EXPECT_EQ(connection_type, ConnectivityManager::ConnectionType::kEthernet);
|
||||
connection_manager.UnregisterLanListener("test");
|
||||
EXPECT_TRUE(is_lan_connected);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_TEST_FAKE_NETWORK_MONITOR_H_
|
||||
#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_TEST_FAKE_NETWORK_MONITOR_H_
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "sharing/internal/api/network_monitor.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
class FakeNetworkMonitor : public api::NetworkMonitor {
|
||||
public:
|
||||
explicit FakeNetworkMonitor(
|
||||
std::function<void(api::NetworkMonitor::ConnectionType, bool, bool)>
|
||||
callback)
|
||||
: api::NetworkMonitor(callback) {}
|
||||
|
||||
~FakeNetworkMonitor() override { callback_ = nullptr; }
|
||||
|
||||
bool IsLanConnected() override { return is_lan_connected_; }
|
||||
bool IsInternetConnected() override { return is_internet_connected_; }
|
||||
|
||||
api::NetworkMonitor::ConnectionType GetCurrentConnection() override {
|
||||
return api::NetworkMonitor::ConnectionType::kWifi;
|
||||
}
|
||||
|
||||
void SetLanConnected(bool connected) { is_lan_connected_ = connected; }
|
||||
void SetInternetConnected(bool connected) {
|
||||
is_internet_connected_ = connected;
|
||||
}
|
||||
|
||||
void TestNetworkChangeToEthernet() {
|
||||
callback_(api::NetworkMonitor::ConnectionType::kEthernet,
|
||||
is_lan_connected_, is_internet_connected_);
|
||||
}
|
||||
|
||||
private:
|
||||
bool is_lan_connected_ = true;
|
||||
bool is_internet_connected_ = true;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_TEST_FAKE_NETWORK_MONITOR_H_
|
||||
@@ -72,17 +72,14 @@ bool ShouldUseInternet(ConnectivityManager& connectivity_manager,
|
||||
// We won't use the internet in a low power mode.
|
||||
if (power_level == PowerLevel::kLowPower) return false;
|
||||
|
||||
ConnectivityManager::ConnectionType connection_type =
|
||||
connectivity_manager.GetConnectionType();
|
||||
|
||||
// Verify that this network has an internet connection.
|
||||
if (connection_type == ConnectivityManager::ConnectionType::kNone) {
|
||||
if (!connectivity_manager.IsInternetConnected()) {
|
||||
VLOG(1) << __func__ << ": No internet connection.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data_usage == DataUsage::WIFI_ONLY_DATA_USAGE &&
|
||||
connection_type != ConnectivityManager::ConnectionType::kWifi) {
|
||||
!connectivity_manager.IsLanConnected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -105,13 +102,7 @@ bool ShouldEnableWifiLan(ConnectivityManager& connectivity_manager) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ConnectivityManager::ConnectionType connection_type =
|
||||
connectivity_manager.GetConnectionType();
|
||||
bool is_connection_wifi_or_ethernet =
|
||||
connection_type == ConnectivityManager::ConnectionType::kWifi ||
|
||||
connection_type == ConnectivityManager::ConnectionType::kEthernet;
|
||||
|
||||
return is_connection_wifi_or_ethernet;
|
||||
return connectivity_manager.IsLanConnected();
|
||||
}
|
||||
|
||||
// Temporarily fix to get around wifi hotspot issues for HP Aero with Realtek.
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <ios>
|
||||
@@ -39,14 +38,13 @@
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/base/files.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/test/fake_clock.h"
|
||||
#include "internal/test/fake_device_info.h"
|
||||
#include "internal/test/fake_task_runner.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
#include "sharing/constants.h"
|
||||
#include "sharing/fake_nearby_connections_service.h"
|
||||
#include "sharing/flags/generated/nearby_sharing_feature_flags.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/internal/test/fake_connectivity_manager.h"
|
||||
#include "sharing/internal/test/fake_context.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
@@ -142,7 +140,6 @@ class NearbyConnectionsManagerImplTest : public testing::Test {
|
||||
true);
|
||||
auto nearby_connections_service =
|
||||
std::make_unique<testing::NiceMock<FakeNearbyConnectionsService>>();
|
||||
SetConnectionType(ConnectivityManager::ConnectionType::kWifi);
|
||||
nearby_connections_ = nearby_connections_service.get();
|
||||
|
||||
nearby_connections_manager_ =
|
||||
@@ -156,10 +153,10 @@ class NearbyConnectionsManagerImplTest : public testing::Test {
|
||||
fake_task_runner_.SyncWithTimeout(absl::Seconds(1));
|
||||
}
|
||||
|
||||
void SetConnectionType(ConnectivityManager::ConnectionType connection_type) {
|
||||
fake_connectivity_manager_.SetConnectionType(connection_type);
|
||||
void SetConnectionStatus(bool lan_connected, bool internet_connected) {
|
||||
fake_connectivity_manager_.SetLanConnected(lan_connected);
|
||||
fake_connectivity_manager_.SetInternetConnected(internet_connected);
|
||||
}
|
||||
|
||||
void Fastforward(absl::Duration duration) {
|
||||
fake_context_.fake_clock()->FastForward(duration);
|
||||
}
|
||||
@@ -241,8 +238,7 @@ class NearbyConnectionsManagerImplTest : public testing::Test {
|
||||
nearby_connections_manager_->StartAdvertising(
|
||||
local_endpoint_info, &incoming_connection_listener,
|
||||
PowerLevel::kHighPower, DataUsage::ONLINE_DATA_USAGE, false,
|
||||
/*force_new_endpoint_id=*/false,
|
||||
std::move(callback));
|
||||
/*force_new_endpoint_id=*/false, std::move(callback));
|
||||
EXPECT_TRUE(
|
||||
notification.WaitForNotificationWithTimeout(kSynchronizationTimeOut));
|
||||
}
|
||||
@@ -532,7 +528,6 @@ TEST_F(NearbyConnectionsManagerImplTest, DiscoveryFlow) {
|
||||
|
||||
TEST_F(NearbyConnectionsManagerImplTest,
|
||||
DisableWifiHotspotForHighQualityNonDisruptiveTransport) {
|
||||
SetConnectionType(ConnectivityManager::ConnectionType::kWifi);
|
||||
// StartDiscovery will succeed.
|
||||
NearbyConnectionsService::DiscoveryListener discovery_listener_remote;
|
||||
testing::NiceMock<MockDiscoveryListener> discovery_listener;
|
||||
@@ -569,7 +564,6 @@ TEST_F(NearbyConnectionsManagerImplTest,
|
||||
}
|
||||
|
||||
TEST_F(NearbyConnectionsManagerImplTest, DisableWifiHotspotForHPRealtekDevice) {
|
||||
SetConnectionType(ConnectivityManager::ConnectionType::kWifi);
|
||||
fake_connectivity_manager_.SetIsHPRealtekDevice(true);
|
||||
|
||||
// StartDiscovery will succeed.
|
||||
@@ -611,7 +605,9 @@ TEST_F(NearbyConnectionsManagerImplTest, DisableWifiHotspotForHPRealtekDevice) {
|
||||
// Begin: NearbyConnectionsManagerImplTestConnectionMediums
|
||||
/******************************************************************************/
|
||||
using ConnectionMediumsTestParam =
|
||||
std::tuple<DataUsage, ConnectivityManager::ConnectionType, bool, bool>;
|
||||
std::tuple<DataUsage, /*is_webrtc_enabled=*/bool,
|
||||
/*is_wifilan_enabled=*/bool, /*is_lan_connected=*/bool,
|
||||
/*is_internet_connected=*/bool>;
|
||||
class NearbyConnectionsManagerImplTestConnectionMediums
|
||||
: public NearbyConnectionsManagerImplTest,
|
||||
public testing::WithParamInterface<ConnectionMediumsTestParam> {};
|
||||
@@ -620,9 +616,15 @@ TEST_P(NearbyConnectionsManagerImplTestConnectionMediums,
|
||||
RequestConnection_MediumSelection) {
|
||||
const ConnectionMediumsTestParam& param = GetParam();
|
||||
DataUsage data_usage = std::get<0>(param);
|
||||
ConnectivityManager::ConnectionType connection_type = std::get<1>(param);
|
||||
bool is_webrtc_enabled = std::get<2>(GetParam());
|
||||
bool is_wifilan_enabled = std::get<3>(GetParam());
|
||||
bool is_webrtc_enabled = std::get<1>(GetParam());
|
||||
bool is_wifilan_enabled = std::get<2>(GetParam());
|
||||
bool is_lan_connected = std::get<3>(GetParam());
|
||||
bool is_internet_connected = std::get<4>(GetParam());
|
||||
LOG(INFO) << "Test params: data_usage: " << static_cast<int>(data_usage)
|
||||
<< ", is_webrtc_enabled: " << is_webrtc_enabled
|
||||
<< ", is_wifilan_enabled: " << is_wifilan_enabled
|
||||
<< ", is_lan_connected: " << is_lan_connected
|
||||
<< ", is_internet_connected: " << is_internet_connected;
|
||||
|
||||
if (is_webrtc_enabled) {
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
@@ -642,18 +644,13 @@ TEST_P(NearbyConnectionsManagerImplTestConnectionMediums,
|
||||
config_package_nearby::nearby_sharing_feature::kEnableMediumWifiLan,
|
||||
false);
|
||||
}
|
||||
SetConnectionStatus(is_lan_connected, is_internet_connected);
|
||||
|
||||
SetConnectionType(connection_type);
|
||||
bool should_use_internet =
|
||||
data_usage != DataUsage::OFFLINE_DATA_USAGE &&
|
||||
connection_type != ConnectivityManager::ConnectionType::kNone &&
|
||||
!(data_usage == DataUsage::WIFI_ONLY_DATA_USAGE &&
|
||||
connection_type != ConnectivityManager::ConnectionType::kWifi);
|
||||
bool is_connection_wifi_or_ethernet =
|
||||
connection_type == ConnectivityManager::ConnectionType::kWifi ||
|
||||
connection_type == ConnectivityManager::ConnectionType::kEthernet;
|
||||
is_internet_connected && data_usage != DataUsage::OFFLINE_DATA_USAGE &&
|
||||
!(data_usage == DataUsage::WIFI_ONLY_DATA_USAGE && !is_lan_connected);
|
||||
should_use_web_rtc_ = is_webrtc_enabled && should_use_internet;
|
||||
should_use_wifilan_ = is_wifilan_enabled && is_connection_wifi_or_ethernet;
|
||||
should_use_wifilan_ = is_wifilan_enabled && is_lan_connected;
|
||||
|
||||
MediumSelection expected_mediums(/*bluetooth=*/true,
|
||||
/*ble=*/false,
|
||||
@@ -707,10 +704,8 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
testing::Combine(testing::Values(DataUsage::WIFI_ONLY_DATA_USAGE,
|
||||
DataUsage::OFFLINE_DATA_USAGE,
|
||||
DataUsage::ONLINE_DATA_USAGE),
|
||||
testing::Values(ConnectivityManager::ConnectionType::kNone,
|
||||
ConnectivityManager::ConnectionType::kWifi,
|
||||
ConnectivityManager::ConnectionType::k3G),
|
||||
testing::Bool(), testing::Bool()));
|
||||
testing::Bool(), testing::Bool(), testing::Bool(),
|
||||
testing::Bool()));
|
||||
/******************************************************************************/
|
||||
// End: NearbyConnectionsManagerImplTestConnectionMediums
|
||||
/******************************************************************************/
|
||||
@@ -1602,8 +1597,9 @@ TEST_F(NearbyConnectionsManagerImplTest, ClearIncomingPayloads) {
|
||||
// Begin: NearbyConnectionsManagerImplTestMediums
|
||||
/******************************************************************************/
|
||||
using MediumsTestParam =
|
||||
std::tuple<PowerLevel, DataUsage, ConnectivityManager::ConnectionType, bool,
|
||||
bool>;
|
||||
std::tuple<PowerLevel, DataUsage, /*is_webrtc_enabled=*/bool,
|
||||
/*is_wifilan_enabled=*/bool, /*is_lan_connected=*/bool,
|
||||
/*is_internet_connected=*/bool>;
|
||||
class NearbyConnectionsManagerImplTestMediums
|
||||
: public NearbyConnectionsManagerImplTest,
|
||||
public testing::WithParamInterface<MediumsTestParam> {};
|
||||
@@ -1612,9 +1608,16 @@ TEST_P(NearbyConnectionsManagerImplTestMediums, StartAdvertising_Options) {
|
||||
const MediumsTestParam& param = GetParam();
|
||||
PowerLevel power_level = std::get<0>(param);
|
||||
DataUsage data_usage = std::get<1>(param);
|
||||
ConnectivityManager::ConnectionType connection_type = std::get<2>(param);
|
||||
bool is_webrtc_enabled = std::get<3>(GetParam());
|
||||
bool is_wifilan_enabled = std::get<4>(GetParam());
|
||||
bool is_webrtc_enabled = std::get<2>(GetParam());
|
||||
bool is_wifilan_enabled = std::get<3>(GetParam());
|
||||
bool is_lan_connected = std::get<4>(GetParam());
|
||||
bool is_internet_connected = std::get<5>(GetParam());
|
||||
LOG(INFO) << "Test params: power_level: " << static_cast<int>(power_level)
|
||||
<< ", data_usage: " << static_cast<int>(data_usage)
|
||||
<< ", is_webrtc_enabled: " << is_webrtc_enabled
|
||||
<< ", is_wifilan_enabled: " << is_wifilan_enabled
|
||||
<< ", is_lan_connected: " << is_lan_connected
|
||||
<< ", is_internet_connected: " << is_internet_connected;
|
||||
|
||||
if (is_webrtc_enabled) {
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
@@ -1634,19 +1637,13 @@ TEST_P(NearbyConnectionsManagerImplTestMediums, StartAdvertising_Options) {
|
||||
config_package_nearby::nearby_sharing_feature::kEnableMediumWifiLan,
|
||||
false);
|
||||
}
|
||||
|
||||
SetConnectionType(connection_type);
|
||||
SetConnectionStatus(is_lan_connected, is_internet_connected);
|
||||
|
||||
bool should_use_internet =
|
||||
data_usage != DataUsage::OFFLINE_DATA_USAGE &&
|
||||
connection_type != ConnectivityManager::ConnectionType::kNone &&
|
||||
!(data_usage == DataUsage::WIFI_ONLY_DATA_USAGE &&
|
||||
connection_type != ConnectivityManager::ConnectionType::kWifi);
|
||||
bool is_connection_wifi_or_ethernet =
|
||||
connection_type == ConnectivityManager::ConnectionType::kWifi ||
|
||||
connection_type == ConnectivityManager::ConnectionType::kEthernet;
|
||||
is_internet_connected && data_usage != DataUsage::OFFLINE_DATA_USAGE &&
|
||||
!(data_usage == DataUsage::WIFI_ONLY_DATA_USAGE && !is_lan_connected);
|
||||
should_use_web_rtc_ = is_webrtc_enabled && should_use_internet;
|
||||
should_use_wifilan_ = is_wifilan_enabled & is_connection_wifi_or_ethernet;
|
||||
should_use_wifilan_ = is_wifilan_enabled && is_lan_connected;
|
||||
|
||||
bool is_high_power = power_level == PowerLevel::kHighPower;
|
||||
|
||||
@@ -1706,10 +1703,8 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
testing::Values(DataUsage::WIFI_ONLY_DATA_USAGE,
|
||||
DataUsage::OFFLINE_DATA_USAGE,
|
||||
DataUsage::ONLINE_DATA_USAGE),
|
||||
testing::Values(ConnectivityManager::ConnectionType::kNone,
|
||||
ConnectivityManager::ConnectionType::kWifi,
|
||||
ConnectivityManager::ConnectionType::k3G),
|
||||
testing::Bool(), testing::Bool()));
|
||||
testing::Bool(), testing::Bool(), testing::Bool(),
|
||||
testing::Bool()));
|
||||
|
||||
/******************************************************************************/
|
||||
// End: NearbyConnectionsManagerImplTestMediums
|
||||
|
||||
@@ -260,11 +260,8 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
|
||||
profile_path, nearby_share_client_factory_.get()),
|
||||
|
||||
certificate_manager_->AddObserver(this);
|
||||
context_->GetConnectivityManager()->RegisterConnectionListener(
|
||||
kConnectionListenerName,
|
||||
[this](nearby::ConnectivityManager::ConnectionType type,
|
||||
bool is_lan_connected, bool is_internet_connected) {
|
||||
OnNetworkChanged(type);
|
||||
context_->GetConnectivityManager()->RegisterLanListener(
|
||||
kConnectionListenerName, [this](bool is_lan_connected) {
|
||||
OnLanConnectedChanged(is_lan_connected);
|
||||
});
|
||||
|
||||
@@ -313,7 +310,7 @@ void NearbySharingServiceImpl::Shutdown(
|
||||
|
||||
certificate_manager_->RemoveObserver(this);
|
||||
account_manager_.RemoveObserver(this);
|
||||
context_->GetConnectivityManager()->UnregisterConnectionListener(
|
||||
context_->GetConnectivityManager()->UnregisterLanListener(
|
||||
kConnectionListenerName);
|
||||
context_->GetBluetoothAdapter().RemoveObserver(this);
|
||||
nearby_fast_initiation_->RemoveObserver(this);
|
||||
@@ -721,7 +718,7 @@ void NearbySharingServiceImpl::SendAttachments(
|
||||
CreateEndpointInfo(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS,
|
||||
local_device_data_manager_->GetDeviceName());
|
||||
if (!endpoint_info) {
|
||||
LOG(WARNING) << "Could not create local endpoint info.";
|
||||
LOG(WARNING) << "Could not create local endpoint info.";
|
||||
std::move(status_codes_callback)(StatusCodes::kError);
|
||||
return;
|
||||
}
|
||||
@@ -1175,12 +1172,11 @@ std::string NearbySharingServiceImpl::Dump() const {
|
||||
preference_manager_,
|
||||
PrefNames::kSchedulerDownloadPublicCertificates)
|
||||
<< std::endl;
|
||||
sstream
|
||||
<< " Upload local device certificates: "
|
||||
<< ConvertToReadableSchedule(
|
||||
preference_manager_,
|
||||
PrefNames::kSchedulerUploadLocalDeviceCertificates)
|
||||
<< std::endl;
|
||||
sstream << " Upload local device certificates: "
|
||||
<< ConvertToReadableSchedule(
|
||||
preference_manager_,
|
||||
PrefNames::kSchedulerUploadLocalDeviceCertificates)
|
||||
<< std::endl;
|
||||
sstream << " Private certificates expiration: "
|
||||
<< ConvertToReadableSchedule(
|
||||
preference_manager_,
|
||||
@@ -1341,15 +1337,14 @@ void NearbySharingServiceImpl::OnLockStateChanged(bool locked) {
|
||||
|
||||
void NearbySharingServiceImpl::AdapterPresentChanged(
|
||||
sharing::api::BluetoothAdapter* adapter, bool present) {
|
||||
RunOnNearbySharingServiceThread(
|
||||
"bt_adapter_present_changed", [this, adapter, present]() {
|
||||
VLOG(1) << "Bluetooth adapter present state changed. (" << present
|
||||
<< ")";
|
||||
NearbySharingService::Observer::AdapterState state =
|
||||
MapAdapterState(present, adapter->IsPowered());
|
||||
service_observers_.NotifyBluetoothStatusChanged(state);
|
||||
InvalidateSurfaceState();
|
||||
});
|
||||
RunOnNearbySharingServiceThread("bt_adapter_present_changed", [this, adapter,
|
||||
present]() {
|
||||
VLOG(1) << "Bluetooth adapter present state changed. (" << present << ")";
|
||||
NearbySharingService::Observer::AdapterState state =
|
||||
MapAdapterState(present, adapter->IsPowered());
|
||||
service_observers_.NotifyBluetoothStatusChanged(state);
|
||||
InvalidateSurfaceState();
|
||||
});
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::AdapterPoweredChanged(
|
||||
@@ -1717,8 +1712,8 @@ void NearbySharingServiceImpl::OnOutgoingDecryptedCertificate(
|
||||
return;
|
||||
}
|
||||
LogShareTargetDiscovered(*share_target);
|
||||
outgoing_targets_manager_.OnShareTargetDiscovered(
|
||||
*share_target, endpoint_id, std::move(certificate));
|
||||
outgoing_targets_manager_.OnShareTargetDiscovered(*share_target, endpoint_id,
|
||||
std::move(certificate));
|
||||
FinishEndpointDiscoveryEvent();
|
||||
}
|
||||
|
||||
@@ -1776,14 +1771,9 @@ bool NearbySharingServiceImpl::HasAvailableConnectionMediums() {
|
||||
bool is_wifi_lan_enabled = NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_sharing_feature::kEnableMediumWifiLan);
|
||||
|
||||
ConnectivityManager::ConnectionType connection_type =
|
||||
context_->GetConnectivityManager()->GetConnectionType();
|
||||
|
||||
bool hasNetworkConnection =
|
||||
connection_type == ConnectivityManager::ConnectionType::kWifi ||
|
||||
connection_type == ConnectivityManager::ConnectionType::kEthernet;
|
||||
|
||||
return IsBluetoothPowered() || (is_wifi_lan_enabled && hasNetworkConnection);
|
||||
return IsBluetoothPowered() ||
|
||||
(is_wifi_lan_enabled &&
|
||||
context_->GetConnectivityManager()->IsLanConnected());
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::InvalidateSurfaceState() {
|
||||
@@ -1975,8 +1965,7 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
|
||||
*endpoint_info,
|
||||
/*listener=*/this, power_level, data_usage,
|
||||
visibility == DeviceVisibility::DEVICE_VISIBILITY_EVERYONE,
|
||||
force_new_endpoint_id_,
|
||||
[this, visibility, data_usage](Status status) {
|
||||
force_new_endpoint_id_, [this, visibility, data_usage](Status status) {
|
||||
// Log analytics event of advertising start.
|
||||
analytics_recorder_.NewAdvertiseDevicePresenceStart(
|
||||
advertising_session_id_, visibility,
|
||||
@@ -3070,8 +3059,8 @@ void NearbySharingServiceImpl::UnregisterShareTarget(int64_t share_target_id) {
|
||||
config_package_nearby::nearby_sharing_feature::
|
||||
kUnregisterTargetDiscoveryCacheLostExpiryMs));
|
||||
if (session != nullptr) {
|
||||
outgoing_targets_manager_.OnShareTargetLost(
|
||||
session->endpoint_id(), cache_retention);
|
||||
outgoing_targets_manager_.OnShareTargetLost(session->endpoint_id(),
|
||||
cache_retention);
|
||||
} else {
|
||||
// Be careful not to clear out the share session map if a new session
|
||||
// was started during the cancellation delay.
|
||||
@@ -3150,15 +3139,11 @@ void NearbySharingServiceImpl::SetInHighVisibility(
|
||||
service_observers_.NotifyHighVisibilityChanged(in_high_visibility_);
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::OnNetworkChanged(
|
||||
nearby::ConnectivityManager::ConnectionType type) {
|
||||
void NearbySharingServiceImpl::OnLanConnectedChanged(bool connected) {
|
||||
on_network_changed_delay_timer_ = std::make_unique<ThreadTimer>(
|
||||
*service_thread_, "on_network_changed_delay_timer",
|
||||
kProcessNetworkChangeTimerDelay,
|
||||
[this]() { StopAdvertisingAndInvalidateSurfaceState(); });
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::OnLanConnectedChanged(bool connected) {
|
||||
RunOnNearbySharingServiceThread(
|
||||
"lan_connection_changed", [this, connected]() {
|
||||
VLOG(1) << __func__
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
#include "sharing/internal/api/preference_manager.h"
|
||||
#include "sharing/internal/api/sharing_platform.h"
|
||||
#include "sharing/internal/api/sharing_rpc_client.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
#include "sharing/internal/public/context.h"
|
||||
#include "sharing/local_device_data/nearby_share_local_device_data_manager.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
@@ -369,7 +368,6 @@ class NearbySharingServiceImpl
|
||||
bool is_initiator_of_cancellation);
|
||||
|
||||
// Monitor connectivity changes.
|
||||
void OnNetworkChanged(nearby::ConnectivityManager::ConnectionType type);
|
||||
void OnLanConnectedChanged(bool connected);
|
||||
|
||||
// Resets all settings of the nearby sharing service.
|
||||
|
||||
@@ -100,7 +100,6 @@
|
||||
namespace nearby::sharing {
|
||||
namespace {
|
||||
|
||||
using ConnectionType = ::nearby::ConnectivityManager::ConnectionType;
|
||||
using SendSurfaceState =
|
||||
::nearby::sharing::NearbySharingService::SendSurfaceState;
|
||||
using ::nearby::sharing::api::MockAppInfo;
|
||||
@@ -448,7 +447,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
SetBluetoothIsPresent(true);
|
||||
SetBluetoothIsPowered(true);
|
||||
SetScreenLocked(false);
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
analytics_recorder_ = std::make_unique<analytics::AnalyticsRecorder>(
|
||||
/*vendor_id=*/0, /*event_logger=*/nullptr);
|
||||
|
||||
@@ -471,11 +470,11 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
nearby_fast_initiation_factory_.reset();
|
||||
}
|
||||
|
||||
void SetConnectionType(ConnectionType type) {
|
||||
void SetLanConnected(bool connected) {
|
||||
FakeConnectivityManager* connectivity_manager =
|
||||
down_cast<FakeConnectivityManager*>(
|
||||
fake_context_.GetConnectivityManager());
|
||||
connectivity_manager->SetConnectionType(type);
|
||||
connectivity_manager->SetLanConnected(connected);
|
||||
}
|
||||
|
||||
std::unique_ptr<NearbySharingServiceImpl> CreateService(
|
||||
@@ -775,7 +774,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
int64_t share_target_id;
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
.WillOnce([&](const ShareTarget& incoming_share_target,
|
||||
@@ -851,7 +850,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
int64_t DiscoverShareTarget(
|
||||
MockTransferUpdateCallback& transfer_callback,
|
||||
MockShareTargetDiscoveredCallback& discovery_callback) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
|
||||
// Start discovering, to ensure a discovery listener is registered.
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1279,16 +1278,13 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
|
||||
struct ValidSendSurfaceTestData {
|
||||
bool bluetooth_enabled;
|
||||
ConnectionType connection_type;
|
||||
bool lan_connected;
|
||||
} kValidSendSurfaceTestData[] = {
|
||||
// No network connection, only bluetooth available
|
||||
{true, ConnectionType::kNone},
|
||||
{true, false},
|
||||
// Wifi available
|
||||
{true, ConnectionType::kWifi},
|
||||
// Ethernet available
|
||||
{true, ConnectionType::kEthernet},
|
||||
// 3G available
|
||||
{true, ConnectionType::k3G}};
|
||||
{true, true},
|
||||
};
|
||||
|
||||
class NearbySharingServiceImplValidSendTest
|
||||
: public NearbySharingServiceImplTest,
|
||||
@@ -1370,7 +1366,7 @@ class TestObserver : public NearbySharingService::Observer {
|
||||
TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertising) {
|
||||
FakeNearbyFastInitiation* fast_initiation =
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1388,7 +1384,7 @@ TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertising) {
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertisingError) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation()
|
||||
@@ -1403,7 +1399,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundStartFastInitiationAdvertisingError) {
|
||||
FakeNearbyFastInitiation* fast_initiation =
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1416,7 +1412,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest, StopFastInitiationAdvertising) {
|
||||
FakeNearbyFastInitiation* fast_initiation =
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1434,7 +1430,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
StopFastInitiationAdvertising_BluetoothBecomesNotPresent) {
|
||||
FakeNearbyFastInitiation* fast_initiation =
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
|
||||
SetConnectionType(ConnectionType::kNone);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1450,7 +1446,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
StopFastInitiationAdvertising_BluetoothBecomesNotPowered) {
|
||||
FakeNearbyFastInitiation* fast_initiation =
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
|
||||
SetConnectionType(ConnectionType::kNone);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1465,7 +1461,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest, FastInitiationScanning_StartAndStop) {
|
||||
FakeNearbyFastInitiation* fast_initiation =
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
|
||||
EXPECT_EQ(fast_initiation->StartScanningCount(), 1);
|
||||
EXPECT_EQ(fast_initiation->StopScanningCount(), 0);
|
||||
@@ -1486,7 +1482,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
FastInitiationScanning_PostTransferCooldown) {
|
||||
FakeNearbyFastInitiation* fast_initiation =
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
|
||||
SetConnectionType(ConnectionType::kBluetooth);
|
||||
SetLanConnected(false);
|
||||
|
||||
// Make sure we started scanning once
|
||||
EXPECT_EQ(fast_initiation->StartScanningCount(), 1);
|
||||
@@ -1508,7 +1504,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundRegisterSendSurfaceStartsDiscovering) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1520,7 +1516,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundRegisterSendSurfaceTwiceKeepsDiscovering) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1556,7 +1552,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundRegisterSendSurfaceNotDiscovering) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1569,7 +1565,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
DifferentSurfaceRegisterSendSurfaceTwiceKeepsDiscovering) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1586,7 +1582,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterSendSurfaceEndpointFoundDiscoveryCallbackNotified) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
|
||||
// Start discovering, to ensure a discovery listener is registered.
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
@@ -1633,7 +1629,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, RegisterSendSurfaceEmptyCertificate) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
|
||||
// Start discovering, to ensure a discovery listener is registered.
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
@@ -1683,7 +1679,7 @@ TEST_F(NearbySharingServiceImplTest, RegisterSendSurfaceEmptyCertificate) {
|
||||
TEST_P(NearbySharingServiceImplValidSendTest,
|
||||
RegisterSendSurfaceIsDiscovering) {
|
||||
SetBluetoothIsPresent(GetParam().bluetooth_enabled);
|
||||
SetConnectionType(GetParam().connection_type);
|
||||
SetLanConnected(GetParam().lan_connected);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1699,7 +1695,7 @@ INSTANTIATE_TEST_SUITE_P(NearbySharingServiceImplTest,
|
||||
testing::ValuesIn(kValidSendSurfaceTestData));
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceStopsDiscovering) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1716,7 +1712,7 @@ TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceStopsDiscovering) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
UnregisterSendSurfaceDifferentCallbackKeepDiscovering) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -1733,7 +1729,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceNeverRegistered) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
@@ -1744,7 +1740,7 @@ TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceNeverRegistered) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundRegisterReceiveSurfaceIsAdvertisingAllContacts) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
::nearby::AccountManager::Account account;
|
||||
account.id = kTestAccountId;
|
||||
@@ -1772,7 +1768,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundRegisterReceiveSurfaceIsAdvertisingNoOne) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_SELF_SHARE);
|
||||
local_device_data_manager()->SetDeviceName(kDeviceName);
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -1798,7 +1794,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundRegisterReceiveSurfaceIsAdvertisingSelectedContacts) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS);
|
||||
::nearby::AccountManager::Account account;
|
||||
account.id = kTestAccountId;
|
||||
@@ -1826,7 +1822,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterReceiveSurfaceTwiceSameCallbackKeepAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -1843,7 +1839,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterReceiveSurfaceTwiceKeepAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -1862,7 +1858,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
DataUsageChangedRegisterReceiveSurfaceRestartsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingDataUsageName,
|
||||
@@ -1890,7 +1886,7 @@ TEST_F(
|
||||
NearbySharingServiceImplTest,
|
||||
UnregisterForegroundReceiveSurfaceVisibilityAllContactsRestartAdvertising) {
|
||||
TestObserver observer(service_.get());
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
@@ -1936,7 +1932,7 @@ TEST_F(
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterReceiveSurfaceWithVendorId_StartAdvertisingVendorId) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE));
|
||||
@@ -1961,7 +1957,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterReceiveSurfaceWithVendorId_DoesNotAdvertiseInContacts) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
@@ -1986,7 +1982,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterReceiveSurfaceWithDifferentVendorIdIsBlocked) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
@@ -2012,7 +2008,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterReceiveSurfaceWithVendorId_OkWithBgNoVendorId) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE));
|
||||
@@ -2057,7 +2053,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, WifiRegisterReceiveSurfaceIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -2069,7 +2065,7 @@ TEST_F(NearbySharingServiceImplTest, WifiRegisterReceiveSurfaceIsAdvertising) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
EthernetRegisterReceiveSurfaceIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kEthernet);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -2081,7 +2077,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ThreeGRegisterReceiveSurfaceIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::k3G);
|
||||
SetLanConnected(false);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -2095,7 +2091,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
NoBluetoothWifiReceiveSurfaceIsAdvertising) {
|
||||
SetBluetoothIsPresent(false);
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -2108,7 +2104,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
NoBluetoothEthernetReceiveSurfaceIsAdvertising) {
|
||||
SetBluetoothIsPresent(false);
|
||||
SetConnectionType(ConnectionType::kEthernet);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -2120,7 +2116,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundReceiveSurfaceNoOneVisibilityIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELF_SHARE));
|
||||
@@ -2135,7 +2131,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceNoOneVisibilityNotAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_SELF_SHARE);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
@@ -2152,7 +2148,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceVisibilityToNoOneStopsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS);
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2173,7 +2169,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest, ValidateLoginStateWhenSettingVisibility) {
|
||||
absl::Notification set_visibility_notification;
|
||||
NearbySharingService::StatusCodes set_visibility_status;
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
FlushTesting();
|
||||
service_->SetVisibility(
|
||||
DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS, absl::ZeroDuration(),
|
||||
@@ -2214,7 +2210,7 @@ TEST_F(NearbySharingServiceImplTest, ValidateLoginStateWhenSettingVisibility) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceVisibilityToAllContactsStartsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_UNSPECIFIED);
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2232,7 +2228,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundReceiveSurfaceSelectedContactsVisibilityIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS));
|
||||
@@ -2247,7 +2243,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceSelectedContactsVisibilityIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS));
|
||||
@@ -2262,7 +2258,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundReceiveSurfaceAllContactsVisibilityIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
@@ -2277,7 +2273,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceAllContactsVisibilityNotAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
@@ -2291,7 +2287,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, UnregisterReceiveSurfaceStopsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -2309,7 +2305,7 @@ TEST_F(NearbySharingServiceImplTest, UnregisterReceiveSurfaceStopsAdvertising) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
UnregisterReceiveSurfaceDifferentCallbackKeepAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -2326,7 +2322,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, UnregisterReceiveSurfaceNeverRegistered) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result =
|
||||
@@ -2340,7 +2336,7 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionClosedAfterShutdown) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
.Times(0);
|
||||
@@ -2361,7 +2357,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -2389,7 +2385,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
.WillOnce([](const ShareTarget& share_target,
|
||||
@@ -2420,7 +2416,7 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionEmptyIntroductionFrame) {
|
||||
GetToken());
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/true);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
.WillOnce([](const ShareTarget& share_target,
|
||||
@@ -2459,7 +2455,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
GetToken());
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -2567,7 +2563,7 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionOutOfStorage) {
|
||||
frame.SerializeToArray(bytes.data(), bytes.size());
|
||||
ReceiveMessageFromConnection(std::move(bytes));
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
.WillOnce([](const ShareTarget& share_target,
|
||||
@@ -2627,7 +2623,7 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionFileSizeOverflow) {
|
||||
frame.SerializeToArray(bytes.data(), bytes.size());
|
||||
ReceiveMessageFromConnection(std::move(bytes));
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -2659,7 +2655,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
GetToken());
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -2954,7 +2950,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
GetToken());
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -2997,7 +2993,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
GetToken());
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
absl::Notification notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
@@ -3044,7 +3040,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
|
||||
SetUpKeyVerification(/*is_incoming=*/true, PairedKeyResultFrame::FAIL);
|
||||
@@ -3076,7 +3072,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
IncomingConnectionEmptyAuthTokenKeyVerificationRunnerStatusFail) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
|
||||
@@ -3769,7 +3765,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TestObserver observer(service_.get());
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanIsConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE);
|
||||
local_device_data_manager()->SetDeviceName(kDeviceName);
|
||||
|
||||
@@ -3906,7 +3902,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, OrderedEndpointDiscoveryEvents) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanIsConnected(true);
|
||||
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
@@ -3977,7 +3973,7 @@ TEST_F(NearbySharingServiceImplTest, OrderedEndpointDiscoveryEvents) {
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RetryDiscoveredEndpointsNoDownloadIfDecryption) {
|
||||
// Start discovery.
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -4007,7 +4003,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, DedupSameEndpointId) {
|
||||
// Start discovery.
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -4053,7 +4049,7 @@ TEST_F(NearbySharingServiceImplTest, DedupSameEndpointId) {
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
OnLostDedupSameEndpointIdBeforeExpiryNoOnShareTargetLost) {
|
||||
// Start discovery.
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -4108,7 +4104,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, OnLostDedupSameEndpointIdAfterExpiry) {
|
||||
// Start discovery.
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -4176,7 +4172,7 @@ TEST_F(NearbySharingServiceImplTest, EndpointDedupBasedOnDeviceId) {
|
||||
kDiscoveryCacheLostExpiryMs,
|
||||
20000); // 20s
|
||||
// Start discovery.
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -4333,7 +4329,7 @@ TEST_F(NearbySharingServiceImplTest, EndpointDedupBasedOnDeviceId) {
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RetryDiscoveredEndpointsDiscoveryRestartClearsCache) {
|
||||
// Start discovery.
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -4374,7 +4370,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RetryDiscoveredEndpointsWhenCannotDecrypted) {
|
||||
// Start discovery.
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -4412,7 +4408,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, RetryDiscoveredEndpointsDownloadLimit) {
|
||||
// Start discovery.
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -4464,7 +4460,7 @@ TEST_F(NearbySharingServiceImplTest, RetryDiscoveredEndpointsDownloadLimit) {
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ScreenLockedRegisterReceiveSurfaceNotAdvertising) {
|
||||
SetScreenLocked(true);
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
&callback, NearbySharingService::ReceiveSurfaceState::kForeground);
|
||||
@@ -4496,7 +4492,7 @@ TEST_F(NearbySharingServiceImplTest, BlockTargetWithSameVendorId) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterSendSurfaceWithDifferentVendorIdIsBlocked) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
@@ -4523,7 +4519,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, ScreenLocksDuringAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -4543,7 +4539,7 @@ TEST_F(NearbySharingServiceImplTest, ScreenLocksDuringAdvertising) {
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, ScreenLocksDuringDiscovery) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
@@ -4680,7 +4676,7 @@ TEST_F(NearbySharingServiceImplTest, ObserveAccountLoginAndLogout) {
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, LoginAndLogoutShouldResetSettings) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
|
||||
// Used to check whether the setting is cleared after login.
|
||||
service_->GetSettings()->SetIsAnalyticsEnabled(true);
|
||||
@@ -4728,7 +4724,7 @@ TEST_F(NearbySharingServiceImplTest, LoginAndLogoutShouldResetSettings) {
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, LoginShouldSetContactsVisibility) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
|
||||
// Create account.
|
||||
AccountManager::Account account;
|
||||
@@ -4747,7 +4743,7 @@ TEST_F(NearbySharingServiceImplTest, LoginShouldSetContactsVisibility) {
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, LogoutShouldSetValidVisibility) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
|
||||
// Create account.
|
||||
AccountManager::Account account;
|
||||
@@ -4801,7 +4797,7 @@ TEST_F(NearbySharingServiceImplTest, LogoutShouldSetValidVisibility) {
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, LoginAndLogoutNoStopRunningSurfaces) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetLanConnected(true);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
|
||||
|
||||
@@ -78,10 +78,8 @@ NearbyShareSchedulerBase::NearbyShareSchedulerBase(
|
||||
}
|
||||
|
||||
if (require_connectivity_) {
|
||||
connectivity_manager_->RegisterConnectionListener(
|
||||
connection_listener_name_,
|
||||
[this](nearby::ConnectivityManager::ConnectionType connection_type,
|
||||
bool is_lan_connected, bool is_internet_connected) {
|
||||
connectivity_manager_->RegisterInternetListener(
|
||||
connection_listener_name_, [this](bool is_internet_connected) {
|
||||
OnInternetConnectivityChanged(is_internet_connected);
|
||||
});
|
||||
}
|
||||
@@ -89,7 +87,7 @@ NearbyShareSchedulerBase::NearbyShareSchedulerBase(
|
||||
|
||||
NearbyShareSchedulerBase::~NearbyShareSchedulerBase() {
|
||||
if (require_connectivity_) {
|
||||
connectivity_manager_->UnregisterConnectionListener(
|
||||
connectivity_manager_->UnregisterInternetListener(
|
||||
connection_listener_name_);
|
||||
}
|
||||
}
|
||||
@@ -154,8 +152,7 @@ absl::Duration NearbyShareSchedulerBase::GetTimeUntilNextRequest() const {
|
||||
|
||||
// Recover from failures using exponential backoff strategy if necessary.
|
||||
absl::Duration time_until_retry = TimeUntilRetry(now);
|
||||
if (time_until_retry != absl::InfiniteDuration())
|
||||
return time_until_retry;
|
||||
if (time_until_retry != absl::InfiniteDuration()) return time_until_retry;
|
||||
|
||||
// Schedule the periodic request if applicable.
|
||||
return TimeUntilRecurringRequest(now);
|
||||
@@ -184,9 +181,7 @@ size_t NearbyShareSchedulerBase::GetNumConsecutiveFailures() const {
|
||||
return pref_value.value();
|
||||
}
|
||||
|
||||
void NearbyShareSchedulerBase::OnStart() {
|
||||
Reschedule();
|
||||
}
|
||||
void NearbyShareSchedulerBase::OnStart() { Reschedule(); }
|
||||
|
||||
void NearbyShareSchedulerBase::OnStop() { timer_->Stop(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user