mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Remove Get/SetEnabled from API
PiperOrigin-RevId: 650353129
This commit is contained in:
committed by
Copybara-Service
parent
2e0996ee7f
commit
20f0904a83
@@ -52,8 +52,6 @@ ABSL_CONST_INIT const char kNearbySharingDeviceIdName[] =
|
||||
"nearby_sharing.device_id";
|
||||
ABSL_CONST_INIT const char kNearbySharingDeviceNameName[] =
|
||||
"nearby_sharing.device_name";
|
||||
ABSL_CONST_INIT const char kNearbySharingEnabledName[] =
|
||||
"nearby_sharing.enabled";
|
||||
ABSL_CONST_INIT const char kNearbySharingFastInitiationNotificationStateName[] =
|
||||
"nearby_sharing.fast_initiation_notification_state";
|
||||
ABSL_CONST_INIT const char kNearbySharingOnboardingCompleteName[] =
|
||||
@@ -105,7 +103,6 @@ void RegisterNearbySharingPrefs(PreferenceManager& preference_manager,
|
||||
// During logging out, we reset all settings and set these settings to new
|
||||
// values. To avoid setting them twice, we skip them here if
|
||||
// skip_persistent_ones is set to true.
|
||||
preference_manager.SetBoolean(kNearbySharingEnabledName, false);
|
||||
preference_manager.SetString(kNearbySharingCustomSavePath, std::string());
|
||||
preference_manager.SetBoolean(kNearbySharingOnboardingCompleteName, false);
|
||||
preference_manager.SetInteger(kNearbySharingBackgroundVisibilityName,
|
||||
|
||||
@@ -33,7 +33,6 @@ ABSL_CONST_INIT extern const char kNearbySharingCustomSavePath[];
|
||||
ABSL_CONST_INIT extern const char kNearbySharingDataUsageName[];
|
||||
ABSL_CONST_INIT extern const char kNearbySharingDeviceIdName[];
|
||||
ABSL_CONST_INIT extern const char kNearbySharingDeviceNameName[];
|
||||
ABSL_CONST_INIT extern const char kNearbySharingEnabledName[];
|
||||
ABSL_CONST_INIT extern const char
|
||||
kNearbySharingFastInitiationNotificationStateName[];
|
||||
ABSL_CONST_INIT extern const char kNearbySharingOnboardingCompleteName[];
|
||||
|
||||
@@ -264,12 +264,9 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
|
||||
NL_LOG(INFO) << __func__ << ": Set custom save path: " << custom_save_path;
|
||||
nearby_connections_manager_->SetCustomSavePath(custom_save_path);
|
||||
|
||||
if (settings_->GetEnabled()) {
|
||||
local_device_data_manager_->Start();
|
||||
contact_manager_->Start();
|
||||
certificate_manager_->Start();
|
||||
}
|
||||
|
||||
local_device_data_manager_->Start();
|
||||
contact_manager_->Start();
|
||||
certificate_manager_->Start();
|
||||
update_file_paths_in_progress_ = false;
|
||||
|
||||
SetupBluetoothAdapter();
|
||||
@@ -313,11 +310,9 @@ void NearbySharingServiceImpl::Shutdown(
|
||||
|
||||
settings_->RemoveSettingsObserver(this);
|
||||
|
||||
if (settings_->GetEnabled()) {
|
||||
local_device_data_manager_->Stop();
|
||||
contact_manager_->Stop();
|
||||
certificate_manager_->Stop();
|
||||
}
|
||||
local_device_data_manager_->Stop();
|
||||
contact_manager_->Stop();
|
||||
certificate_manager_->Stop();
|
||||
|
||||
is_shutting_down_ = nullptr;
|
||||
std::move(status_codes_callback)(StatusCodes::kOk);
|
||||
@@ -1297,10 +1292,7 @@ std::string NearbySharingServiceImpl::Dump() const {
|
||||
// Private methods for NearbyShareSettings::Observer.
|
||||
void NearbySharingServiceImpl::OnSettingChanged(absl::string_view key,
|
||||
const Data& data) {
|
||||
if (key == prefs::kNearbySharingEnabledName) {
|
||||
bool enabled = data.value.as_bool;
|
||||
OnEnabledChanged(enabled);
|
||||
} else if (key == prefs::kNearbySharingDataUsageName) {
|
||||
if (key == prefs::kNearbySharingDataUsageName) {
|
||||
DataUsage data_usage = static_cast<DataUsage>(data.value.as_int64);
|
||||
OnDataUsageChanged(data_usage);
|
||||
} else if (key == prefs::kNearbySharingCustomSavePath) {
|
||||
@@ -1316,27 +1308,6 @@ void NearbySharingServiceImpl::OnSettingChanged(absl::string_view key,
|
||||
}
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::OnEnabledChanged(bool enabled) {
|
||||
RunOnNearbySharingServiceThread("on_enabled_changed", [this, enabled]() {
|
||||
if (enabled) {
|
||||
NL_VLOG(1) << __func__ << ": Nearby sharing enabled!";
|
||||
local_device_data_manager_->Start();
|
||||
contact_manager_->Start();
|
||||
certificate_manager_->Start();
|
||||
} else {
|
||||
NL_VLOG(1) << __func__ << ": Nearby sharing disabled!";
|
||||
StopAdvertising();
|
||||
StopScanning();
|
||||
nearby_connections_manager_->Shutdown();
|
||||
local_device_data_manager_->Stop();
|
||||
contact_manager_->Stop();
|
||||
certificate_manager_->Stop();
|
||||
}
|
||||
|
||||
InvalidateSurfaceState();
|
||||
});
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::OnDataUsageChanged(DataUsage data_usage) {
|
||||
RunOnNearbySharingServiceThread(
|
||||
"on_data_usage_changed", [this, data_usage]() {
|
||||
@@ -1956,14 +1927,6 @@ void NearbySharingServiceImpl::InvalidateScanningState() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Nearby Sharing is disabled. Don't advertise.
|
||||
if (!settings_->GetEnabled()) {
|
||||
StopScanning();
|
||||
NL_VLOG(1) << __func__
|
||||
<< ": Stopping discovery because Nearby Sharing is disabled.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_transferring_ || is_connecting_) {
|
||||
StopScanning();
|
||||
NL_VLOG(1)
|
||||
@@ -2004,15 +1967,6 @@ void NearbySharingServiceImpl::InvalidateFastInitiationAdvertising() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Nearby Sharing is disabled. Don't advertise.
|
||||
if (!settings_->GetEnabled()) {
|
||||
StopFastInitiationAdvertising();
|
||||
NL_VLOG(1) << __func__
|
||||
<< ": Stopping fast initiation advertising because Nearby "
|
||||
"Sharing is disabled.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_transferring_ || is_connecting_) {
|
||||
StopFastInitiationAdvertising();
|
||||
NL_VLOG(1) << __func__
|
||||
@@ -2059,14 +2013,6 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Nearby Sharing is disabled. Don't advertise.
|
||||
if (!settings_->GetEnabled()) {
|
||||
StopAdvertising();
|
||||
NL_VLOG(1) << __func__
|
||||
<< ": Stopping advertising because Nearby Sharing is disabled.";
|
||||
return;
|
||||
}
|
||||
|
||||
// We're scanning for other nearby devices. Don't advertise.
|
||||
if (is_scanning_) {
|
||||
StopAdvertising();
|
||||
@@ -2203,7 +2149,6 @@ void NearbySharingServiceImpl::StopAdvertising() {
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::StartScanning() {
|
||||
NL_DCHECK(settings_->GetEnabled());
|
||||
NL_DCHECK(!is_screen_locked_);
|
||||
NL_DCHECK(HasAvailableConnectionMediums());
|
||||
NL_DCHECK(!foreground_send_surface_map_.empty());
|
||||
@@ -2298,14 +2243,6 @@ void NearbySharingServiceImpl::InvalidateFastInitiationScanning() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!settings_->GetEnabled()) {
|
||||
NL_VLOG(1) << __func__
|
||||
<< ": Stopping background scanning because Nearby Sharing "
|
||||
"is disabled";
|
||||
StopFastInitiationScanning();
|
||||
return;
|
||||
}
|
||||
|
||||
// Screen is off. Do no work.
|
||||
if (is_screen_locked_) {
|
||||
NL_VLOG(1)
|
||||
|
||||
@@ -205,7 +205,6 @@ class NearbySharingServiceImpl
|
||||
void OnSettingChanged(absl::string_view key, const Data& data) override;
|
||||
void OnIsFastInitiationHardwareSupportedChanged(bool is_supported) override {}
|
||||
|
||||
void OnEnabledChanged(bool enabled);
|
||||
void OnDeviceNameChanged(absl::string_view device_name);
|
||||
void OnDataUsageChanged(proto::DataUsage data_usage);
|
||||
void OnCustomSavePathChanged(absl::string_view custom_save_path);
|
||||
|
||||
@@ -434,8 +434,6 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
|
||||
std::unique_ptr<NearbySharingServiceImpl> CreateService(
|
||||
std::unique_ptr<FakeTaskRunner> task_runner) {
|
||||
preference_manager_.SetBoolean(prefs::kNearbySharingEnabledName, true);
|
||||
|
||||
fake_nearby_connections_manager_ = new FakeNearbyConnectionsManager();
|
||||
return std::make_unique<NearbySharingServiceImpl>(
|
||||
/*vendor_id=*/0, std::move(task_runner), &fake_context_,
|
||||
@@ -448,11 +446,6 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
FlushTesting();
|
||||
}
|
||||
|
||||
void SetIsEnabled(bool is_enabled) {
|
||||
service_->GetSettings()->SetEnabled(is_enabled);
|
||||
FlushTesting();
|
||||
}
|
||||
|
||||
void SetFastInitiationNotificationState(
|
||||
FastInitiationNotificationState state) {
|
||||
service_->GetSettings()->SetFastInitiationNotificationState(state);
|
||||
@@ -1398,13 +1391,6 @@ class TestObserver : public NearbySharingService::Observer {
|
||||
AdapterState lan_state_ = AdapterState::INVALID;
|
||||
};
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, DisableNearbyShutdownConnections) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetBoolean(prefs::kNearbySharingEnabledName, false);
|
||||
FlushTesting();
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->is_shutdown());
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertising) {
|
||||
FakeNearbyFastInitiation* fast_initiation =
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
|
||||
@@ -1536,21 +1522,6 @@ TEST_F(NearbySharingServiceImplTest, FastInitiationScanning_StartAndStop) {
|
||||
EXPECT_EQ(fast_initiation->StopScanningCount(), 1);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
FastInitiationScanning_DisallowedBySettings) {
|
||||
FakeNearbyFastInitiation* fast_initiation =
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
|
||||
|
||||
EXPECT_EQ(fast_initiation->StartScanningCount(), 1);
|
||||
EXPECT_EQ(fast_initiation->StopScanningCount(), 0);
|
||||
|
||||
SetIsEnabled(false);
|
||||
SetConnectionType(ConnectionType::kBluetooth);
|
||||
|
||||
EXPECT_EQ(fast_initiation->StartScanningCount(), 1);
|
||||
EXPECT_EQ(fast_initiation->StopScanningCount(), 1);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, FastInitiationScanning_NotifyObservers) {
|
||||
FakeNearbyFastInitiation* fast_initiation =
|
||||
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
|
||||
@@ -1792,35 +1763,6 @@ INSTANTIATE_TEST_SUITE_P(NearbySharingServiceImplTest,
|
||||
NearbySharingServiceImplValidSendTest,
|
||||
testing::ValuesIn(kValidSendSurfaceTestData));
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, DisableFeatureSendSurfaceNotDiscovering) {
|
||||
preference_manager().SetBoolean(prefs::kNearbySharingEnabledName, false);
|
||||
FlushTesting();
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
SendSurfaceState::kForeground),
|
||||
NearbySharingService::StatusCodes::kOk);
|
||||
EXPECT_FALSE(fake_nearby_connections_manager_->IsDiscovering());
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->is_shutdown());
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
DisableFeatureSendSurfaceStopsDiscovering) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
SendSurfaceState::kForeground),
|
||||
NearbySharingService::StatusCodes::kOk);
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
|
||||
|
||||
preference_manager().SetBoolean(prefs::kNearbySharingEnabledName, false);
|
||||
FlushTesting();
|
||||
EXPECT_FALSE(fake_nearby_connections_manager_->IsDiscovering());
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->is_shutdown());
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceStopsDiscovering) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
@@ -2236,35 +2178,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_FALSE(fake_nearby_connections_manager_->is_shutdown());
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
DisableFeatureReceiveSurfaceNotAdvertising) {
|
||||
preference_manager().SetBoolean(prefs::kNearbySharingEnabledName, false);
|
||||
FlushTesting();
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
&callback, NearbySharingService::ReceiveSurfaceState::kForeground);
|
||||
EXPECT_EQ(result, NearbySharingService::StatusCodes::kOk);
|
||||
EXPECT_FALSE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->is_shutdown());
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
DisableFeatureReceiveSurfaceStopsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
&callback, NearbySharingService::ReceiveSurfaceState::kForeground);
|
||||
EXPECT_EQ(result, NearbySharingService::StatusCodes::kOk);
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
|
||||
preference_manager().SetBoolean(prefs::kNearbySharingEnabledName, false);
|
||||
FlushTesting();
|
||||
EXPECT_FALSE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->is_shutdown());
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundReceiveSurfaceNoOneVisibilityIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
|
||||
@@ -110,12 +110,6 @@ NearbyShareSettings::~NearbyShareSettings() {
|
||||
visibility_expiration_timer_->Stop();
|
||||
}
|
||||
|
||||
bool NearbyShareSettings::GetEnabled() const {
|
||||
MutexLock lock(&mutex_);
|
||||
return preference_manager_.GetBoolean(prefs::kNearbySharingEnabledName,
|
||||
false);
|
||||
}
|
||||
|
||||
FastInitiationNotificationState
|
||||
NearbyShareSettings::GetFastInitiationNotificationState() const {
|
||||
MutexLock lock(&mutex_);
|
||||
@@ -213,7 +207,7 @@ std::string NearbyShareSettings::GetCustomSavePath() const {
|
||||
GetCompatibleU8String(device_info_.GetDownloadPath().u8string()));
|
||||
}
|
||||
|
||||
bool NearbyShareSettings::IsDisabledByPolicy() const { return !GetEnabled(); }
|
||||
bool NearbyShareSettings::IsDisabledByPolicy() const { return false; }
|
||||
|
||||
void NearbyShareSettings::AddSettingsObserver(Observer* observer) {
|
||||
MutexLock lock(&mutex_);
|
||||
@@ -225,10 +219,6 @@ void NearbyShareSettings::RemoveSettingsObserver(Observer* observer) {
|
||||
observers_set_.RemoveObserver(observer);
|
||||
}
|
||||
|
||||
void NearbyShareSettings::GetEnabled(std::function<void(bool)> callback) {
|
||||
std::move(callback)(GetEnabled());
|
||||
}
|
||||
|
||||
void NearbyShareSettings::GetFastInitiationNotificationState(
|
||||
std::function<void(FastInitiationNotificationState)> callback) {
|
||||
std::move(callback)(GetFastInitiationNotificationState());
|
||||
@@ -240,18 +230,6 @@ void NearbyShareSettings::GetIsFastInitiationHardwareSupported(
|
||||
std::move(callback)(is_fast_initiation_hardware_supported_);
|
||||
}
|
||||
|
||||
void NearbyShareSettings::SetEnabled(bool enabled) {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
preference_manager_.SetBoolean(prefs::kNearbySharingEnabledName, enabled);
|
||||
if (enabled &&
|
||||
GetVisibility() == DeviceVisibility::DEVICE_VISIBILITY_UNSPECIFIED) {
|
||||
NL_LOG(ERROR) << "Nearby Share enabled with visibility unset. Setting "
|
||||
"default visibility to kEveryone.";
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE);
|
||||
}
|
||||
}
|
||||
|
||||
void NearbyShareSettings::SetFastInitiationNotificationState(
|
||||
FastInitiationNotificationState state) {
|
||||
MutexLock lock(&mutex_);
|
||||
@@ -438,10 +416,7 @@ void NearbyShareSettings::SetCustomSavePathAsync(
|
||||
|
||||
void NearbyShareSettings::OnPreferenceChanged(absl::string_view key) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (key == prefs::kNearbySharingEnabledName) {
|
||||
NotifyAllObservers(key, Observer::Data(GetEnabled()));
|
||||
ProcessFastInitiationNotificationParentPrefChanged(GetEnabled());
|
||||
} else if (key == prefs::kNearbySharingFastInitiationNotificationStateName) {
|
||||
if (key == prefs::kNearbySharingFastInitiationNotificationStateName) {
|
||||
NotifyAllObservers(key, Observer::Data(static_cast<int64_t>(
|
||||
GetFastInitiationNotificationState())));
|
||||
} else if (key == prefs::kNearbySharingBackgroundVisibilityName) {
|
||||
@@ -478,25 +453,6 @@ void NearbyShareSettings::NotifyAllObservers(absl::string_view key,
|
||||
}
|
||||
}
|
||||
|
||||
void NearbyShareSettings::ProcessFastInitiationNotificationParentPrefChanged(
|
||||
bool enabled) {
|
||||
// If onboarding is not yet complete the Nearby feature should not be able
|
||||
// to affect the enabled state.
|
||||
if (!IsOnboardingComplete()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the user explicitly disabled notifications, toggling the Nearby Share
|
||||
// feature does not re-enable the notification sub-feature.
|
||||
if (GetFastInitiationNotificationState() ==
|
||||
FastInitiationNotificationState::DISABLED_BY_USER_FAST_INIT) {
|
||||
return;
|
||||
}
|
||||
SetFastInitiationNotificationState(
|
||||
enabled ? FastInitiationNotificationState::ENABLED_FAST_INIT
|
||||
: FastInitiationNotificationState::DISABLED_BY_FEATURE_FAST_INIT);
|
||||
}
|
||||
|
||||
bool NearbyShareSettings::GetIsAnalyticsEnabled() {
|
||||
MutexLock lock(&mutex_);
|
||||
return preference_manager_.GetBoolean(
|
||||
@@ -516,8 +472,6 @@ std::string NearbyShareSettings::Dump() const {
|
||||
sstream << " Device name: " << GetDeviceName() << std::endl;
|
||||
sstream << " Visibility: " << DeviceVisibility_Name(GetVisibility())
|
||||
<< std::endl;
|
||||
sstream << " Enabled: " << std::boolalpha << GetEnabled() << std::noboolalpha
|
||||
<< std::endl;
|
||||
sstream << " FastInitiationNotification: "
|
||||
<< FastInitiationNotificationState_Name(
|
||||
GetFastInitiationNotificationState())
|
||||
|
||||
@@ -166,7 +166,6 @@ class NearbyShareSettings
|
||||
~NearbyShareSettings() override;
|
||||
|
||||
// Internal synchronous getters for C++ clients
|
||||
bool GetEnabled() const;
|
||||
proto::FastInitiationNotificationState GetFastInitiationNotificationState()
|
||||
const;
|
||||
bool is_fast_initiation_hardware_supported();
|
||||
@@ -188,11 +187,9 @@ class NearbyShareSettings
|
||||
// Asynchronous APIs exposed by NearbyShareSettings
|
||||
void AddSettingsObserver(Observer* observer);
|
||||
void RemoveSettingsObserver(Observer* observer);
|
||||
void GetEnabled(std::function<void(bool)> callback);
|
||||
void GetFastInitiationNotificationState(
|
||||
std::function<void(proto::FastInitiationNotificationState)> callback);
|
||||
void GetIsFastInitiationHardwareSupported(std::function<void(bool)> callback);
|
||||
void SetEnabled(bool enabled);
|
||||
void SetFastInitiationNotificationState(
|
||||
proto::FastInitiationNotificationState state);
|
||||
void IsOnboardingComplete(std::function<void(bool)> callback);
|
||||
@@ -251,12 +248,6 @@ class NearbyShareSettings
|
||||
void NotifyAllObservers(absl::string_view key, Observer::Data value)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
// If the Nearby Share parent feature is toggled on then Fast Initiation
|
||||
// notifications should be re-enabled unless the user explicitly disabled the
|
||||
// notification sub-feature.
|
||||
void ProcessFastInitiationNotificationParentPrefChanged(bool enabled)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
void StartVisibilityTimer(absl::Duration expiration) const
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
|
||||
@@ -51,10 +51,7 @@ class FakeNearbyShareSettingsObserver : public NearbyShareSettings::Observer {
|
||||
public:
|
||||
void OnSettingChanged(absl::string_view key, const Data& data) override {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
if (key == prefs::kNearbySharingEnabledName) {
|
||||
enabled_ = data.value.as_bool;
|
||||
} else if (key ==
|
||||
prefs::kNearbySharingFastInitiationNotificationStateName) {
|
||||
if (key == prefs::kNearbySharingFastInitiationNotificationStateName) {
|
||||
fast_initiation_notification_state_ =
|
||||
static_cast<FastInitiationNotificationState>(data.value.as_int64);
|
||||
} else if (key == prefs::kNearbySharingDataUsageName) {
|
||||
@@ -75,16 +72,6 @@ class FakeNearbyShareSettingsObserver : public NearbyShareSettings::Observer {
|
||||
is_fast_initiation_notification_hardware_supported_ = is_supported;
|
||||
}
|
||||
|
||||
bool enabled() const {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
void set_enabled(bool enabled) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
enabled_ = enabled;
|
||||
}
|
||||
|
||||
FastInitiationNotificationState fast_initiation_notification_state() const {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
return fast_initiation_notification_state_;
|
||||
@@ -123,7 +110,6 @@ class FakeNearbyShareSettingsObserver : public NearbyShareSettings::Observer {
|
||||
private:
|
||||
mutable absl::Mutex mutex_;
|
||||
|
||||
bool enabled_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
FastInitiationNotificationState fast_initiation_notification_state_
|
||||
ABSL_GUARDED_BY(mutex_) =
|
||||
FastInitiationNotificationState::ENABLED_FAST_INIT;
|
||||
@@ -197,36 +183,6 @@ class NearbyShareSettingsTest : public ::testing::Test {
|
||||
std::unique_ptr<NearbyShareSettings> nearby_share_settings_;
|
||||
};
|
||||
|
||||
TEST_F(NearbyShareSettingsTest, GetAndSetEnabled) {
|
||||
EXPECT_EQ(observer_.enabled(), false);
|
||||
settings()->SetIsOnboardingComplete(true, []() {});
|
||||
settings()->SetEnabled(true);
|
||||
EXPECT_EQ(settings()->GetEnabled(), true);
|
||||
Flush();
|
||||
EXPECT_EQ(observer_.enabled(), true);
|
||||
|
||||
bool enabled = false;
|
||||
settings()->GetEnabled([&enabled](bool result) { enabled = result; });
|
||||
EXPECT_EQ(enabled, true);
|
||||
|
||||
settings()->SetEnabled(false);
|
||||
EXPECT_EQ(settings()->GetEnabled(), false);
|
||||
Flush();
|
||||
EXPECT_EQ(observer_.enabled(), false);
|
||||
|
||||
settings()->GetEnabled([&enabled](bool result) { enabled = result; });
|
||||
EXPECT_EQ(enabled, false);
|
||||
|
||||
// Verify that setting the value to false again value doesn't trigger an
|
||||
// observer event.
|
||||
observer_.set_enabled(true);
|
||||
settings()->SetEnabled(false);
|
||||
EXPECT_EQ(settings()->GetEnabled(), false);
|
||||
Flush();
|
||||
// the observers' value should not have been updated.
|
||||
EXPECT_EQ(observer_.enabled(), true);
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareSettingsTest, GetAndSetFastInitiationNotificationState) {
|
||||
// Fast init notifications are enabled by default.
|
||||
EXPECT_EQ(observer_.fast_initiation_notification_state(),
|
||||
@@ -246,53 +202,6 @@ TEST_F(NearbyShareSettingsTest, GetAndSetFastInitiationNotificationState) {
|
||||
EXPECT_EQ(state, FastInitiationNotificationState::DISABLED_BY_USER_FAST_INIT);
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareSettingsTest,
|
||||
ParentFeatureChangesFastInitiationNotificationState) {
|
||||
// Fast init notifications are enabled by default.
|
||||
EXPECT_EQ(observer_.fast_initiation_notification_state(),
|
||||
FastInitiationNotificationState::ENABLED_FAST_INIT);
|
||||
settings()->SetIsOnboardingComplete(true, []() {});
|
||||
settings()->SetEnabled(true);
|
||||
Flush();
|
||||
|
||||
// Simulate toggling the parent feature off.
|
||||
settings()->SetEnabled(false);
|
||||
Flush();
|
||||
EXPECT_FALSE(settings()->GetEnabled());
|
||||
EXPECT_EQ(observer_.fast_initiation_notification_state(),
|
||||
FastInitiationNotificationState::DISABLED_BY_FEATURE_FAST_INIT);
|
||||
|
||||
// Simulate toggling the parent feature on.
|
||||
settings()->SetEnabled(true);
|
||||
Flush();
|
||||
EXPECT_TRUE(settings()->GetEnabled());
|
||||
EXPECT_EQ(observer_.fast_initiation_notification_state(),
|
||||
FastInitiationNotificationState::ENABLED_FAST_INIT);
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareSettingsTest,
|
||||
ParentFeatureChangesFastInitiationNotificationDisabledByUser) {
|
||||
// Fast init notifications are enabled by default.
|
||||
EXPECT_EQ(observer_.fast_initiation_notification_state(),
|
||||
FastInitiationNotificationState::ENABLED_FAST_INIT);
|
||||
|
||||
// Set explicitly disabled by user.
|
||||
settings()->SetFastInitiationNotificationState(
|
||||
FastInitiationNotificationState::DISABLED_BY_USER_FAST_INIT);
|
||||
Flush();
|
||||
EXPECT_EQ(observer_.fast_initiation_notification_state(),
|
||||
FastInitiationNotificationState::DISABLED_BY_USER_FAST_INIT);
|
||||
|
||||
// Simulate toggling parent feature on.
|
||||
settings()->SetIsOnboardingComplete(true, []() {});
|
||||
settings()->SetEnabled(true);
|
||||
Flush();
|
||||
|
||||
// The disabled by user flag should persist if the parent feature is enabled.
|
||||
EXPECT_EQ(observer_.fast_initiation_notification_state(),
|
||||
FastInitiationNotificationState::DISABLED_BY_USER_FAST_INIT);
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareSettingsTest, GetAndSetCustomSavePath) {
|
||||
absl::Notification notification;
|
||||
settings()->SetCustomSavePathAsync(
|
||||
|
||||
Reference in New Issue
Block a user