diff --git a/internal/platform/feature_flags.h b/internal/platform/feature_flags.h index 86017fdf..712c038f 100644 --- a/internal/platform/feature_flags.h +++ b/internal/platform/feature_flags.h @@ -49,6 +49,12 @@ class FeatureFlags { bool support_ble_v2 = false; // Allows the code to change the bluetooth radio state bool enable_set_radio_state = false; + // If the feature is enabled, medium connection will timeout when cannot + // create connection with remote device in a duration. + bool enable_connection_timeout = false; + // Controls to enable or disable to track the status of Bluetooth classic + // conncetion. + bool enable_bluetooth_connection_status_track = false; }; static const FeatureFlags& GetInstance() { diff --git a/internal/platform/implementation/windows/bluetooth_classic_socket.cc b/internal/platform/implementation/windows/bluetooth_classic_socket.cc index 0599b896..7d10ef91 100644 --- a/internal/platform/implementation/windows/bluetooth_classic_socket.cc +++ b/internal/platform/implementation/windows/bluetooth_classic_socket.cc @@ -18,6 +18,7 @@ #include #include +#include "internal/platform/feature_flags.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Devices.Bluetooth.h" #include "internal/platform/implementation/windows/generated/winrt/Windows.Networking.Sockets.h" #include "internal/platform/implementation/windows/generated/winrt/base.h" @@ -35,9 +36,14 @@ BluetoothSocket::BluetoothSocket(StreamSocket streamSocket) winrt::Windows::Devices::Bluetooth::BluetoothDevice::FromHostNameAsync( windows_socket_.Information().RemoteHostName()) .get(); - connection_status_changed_token_ = - native_bluetooth_device_.ConnectionStatusChanged( - {this, &BluetoothSocket::Listener_ConnectionStatusChanged}); + if (FeatureFlags::GetInstance() + .GetFlags() + .enable_bluetooth_connection_status_track) { + connection_status_changed_token_ = + native_bluetooth_device_.ConnectionStatusChanged( + {this, &BluetoothSocket::Listener_ConnectionStatusChanged}); + } + bluetooth_device_ = std::make_unique(native_bluetooth_device_); input_stream_ = BluetoothInputStream(windows_socket_.InputStream()); @@ -48,8 +54,13 @@ BluetoothSocket::BluetoothSocket() {} BluetoothSocket::~BluetoothSocket() { if (native_bluetooth_device_ != nullptr) { - native_bluetooth_device_.ConnectionStatusChanged( - connection_status_changed_token_); + if (FeatureFlags::GetInstance() + .GetFlags() + .enable_bluetooth_connection_status_track) { + native_bluetooth_device_.ConnectionStatusChanged( + connection_status_changed_token_); + } + native_bluetooth_device_ = nullptr; } } diff --git a/internal/platform/implementation/windows/wifi_hotspot_medium.cc b/internal/platform/implementation/windows/wifi_hotspot_medium.cc index 4a8a978c..9ca397b9 100644 --- a/internal/platform/implementation/windows/wifi_hotspot_medium.cc +++ b/internal/platform/implementation/windows/wifi_hotspot_medium.cc @@ -19,6 +19,7 @@ #include "absl/strings/string_view.h" #include "absl/time/time.h" +#include "internal/platform/feature_flags.h" #include "internal/platform/implementation/windows/wifi_hotspot.h" // Nearby connections headers @@ -125,12 +126,14 @@ std::unique_ptr WifiHotspotMedium::ConnectToService( }); } - connection_timeout_ = scheduled_executor_.Schedule( - [socket]() { - NEARBY_LOGS(WARNING) << "connect is closed due to timeout."; - socket.Close(); - }, - kWifiHotspotClientSocketConnectTimeoutMillis); + if (FeatureFlags::GetInstance().GetFlags().enable_connection_timeout) { + connection_timeout_ = scheduled_executor_.Schedule( + [socket]() { + NEARBY_LOGS(WARNING) << "connect is closed due to timeout."; + socket.Close(); + }, + kWifiHotspotClientSocketConnectTimeoutMillis); + } socket.ConnectAsync(host_name, service_name).get(); if (connection_cancellation_listener_ != nullptr) { diff --git a/internal/platform/implementation/windows/wifi_lan_medium.cc b/internal/platform/implementation/windows/wifi_lan_medium.cc index d0a90952..ea2923d9 100644 --- a/internal/platform/implementation/windows/wifi_lan_medium.cc +++ b/internal/platform/implementation/windows/wifi_lan_medium.cc @@ -38,6 +38,7 @@ #include "absl/time/time.h" #include "internal/platform/cancellation_flag_listener.h" #include "internal/platform/exception.h" +#include "internal/platform/feature_flags.h" #include "internal/platform/implementation/windows/utils.h" #include "internal/platform/logging.h" #include "internal/platform/runnable.h" @@ -373,12 +374,14 @@ std::unique_ptr WifiLanMedium::ConnectToService( // connection to the service try { - connection_timeout_ = scheduled_executor_.Schedule( - [socket]() { - NEARBY_LOGS(WARNING) << "connect is closed due to timeout."; - socket.Close(); - }, - kConnectServiceTimeout); + if (FeatureFlags::GetInstance().GetFlags().enable_connection_timeout) { + connection_timeout_ = scheduled_executor_.Schedule( + [socket]() { + NEARBY_LOGS(WARNING) << "connect is closed due to timeout."; + socket.Close(); + }, + kConnectServiceTimeout); + } socket.ConnectAsync(host_name, service_name).get(); if (connection_cancellation_listener_ != nullptr) {