Deprecate UseStableEndpointId flag.

PiperOrigin-RevId: 856873445
This commit is contained in:
Francis Tsui
2026-01-15 16:44:47 -08:00
committed by Copybara-Service
parent 6c0d7af5f3
commit e2714e1685
6 changed files with 23 additions and 186 deletions
+3 -22
View File
@@ -250,21 +250,8 @@ Status BasePcpHandler::StartAdvertising(
if (compatible_advertising_options.force_new_endpoint_id) {
client->ClearCachedLocalEndpointId();
}
if (NearbyFlags::GetInstance().GetBoolFlag(
connections::config_package_nearby::nearby_connections_feature::
kUseStableEndpointId)) {
if (ShouldEnterStableEndpointIdMode(compatible_advertising_options)) {
client->EnterStableEndpointIdMode();
}
} else {
// The endpoint id inside of the advertisement is different to high
// visibility and low visibility mode. In order to decide if client
// should grab the high visibility or low visibility id, it needs to
// tell client which one right now, before
// client#StartedAdvertising.
if (ShouldEnterHighVisibilityMode(compatible_advertising_options)) {
client->EnterHighVisibilityMode();
}
if (ShouldEnterStableEndpointIdMode(compatible_advertising_options)) {
client->EnterStableEndpointIdMode();
}
if (client->IsDctEnabled()) {
@@ -283,13 +270,7 @@ Status BasePcpHandler::StartAdvertising(
client, service_id, client->GetLocalEndpointId(),
info.endpoint_info, compatible_advertising_options);
if (!result.status.Ok()) {
if (NearbyFlags::GetInstance().GetBoolFlag(
connections::config_package_nearby::
nearby_connections_feature::kUseStableEndpointId)) {
client->ExitStableEndpointIdMode();
} else {
client->ExitHighVisibilityMode();
}
client->ExitStableEndpointIdMode();
response.Set(result.status);
return;
}
@@ -2770,9 +2770,6 @@ TEST_F(BasePcpHandlerTest, TestNeedsToTurnOffAdvertisingMedium) {
TEST_F(BasePcpHandlerTest, TestUpdateAdvertisingOptionsWorks) {
env_.Start();
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kUseStableEndpointId,
true);
AdvertisingOptions old_options{
{},
true, // auto_upgrade_bandwidth
+18 -72
View File
@@ -95,11 +95,6 @@ constexpr absl::string_view kAdvertisingTimestamp = "nc.advertising.timestamp";
constexpr absl::Duration kAdvertisingKeepAliveDuration = absl::Seconds(30);
bool IsFeatureUseStableEndpointIdEnabled() {
return NearbyFlags::GetInstance().GetBoolFlag(
connections::config_package_nearby::nearby_connections_feature::
kUseStableEndpointId);
}
} // namespace
ClientProxy::ClientProxy(::nearby::analytics::EventLogger* event_logger)
@@ -214,26 +209,14 @@ void ClientProxy::SetBluetoothMacAddress(const std::string& endpoint_id,
}
std::string ClientProxy::GenerateLocalEndpointId() {
if (IsFeatureUseStableEndpointIdEnabled()) {
if (!cached_endpoint_id_.empty()) {
if (stable_endpoint_id_mode_) {
LOG(INFO) << "ClientProxy [Local Endpoint Re-using cached "
"endpoint id due to in stable endpoint id mode]: "
"client="
<< GetClientId()
<< "; cached_endpoint_id_=" << cached_endpoint_id_;
return cached_endpoint_id_;
}
}
} else {
if (high_vis_mode_) {
if (!cached_endpoint_id_.empty()) {
LOG(INFO) << "ClientProxy [Local Endpoint Re-using cached "
"endpoint id]: client="
<< GetClientId()
<< "; cached_endpoint_id_=" << cached_endpoint_id_;
return cached_endpoint_id_;
}
if (!cached_endpoint_id_.empty()) {
if (stable_endpoint_id_mode_) {
LOG(INFO) << "ClientProxy [Local Endpoint Re-using cached "
"endpoint id due to in stable endpoint id mode]: "
"client="
<< GetClientId()
<< "; cached_endpoint_id_=" << cached_endpoint_id_;
return cached_endpoint_id_;
}
}
std::string id;
@@ -252,11 +235,7 @@ void ClientProxy::Reset() {
StoppedAdvertising();
StoppedDiscovery();
RemoveAllEndpoints();
if (IsFeatureUseStableEndpointIdEnabled()) {
ExitStableEndpointIdMode();
} else {
ExitHighVisibilityMode();
}
ExitStableEndpointIdMode();
}
void ClientProxy::StartedAdvertising(
@@ -269,24 +248,14 @@ void ClientProxy::StartedAdvertising(
MutexLock lock(&mutex_);
LOG(INFO) << "ClientProxy [StartedAdvertising]: client=" << GetClientId();
if (IsFeatureUseStableEndpointIdEnabled()) {
if (stable_endpoint_id_mode_) {
cached_endpoint_id_ = local_endpoint_id_;
} else {
cached_endpoint_id_.clear();
}
CancelClearCachedEndpointIdAlarm();
if (stable_endpoint_id_mode_) {
cached_endpoint_id_ = local_endpoint_id_;
} else {
if (high_vis_mode_) {
cached_endpoint_id_ = local_endpoint_id_;
LOG(INFO)
<< "ClientProxy [High Visibility Mode Adv, Cache EndpointId]: client="
<< GetClientId() << "; cached_endpoint_id_=" << cached_endpoint_id_;
CancelClearCachedEndpointIdAlarm();
}
cached_endpoint_id_.clear();
}
CancelClearCachedEndpointIdAlarm();
advertising_info_ = {service_id, listener};
advertising_options_ = advertising_options;
@@ -313,11 +282,7 @@ void ClientProxy::StoppedAdvertising() {
// advertising_options_ is purposefully not cleared here.
OnSessionComplete();
if (IsFeatureUseStableEndpointIdEnabled()) {
ExitStableEndpointIdMode();
} else {
ExitHighVisibilityMode();
}
ExitStableEndpointIdMode();
}
bool ClientProxy::IsAdvertising() const {
@@ -640,10 +605,8 @@ void ClientProxy::OnDisconnected(const std::string& endpoint_id, bool notify) {
CancelEndpoint(endpoint_id);
if (IsFeatureUseStableEndpointIdEnabled()) {
if (!stable_endpoint_id_mode_ && !HasOngoingConnection()) {
ScheduleClearCachedEndpointIdAlarm();
}
if (!stable_endpoint_id_mode_ && !HasOngoingConnection()) {
ScheduleClearCachedEndpointIdAlarm();
}
}
@@ -1158,22 +1121,6 @@ v3::ConnectionListeningOptions ClientProxy::GetListeningOptions() const {
return listening_options_;
}
void ClientProxy::EnterHighVisibilityMode() {
MutexLock lock(&mutex_);
LOG(INFO) << "ClientProxy [EnterHighVisibilityMode]: client="
<< GetClientId();
high_vis_mode_ = true;
}
void ClientProxy::ExitHighVisibilityMode() {
MutexLock lock(&mutex_);
LOG(INFO) << "ClientProxy [ExitHighVisibilityMode]: client=" << GetClientId();
high_vis_mode_ = false;
ScheduleClearCachedEndpointIdAlarm();
}
void ClientProxy::EnterStableEndpointIdMode() {
MutexLock lock(&mutex_);
VLOG(1) << "ClientProxy [EnterStableEndpointIdMode]: client="
@@ -1200,7 +1147,7 @@ void ClientProxy::ScheduleClearCachedEndpointIdAlarm() {
return;
}
if (IsFeatureUseStableEndpointIdEnabled() && HasOngoingConnection()) {
if (HasOngoingConnection()) {
VLOG(1) << "ClientProxy [Handle clearing cached endpoint ID "
"during disconnection]: client="
<< GetClientId();
@@ -1468,7 +1415,6 @@ std::string ClientProxy::Dump() {
sstream << " Client ID: " << GetClientId() << std::endl;
sstream << " Local Endpoint ID: " << GetLocalEndpointId() << std::endl;
sstream << std::boolalpha;
sstream << " High Visibility Mode: " << high_vis_mode_ << std::endl;
sstream << " Is Advertising: " << IsAdvertising() << std::endl;
sstream << " Is Discovering: " << IsDiscovering() << std::endl;
sstream << std::noboolalpha;
-14
View File
@@ -266,15 +266,6 @@ class ClientProxy final {
DiscoveryOptions GetDiscoveryOptions() const;
v3::ConnectionListeningOptions GetListeningOptions() const;
// The endpoint id will be stable for 30 seconds after high visibility mode
// (high power and Bluetooth Classic) advertisement stops.
// If client re-enters high visibility mode within 30 seconds, he is going to
// have the same endpoint id.
void EnterHighVisibilityMode();
// Cleans up any modifications in high visibility mode. The endpoint id always
// rotates.
void ExitHighVisibilityMode();
// Enters stable endpoint ID mode.
void EnterStableEndpointIdMode();
// Cleans up any modifications in stable endpoint ID mode. The endpoint id
@@ -472,11 +463,6 @@ class ClientProxy final {
std::int64_t client_id_;
std::string local_endpoint_id_;
std::string local_endpoint_info_;
// If currently is advertising in high visibility mode is true: high power and
// Bluetooth Classic enabled. When high_visibility_mode_ is true, the endpoint
// id is stable for 30s. When high_visibility_mode_ is false, the endpoint id
// always rotates.
bool high_vis_mode_ = false;
// If advertising is in stable endpoint ID mode, the endpoint ID is stable
// for 30s after advertising or disconnection. When stable_endpoint_id_mode_
@@ -176,12 +176,6 @@ class ClientProxyTest : public ::testing::TestWithParam<FeatureFlags::Flags> {
NearbyFlags::GetInstance().ResetOverridedValues();
}
bool ShouldEnterHighVisibilityMode(
const AdvertisingOptions& advertising_options) {
return !advertising_options.low_power &&
advertising_options.allowed.bluetooth;
}
bool ShouldEnterStableEndpointIdMode(
const AdvertisingOptions& advertising_options) {
if (advertising_options.use_stable_endpoint_id) {
@@ -196,16 +190,8 @@ class ClientProxyTest : public ::testing::TestWithParam<FeatureFlags::Flags> {
Endpoint StartAdvertising(
ClientProxy* client, ConnectionListener listener,
AdvertisingOptions advertising_options = AdvertisingOptions{}) {
if (NearbyFlags::GetInstance().GetBoolFlag(
connections::config_package_nearby::nearby_connections_feature::
kUseStableEndpointId)) {
if (ShouldEnterStableEndpointIdMode(advertising_options)) {
client->EnterStableEndpointIdMode();
}
} else {
if (ShouldEnterHighVisibilityMode(advertising_options)) {
client->EnterHighVisibilityMode();
}
if (ShouldEnterStableEndpointIdMode(advertising_options)) {
client->EnterStableEndpointIdMode();
}
Endpoint endpoint{
.info = ByteArray{"advertising endpoint name"},
@@ -369,13 +355,6 @@ class ClientProxyTest : public ::testing::TestWithParam<FeatureFlags::Flags> {
client->OnPayloadProgress(endpoint.id, {});
}
void EnableUseStableEndpointIdFeature() {
NearbyFlags::GetInstance().OverrideBoolFlagValue(
connections::config_package_nearby::nearby_connections_feature::
kUseStableEndpointId,
true);
}
ClientProxy* client1() { return client1_.get(); }
ClientProxy* client2() { return client2_.get(); }
@@ -575,7 +554,6 @@ TEST_F(ClientProxyTest, DumpString) {
"Nearby Connections State\n"
" Client ID: %d\n"
" Local Endpoint ID: %s\n"
" High Visibility Mode: false\n"
" Is Advertising: false\n"
" Is Discovering: false\n"
" Advertising Service ID: \n"
@@ -826,7 +804,6 @@ TEST_F(ClientProxyTest,
TEST_F(ClientProxyTest,
RotateWhenLowVizAdvertisementAfterHighVizAndStableAdvertisement) {
EnableUseStableEndpointIdFeature();
BooleanMediumSelector booleanMediumSelector;
booleanMediumSelector.bluetooth = true;
@@ -867,7 +844,6 @@ TEST_F(ClientProxyTest,
TEST_F(
ClientProxyTest,
NoRotateWhenLowVizStableAdvertisementAfterHighVizAndStableAdvertisement) {
EnableUseStableEndpointIdFeature();
BooleanMediumSelector booleanMediumSelector;
booleanMediumSelector.bluetooth = true;
@@ -911,7 +887,6 @@ TEST_F(
TEST_F(
ClientProxyTest,
NoRotateWhenAdvertisementHasConnectionAfterStableAdvertisementForAWhile) {
EnableUseStableEndpointIdFeature();
BooleanMediumSelector booleanMediumSelector;
booleanMediumSelector.bluetooth = true;
@@ -958,7 +933,6 @@ TEST_F(
}
TEST_F(ClientProxyTest, RotateWhenLowVizAdvertisementAfterDisconnection) {
EnableUseStableEndpointIdFeature();
BooleanMediumSelector booleanMediumSelector;
booleanMediumSelector.bluetooth = true;
@@ -1001,7 +975,6 @@ TEST_F(ClientProxyTest, RotateWhenLowVizAdvertisementAfterDisconnection) {
TEST_F(ClientProxyTest,
NoRotateWhenLowVizAndStableAdvertisementAfterDisconnection) {
EnableUseStableEndpointIdFeature();
BooleanMediumSelector booleanMediumSelector;
booleanMediumSelector.bluetooth = true;
@@ -1046,7 +1019,6 @@ TEST_F(ClientProxyTest,
}
TEST_F(ClientProxyTest, RotateWhenAdvertisementAfterDisconnectionForAWhile) {
EnableUseStableEndpointIdFeature();
BooleanMediumSelector booleanMediumSelector;
booleanMediumSelector.bluetooth = true;
@@ -1147,36 +1119,6 @@ TEST_F(ClientProxyTest,
EXPECT_NE(advertising_endpoint_1.id, advertising_endpoint_2.id);
}
// Tests the low visibility mode with bluetooth disabled advertisment.
TEST_F(ClientProxyTest,
EndpointIdRotateWhenLowVizAdvertisementWithBluetoothDisabled) {
BooleanMediumSelector booleanMediumSelector;
booleanMediumSelector.bluetooth = false;
AdvertisingOptions advertising_options{
{
strategy_,
booleanMediumSelector,
},
false, // auto_upgrade_bandwidth
false, // enforce_topology_constraints
false, // low_power
true, // enable_bluetooth_listening
false, // enable_webrtc_listening
true, // use_stable_endpoint_id
};
Endpoint advertising_endpoint_1 = StartAdvertising(
client1(), advertising_connection_listener_, advertising_options);
StopAdvertising(client1());
Endpoint advertising_endpoint_2 = StartAdvertising(
client1(), advertising_connection_listener_, advertising_options);
EXPECT_NE(advertising_endpoint_1.id, advertising_endpoint_2.id);
}
// Tests the low visibility mode with low power advertisment.
TEST_F(ClientProxyTest, EndpointIdRotateWhenLowVizAdvertisementWithLowPower) {
BooleanMediumSelector booleanMediumSelector;
@@ -1623,9 +1565,6 @@ TEST_F(ClientProxyTest, TestRemoteMultiplexSocketBitmask) {
}
TEST_F(ClientProxyTest, SaveClientInfoFromPreferences) {
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kUseStableEndpointId,
true);
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::
kEnableNearbyConnectionsPreferences,
@@ -1642,9 +1581,6 @@ TEST_F(ClientProxyTest, SaveClientInfoFromPreferences) {
// The new client should load the same endpoint ID.
EXPECT_EQ(client1()->GetLocalEndpointId(), endpoint_id);
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kUseStableEndpointId,
false);
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::
kEnableNearbyConnectionsPreferences,
@@ -1652,9 +1588,6 @@ TEST_F(ClientProxyTest, SaveClientInfoFromPreferences) {
}
TEST_F(ClientProxyTest, NotLoadClientInfoFromPreferencesOnExpired) {
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kUseStableEndpointId,
true);
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::
kEnableNearbyConnectionsPreferences,
@@ -1673,9 +1606,6 @@ TEST_F(ClientProxyTest, NotLoadClientInfoFromPreferencesOnExpired) {
// The new client should load the same endpoint ID.
EXPECT_NE(client1()->GetLocalEndpointId(), endpoint_id);
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kUseStableEndpointId,
false);
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::
kEnableNearbyConnectionsPreferences,
@@ -123,9 +123,6 @@ constexpr auto kRefactorBleL2cap =
// 4. auto-resume 5. non-distance-constraint-recovery 6. payload_ack
constexpr auto kSafeToDisconnectVersion =
flags::Flag<int64_t>(kConfigPackage, "45425841", 0);
// When true, use stable endpoint ID.
constexpr auto kUseStableEndpointId =
flags::Flag<bool>(kConfigPackage, "45639298", false);
} // namespace nearby_connections_feature
} // namespace config_package_nearby