From d9b38e2efd7f851eac62079109e400e63b39bfd3 Mon Sep 17 00:00:00 2001 From: Anay Wadhera Date: Tue, 24 Sep 2024 00:45:55 -0700 Subject: [PATCH] Don't attach vendor ID to advertisements that aren't in everyone mode. PiperOrigin-RevId: 678117611 --- sharing/nearby_sharing_service_impl.cc | 4 ++- sharing/nearby_sharing_service_impl_test.cc | 30 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/sharing/nearby_sharing_service_impl.cc b/sharing/nearby_sharing_service_impl.cc index 7e132c7a..9417787e 100644 --- a/sharing/nearby_sharing_service_impl.cc +++ b/sharing/nearby_sharing_service_impl.cc @@ -1593,7 +1593,9 @@ NearbySharingServiceImpl::CreateEndpointInfo( std::unique_ptr advertisement = Advertisement::NewInstance( std::move(salt), std::move(encrypted_key), device_type, device_name, - static_cast(GetReceivingVendorId())); + visibility == DeviceVisibility::DEVICE_VISIBILITY_EVERYONE + ? static_cast(GetReceivingVendorId()) + : static_cast(BlockedVendorId::kNone)); if (advertisement) { return advertisement->ToEndpointInfo(); } else { diff --git a/sharing/nearby_sharing_service_impl_test.cc b/sharing/nearby_sharing_service_impl_test.cc index e26f9627..9f28da46 100644 --- a/sharing/nearby_sharing_service_impl_test.cc +++ b/sharing/nearby_sharing_service_impl_test.cc @@ -1921,7 +1921,7 @@ TEST_F(NearbySharingServiceImplTest, SetConnectionType(ConnectionType::kWifi); preference_manager().SetInteger( prefs::kNearbySharingBackgroundVisibilityName, - static_cast(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS)); + static_cast(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE)); FlushTesting(); // Register background receive surface with vendor ID 1. @@ -1940,6 +1940,30 @@ TEST_F(NearbySharingServiceImplTest, static_cast(Advertisement::BlockedVendorId::kSamsung)); } +TEST_F(NearbySharingServiceImplTest, + RegisterReceiveSurfaceWithVendorId_DoesNotAdvertiseInContacts) { + SetConnectionType(ConnectionType::kWifi); + preference_manager().SetInteger( + prefs::kNearbySharingBackgroundVisibilityName, + static_cast(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS)); + FlushTesting(); + + // Register background receive surface with vendor ID 1. + MockTransferUpdateCallback background_transfer_callback; + NearbySharingService::StatusCodes result = RegisterReceiveSurface( + &background_transfer_callback, + NearbySharingService::ReceiveSurfaceState::kBackground, + static_cast(Advertisement::BlockedVendorId::kSamsung)); + ASSERT_EQ(result, NearbySharingService::StatusCodes::kOk); + ASSERT_TRUE(fake_nearby_connections_manager_->IsAdvertising()); + + auto endpoint_info = + fake_nearby_connections_manager_->advertising_endpoint_info(); + auto advertisement = Advertisement::FromEndpointInfo(*endpoint_info); + EXPECT_EQ(advertisement->vendor_id(), + static_cast(Advertisement::BlockedVendorId::kNone)); +} + TEST_F(NearbySharingServiceImplTest, RegisterReceiveSurfaceWithDifferentVendorIdIsBlocked) { SetConnectionType(ConnectionType::kWifi); @@ -1970,7 +1994,7 @@ TEST_F(NearbySharingServiceImplTest, SetConnectionType(ConnectionType::kWifi); preference_manager().SetInteger( prefs::kNearbySharingBackgroundVisibilityName, - static_cast(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS)); + static_cast(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE)); FlushTesting(); // Register background receive surface with vendor ID 0. @@ -4181,7 +4205,7 @@ TEST_F(NearbySharingServiceImplTest, // This test verifies the de-dup logic. Since certificates are the same, all the // share targets are duplicates. -TEST_F(NearbySharingServiceImplTest, EndpointDedupBAsedOnDeviceId) { +TEST_F(NearbySharingServiceImplTest, EndpointDedupBasedOnDeviceId) { NearbyFlags::GetInstance().OverrideBoolFlagValue( config_package_nearby::nearby_sharing_feature::kApplyEndpointsDedup, true);