Remove FastInitiation scanning.

PiperOrigin-RevId: 843401331
This commit is contained in:
Francis Tsui
2025-12-11 15:36:23 -08:00
committed by Copybara-Service
parent d262f64219
commit 8dfdb44e7c
3 changed files with 0 additions and 157 deletions
-104
View File
@@ -301,7 +301,6 @@ void NearbySharingServiceImpl::Shutdown(
service_observers_.Clear();
StopAdvertising();
StopFastInitiationScanning();
StopFastInitiationAdvertising();
StopScanning();
nearby_connections_manager_->Shutdown();
@@ -1869,7 +1868,6 @@ void NearbySharingServiceImpl::InvalidateFastInitiationAdvertising() {
void NearbySharingServiceImpl::InvalidateReceiveSurfaceState() {
InvalidateAdvertisingState();
InvalidateFastInitiationScanning();
}
void NearbySharingServiceImpl::InvalidateAdvertisingState() {
@@ -2097,102 +2095,6 @@ void NearbySharingServiceImpl::StopAdvertisingAndInvalidateSurfaceState() {
InvalidateSurfaceState();
}
void NearbySharingServiceImpl::InvalidateFastInitiationScanning() {
bool is_hardware_offloading_supported =
IsBluetoothPresent() && nearby_fast_initiation_->IsScanOffloadSupported();
// Hardware offloading support is computed when the bluetooth adapter becomes
// available. We set the hardware supported state on |settings_| to notify the
// UI of state changes. InvalidateFastInitiationScanning gets triggered on
// adapter change events.
settings_->SetIsFastInitiationHardwareSupported(
is_hardware_offloading_supported);
if (fast_initiation_scanner_cooldown_timer_ &&
fast_initiation_scanner_cooldown_timer_->IsRunning()) {
VLOG(1) << __func__
<< ": Stopping background scanning due to post-transfer "
"cooldown period";
StopFastInitiationScanning();
return;
}
// Screen is off. Do no work.
if (is_screen_locked_) {
VLOG(1) << __func__
<< ": Stopping background scanning because the screen is locked.";
StopFastInitiationScanning();
return;
}
if (!IsBluetoothPowered()) {
VLOG(1)
<< __func__
<< ": Stopping background scanning because bluetooth is powered down.";
StopFastInitiationScanning();
return;
}
// We're scanning for other nearby devices. Don't background scan.
if (is_scanning_) {
VLOG(1) << __func__
<< ": Stopping background scanning because we're scanning "
"for other devices.";
StopFastInitiationScanning();
return;
}
if (is_transferring_) {
VLOG(1) << __func__
<< ": Stopping background scanning because we're currently "
"in the midst of a transfer.";
StopFastInitiationScanning();
return;
}
if (advertising_power_level_ == PowerLevel::kHighPower) {
VLOG(1) << __func__
<< ": Stopping background scanning because we're already "
"in high visibility mode.";
StopFastInitiationScanning();
return;
}
if (!is_hardware_offloading_supported) {
VLOG(1) << __func__
<< ": Stopping background scanning because hardware "
"support is not available or not ready.";
StopFastInitiationScanning();
return;
}
StartFastInitiationScanning();
}
void NearbySharingServiceImpl::StartFastInitiationScanning() {
VLOG(1) << __func__ << ": Starting background scanning.";
if (nearby_fast_initiation_->IsScanning()) {
return;
}
nearby_fast_initiation_->StartScanning(
/*devices_discovered_callback=*/[]() {},
/*devices_not_discovered_callback=*/[]() {},
[this]() { StopFastInitiationScanning(); });
}
void NearbySharingServiceImpl::StopFastInitiationScanning() {
VLOG(1) << __func__ << ": Stop fast initiation scanning.";
if (!nearby_fast_initiation_->IsScanning()) {
return;
}
nearby_fast_initiation_->StopScanning(
[]() { VLOG(1) << __func__ << ": Stopped fast initiation scanning."; });
VLOG(1) << __func__ << ": Stopped background scanning.";
}
void NearbySharingServiceImpl::ScheduleRotateBackgroundAdvertisementTimer() {
absl::BitGen bitgen;
uint64_t delayMilliseconds = absl::Uniform(
@@ -2906,12 +2808,6 @@ void NearbySharingServiceImpl::OnIncomingFilesMetadataUpdated(
// ShareTarget already disconnected.
return;
}
fast_initiation_scanner_cooldown_timer_ = std::make_unique<ThreadTimer>(
*service_thread_, "fast_initiation_scanner_cooldown_timer",
kFastInitiationScannerCooldown, [this]() {
fast_initiation_scanner_cooldown_timer_.reset();
InvalidateFastInitiationScanning();
});
// Make sure to call this before calling Disconnect, or we risk losing
// some transfer updates in the receive case due to the Disconnect call
// cleaning up share targets.
-9
View File
@@ -277,11 +277,6 @@ class NearbySharingServiceImpl
StatusCodes StopScanning();
void StopAdvertisingAndInvalidateSurfaceState();
void InvalidateFastInitiationScanning();
void StartFastInitiationScanning();
void OnFastInitiationDevicesNotDetected();
void StopFastInitiationScanning();
void ScheduleRotateBackgroundAdvertisementTimer();
void OnRotateBackgroundAdvertisementTimerFired();
@@ -501,10 +496,6 @@ class NearbySharingServiceImpl
// Used to debounce OnNetworkChanged processing.
std::unique_ptr<ThreadTimer> on_network_changed_delay_timer_;
// Used to prevent the "Device nearby is sharing" notification from appearing
// immediately after a completed share.
std::unique_ptr<ThreadTimer> fast_initiation_scanner_cooldown_timer_;
// A queue of endpoint-discovered and endpoint-lost events that ensures the
// events are processed sequentially, in the order received from Nearby
// Connections. An event is processed either immediately, if there are no
@@ -1464,50 +1464,6 @@ TEST_F(NearbySharingServiceImplTest,
EXPECT_EQ(fast_initiation->StopAdvertisingCount(), 1);
}
TEST_F(NearbySharingServiceImplTest, FastInitiationScanning_StartAndStop) {
FakeNearbyFastInitiation* fast_initiation =
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
SetLanConnected(true);
EXPECT_EQ(fast_initiation->StartScanningCount(), 1);
EXPECT_EQ(fast_initiation->StopScanningCount(), 0);
// Trigger a call to StopFastInitiationScanning().
SetBluetoothIsPowered(false);
EXPECT_EQ(fast_initiation->StartScanningCount(), 1);
EXPECT_EQ(fast_initiation->StopScanningCount(), 1);
// Trigger a call to StartFastInitiationScanning().
SetBluetoothIsPowered(true);
EXPECT_TRUE(sharing_service_task_runner_->SyncWithTimeout(kTaskWaitTimeout));
EXPECT_EQ(fast_initiation->StartScanningCount(), 2);
EXPECT_EQ(fast_initiation->StopScanningCount(), 1);
}
TEST_F(NearbySharingServiceImplTest,
FastInitiationScanning_PostTransferCooldown) {
FakeNearbyFastInitiation* fast_initiation =
nearby_fast_initiation_factory_->GetNearbyFastInitiation();
SetLanConnected(false);
// Make sure we started scanning once
EXPECT_EQ(fast_initiation->StartScanningCount(), 1);
EXPECT_EQ(fast_initiation->StopScanningCount(), 0);
SuccessfullyReceiveTransfer();
// Make sure we stopped scanning and didn't restart... yet.
EXPECT_EQ(fast_initiation->StartScanningCount(), 1);
EXPECT_EQ(fast_initiation->StopScanningCount(), 1);
// Fast-forward 10s to pass through the cooldown period.
FastForward(absl::Seconds(10));
// Make sure we restarted Fast Initiation scanning.
EXPECT_EQ(fast_initiation->StartScanningCount(), 2);
EXPECT_EQ(fast_initiation->StopScanningCount(), 1);
}
TEST_F(NearbySharingServiceImplTest,
ForegroundRegisterSendSurfaceStartsDiscovering) {
SetLanConnected(true);