From 9b8d708a7fae79be4480fe5b0148dd71995ccb43 Mon Sep 17 00:00:00 2001 From: Guogang Li Date: Wed, 29 May 2024 20:24:37 -0700 Subject: [PATCH] Add use_stable_endpoint_id to AdvertisingOptions PiperOrigin-RevId: 638501216 --- connections/advertising_options.h | 2 + connections/core.cc | 52 +++++++++++++--------- connections/v3/advertising_options.h | 2 + sharing/nearby_connections_manager_impl.cc | 1 + sharing/nearby_connections_service_impl.cc | 1 + sharing/nearby_connections_types.h | 5 +++ 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/connections/advertising_options.h b/connections/advertising_options.h index 1f87960f..d7408d16 100644 --- a/connections/advertising_options.h +++ b/connections/advertising_options.h @@ -33,6 +33,8 @@ struct AdvertisingOptions : public OptionsBase { bool low_power; bool enable_bluetooth_listening; bool enable_webrtc_listening; + // Indicates whether the endpoint id should be stable. + bool use_stable_endpoint_id = false; // Whether this is intended to be used in conjunction with InjectEndpoint(). bool is_out_of_band_connection = false; diff --git a/connections/core.cc b/connections/core.cc index 0e8c00b4..76db0338 100644 --- a/connections/core.cc +++ b/connections/core.cc @@ -270,21 +270,26 @@ void Core::StartAdvertisingV3(absl::string_view service_id, CheckServiceId(service_id); CHECK(advertising_options.strategy.IsValid()); - AdvertisingOptions old_advertising_options = { - { - advertising_options.strategy, - advertising_options.advertising_mediums, - }, - advertising_options.auto_upgrade_bandwidth, - advertising_options.enforce_topology_constraints, - advertising_options.power_level == PowerLevel::kLowPower, // low_power - advertising_options.enable_bluetooth_listening, - advertising_options.advertising_mediums.web_rtc, - false, // is_out_of_band_connection - advertising_options.fast_advertisement_service_uuid, - "" // device_info - }; // TODO(b/291295755): Refactor deeper to use v3 options throughout. + AdvertisingOptions old_advertising_options = { + /*OptionsBase=*/ + { + /*strategy=*/advertising_options.strategy, + /*allowed=*/advertising_options.advertising_mediums, + }, + /*auto_upgrade_bandwidth=*/advertising_options.auto_upgrade_bandwidth, + /*enforce_topology_constraints=*/ + advertising_options.enforce_topology_constraints, + /*low_power=*/advertising_options.power_level == PowerLevel::kLowPower, + /*enable_bluetooth_listening=*/ + advertising_options.enable_bluetooth_listening, + /*enable_webrtc_listening=*/ + advertising_options.advertising_mediums.web_rtc, + /*use_stable_endpoint_id=*/advertising_options.use_stable_endpoint_id, + /*is_out_of_band_connection=*/false, + /*fast_advertisement_service_uuid=*/ + advertising_options.fast_advertisement_service_uuid, + /*device_info=*/""}; router_->StartAdvertising(&client_, service_id, old_advertising_options, old_info, std::move(callback)); } @@ -505,19 +510,24 @@ void Core::UpdateAdvertisingOptionsV3( ResultCallback result_cb) { // TODO(b/291295755): Deeper refactor to use new advertising options. AdvertisingOptions old_advertising_options = { + /*OptionsBase=*/ { - advertising_options.strategy, - advertising_options.advertising_mediums, + /*strategy=*/advertising_options.strategy, + /*allowed=*/advertising_options.advertising_mediums, }, - advertising_options.auto_upgrade_bandwidth, + /*auto_upgrade_bandwidth=*/advertising_options.auto_upgrade_bandwidth, + /*enforce_topology_constraints=*/ advertising_options.enforce_topology_constraints, - advertising_options.power_level == PowerLevel::kLowPower, // low_power + /*low_power=*/advertising_options.power_level == PowerLevel::kLowPower, + /*enable_bluetooth_listening=*/ advertising_options.enable_bluetooth_listening, + /*enable_webrtc_listening=*/ advertising_options.advertising_mediums.web_rtc, - false, // is_out_of_band_connection + /*use_stable_endpoint_id=*/advertising_options.use_stable_endpoint_id, + /*is_out_of_band_connection=*/false, + /*fast_advertisement_service_uuid=*/ advertising_options.fast_advertisement_service_uuid, - "" // device_info - }; + /*device_info=*/""}; router_->UpdateAdvertisingOptionsV3( &client_, service_id, old_advertising_options, std::move(result_cb)); } diff --git a/connections/v3/advertising_options.h b/connections/v3/advertising_options.h index 4e22c552..42eb8010 100644 --- a/connections/v3/advertising_options.h +++ b/connections/v3/advertising_options.h @@ -39,6 +39,8 @@ struct AdvertisingOptions { // If Nearby Connections should auto-upgrade bandwidth. bool auto_upgrade_bandwidth = true; bool enforce_topology_constraints = true; + // Indicates whether the endpoint id should be stable. + bool use_stable_endpoint_id = false; std::string fast_advertisement_service_uuid; BooleanMediumSelector advertising_mediums; BooleanMediumSelector upgrade_mediums; diff --git a/sharing/nearby_connections_manager_impl.cc b/sharing/nearby_connections_manager_impl.cc index 4cba8787..a76b5eb8 100644 --- a/sharing/nearby_connections_manager_impl.cc +++ b/sharing/nearby_connections_manager_impl.cc @@ -277,6 +277,7 @@ void NearbyConnectionsManagerImpl::StartAdvertising( /*enable_bluetooth_listening=*/use_ble, /*enable_webrtc_listening=*/ ShouldEnableWebRtc(connectivity_manager_, data_usage, power_level), + /*use_stable_endpoint_id=*/false, /*fast_advertisement_service_uuid=*/ fast_advertisement_service_uuid), std::move(connection_listener), std::move(callback)); diff --git a/sharing/nearby_connections_service_impl.cc b/sharing/nearby_connections_service_impl.cc index c93c3717..9103d621 100644 --- a/sharing/nearby_connections_service_impl.cc +++ b/sharing/nearby_connections_service_impl.cc @@ -75,6 +75,7 @@ void NearbyConnectionsServiceImpl::StartAdvertising( options.enable_bluetooth_listening = advertising_options.enable_bluetooth_listening; options.enable_webrtc_listening = advertising_options.enable_webrtc_listening; + options.use_stable_endpoint_id = advertising_options.use_stable_endpoint_id; options.fast_advertisement_service_uuid = advertising_options.fast_advertisement_service_uuid.uuid; diff --git a/sharing/nearby_connections_types.h b/sharing/nearby_connections_types.h index 6e0ef1dd..c6a29fce 100644 --- a/sharing/nearby_connections_types.h +++ b/sharing/nearby_connections_types.h @@ -205,6 +205,7 @@ struct AdvertisingOptions { bool enforce_topology_constraints, bool enable_bluetooth_listening, bool enable_webrtc_listening, + bool use_stable_endpoint_id, Uuid fast_advertisement_service_uuid) { this->strategy = strategy; this->allowed_mediums = allowed_mediums; @@ -212,6 +213,7 @@ struct AdvertisingOptions { this->enforce_topology_constraints = enforce_topology_constraints; this->enable_bluetooth_listening = enable_bluetooth_listening; this->enable_webrtc_listening = enable_webrtc_listening; + this->use_stable_endpoint_id = use_stable_endpoint_id; this->fast_advertisement_service_uuid = fast_advertisement_service_uuid; } @@ -238,6 +240,9 @@ struct AdvertisingOptions { // By default, this option is false. If true, this allows listening on // incoming WebRTC connections while advertising. bool enable_webrtc_listening = false; + // Indicates whether the endpoint id should be stable. When visibility is + // everyone mode, we should set this to true to avoid duplicated endpoint ids. + bool use_stable_endpoint_id = false; // Optional. If set, BLE advertisements will be in their "fast advertisement" // form, use this UUID, and non-connectable; if empty, BLE advertisements // will otherwise be normal and connectable.