From 540f4bac7a53b4691f3f68356b23cf0e9e5dba4e Mon Sep 17 00:00:00 2001 From: Edwin Wu Date: Tue, 13 May 2025 19:50:57 -0700 Subject: [PATCH] Add flag to control whether to disconnect the GATT client when exiting the BLE GATT service. PiperOrigin-RevId: 758474539 --- .../implementation/flags/nearby_connections_feature_flags.h | 3 +++ .../platform/implementation/apple/Flags/GNCFeatureFlags.h | 3 +++ .../platform/implementation/apple/Flags/GNCFeatureFlags.mm | 6 ++++++ internal/platform/implementation/apple/ble_gatt_client.mm | 5 ++--- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/connections/implementation/flags/nearby_connections_feature_flags.h b/connections/implementation/flags/nearby_connections_feature_flags.h index b571e1b1..5804a1f7 100644 --- a/connections/implementation/flags/nearby_connections_feature_flags.h +++ b/connections/implementation/flags/nearby_connections_feature_flags.h @@ -104,6 +104,9 @@ constexpr auto kEnableDynamicRoleSwitch = // Enable/Disable DCT advertising/scanning specification. constexpr auto kEnableDct = flags::Flag(kConfigPackage, "45697202", false); +// Enable/Disable GATT client disconnection. +constexpr auto kEnableGattClientDisconnection = + flags::Flag(kConfigPackage, "45698964", false); } // namespace nearby_connections_feature } // namespace config_package_nearby } // namespace connections diff --git a/internal/platform/implementation/apple/Flags/GNCFeatureFlags.h b/internal/platform/implementation/apple/Flags/GNCFeatureFlags.h index 54328ce7..d01eb4a5 100644 --- a/internal/platform/implementation/apple/Flags/GNCFeatureFlags.h +++ b/internal/platform/implementation/apple/Flags/GNCFeatureFlags.h @@ -20,4 +20,7 @@ /** Checks whether DCT is enabled in the Nearby Connections SDK. */ @property(nonatomic, class, readonly) BOOL dctEnabled; +/** Checks whether GATT client disconnection is enabled in the Nearby Connections SDK. */ +@property(nonatomic, class, readonly) BOOL gattClientDisconnectionEnabled; + @end diff --git a/internal/platform/implementation/apple/Flags/GNCFeatureFlags.mm b/internal/platform/implementation/apple/Flags/GNCFeatureFlags.mm index be4fc1c5..ef71e5e8 100644 --- a/internal/platform/implementation/apple/Flags/GNCFeatureFlags.mm +++ b/internal/platform/implementation/apple/Flags/GNCFeatureFlags.mm @@ -24,4 +24,10 @@ nearby::connections::config_package_nearby::nearby_connections_feature::kEnableDct); } ++ (BOOL)gattClientDisconnectionEnabled { + return nearby::NearbyFlags::GetInstance().GetBoolFlag( + nearby::connections::config_package_nearby::nearby_connections_feature:: + kEnableGattClientDisconnection); +} + @end diff --git a/internal/platform/implementation/apple/ble_gatt_client.mm b/internal/platform/implementation/apple/ble_gatt_client.mm index c67332ca..b182d072 100644 --- a/internal/platform/implementation/apple/ble_gatt_client.mm +++ b/internal/platform/implementation/apple/ble_gatt_client.mm @@ -133,9 +133,8 @@ void GattClient::Disconnect() { // not connect to the iOS device if the iOS device disconnects and then attempts to reconnect. // Because of this, we no-op here instead of calling `[gatt_client_ disconnect]`. // See: b/375176623 - if (GNCFeatureFlags.dctEnabled) { - // Avoid to impact GTV functionality, put the disconnect for NC iOS SDK only, so thatGATT client - // can reconnect to the GATT server. + if (GNCFeatureFlags.gattClientDisconnectionEnabled) { + // Avoid to impact GTV functionality, so that GATT client can reconnect to the GATT server. [gatt_client_ disconnect]; } }