Added logic to stabilize endpoint IDs

PiperOrigin-RevId: 644407047
This commit is contained in:
Guogang Li
2024-06-18 09:11:51 -07:00
committed by Copybara-Service
parent 23031698dd
commit 4f386b95db
6 changed files with 559 additions and 71 deletions
+33 -8
View File
@@ -227,20 +227,34 @@ Status BasePcpHandler::StartAdvertising(
"start-advertising",
[this, client, &service_id, &info, &compatible_advertising_options,
&response]() RUN_ON_PCP_HANDLER_THREAD() {
// 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 (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();
}
}
auto result = StartAdvertisingImpl(
client, service_id, client->GetLocalEndpointId(),
info.endpoint_info, compatible_advertising_options);
if (!result.status.Ok()) {
client->ExitHighVisibilityMode();
if (NearbyFlags::GetInstance().GetBoolFlag(
connections::config_package_nearby::
nearby_connections_feature::kUseStableEndpointId)) {
client->ExitStableEndpointIdMode();
} else {
client->ExitHighVisibilityMode();
}
response.Set(result.status);
return;
}
@@ -333,6 +347,17 @@ bool BasePcpHandler::ShouldEnterHighVisibilityMode(
advertising_options.allowed.bluetooth;
}
bool BasePcpHandler::ShouldEnterStableEndpointIdMode(
const AdvertisingOptions& advertising_options) {
if (advertising_options.use_stable_endpoint_id) {
return true;
} else if (advertising_options.low_power) {
return false;
} else {
return true;
}
}
BooleanMediumSelector BasePcpHandler::ComputeIntersectionOfSupportedMediums(
const PendingConnectionInfo& connection_info) {
absl::flat_hash_set<Medium> intersection;