From 851f5ec0dd9fffe71d7e508a16cb6512e2c2c0c8 Mon Sep 17 00:00:00 2001 From: Guogang Li Date: Tue, 6 Sep 2022 10:48:19 -0700 Subject: [PATCH] Fixed the crash when connecting a remote target from Win to Phone PiperOrigin-RevId: 472502070 --- .../implementation/windows/bluetooth_classic_medium.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/platform/implementation/windows/bluetooth_classic_medium.cc b/internal/platform/implementation/windows/bluetooth_classic_medium.cc index 23adfdb8..15781b7e 100644 --- a/internal/platform/implementation/windows/bluetooth_classic_medium.cc +++ b/internal/platform/implementation/windows/bluetooth_classic_medium.cc @@ -284,6 +284,12 @@ std::unique_ptr BluetoothClassicMedium::ConnectToService( NEARBY_LOGS(ERROR) << __func__ << ": Exception connecting bluetooth async: " << exception.what(); return nullptr; + } catch (const winrt::hresult_error& ex) { + NEARBY_LOGS(ERROR) << __func__ + << ": Exception connecting bluetooth async, error code: " + << ex.code() + << ", error message: " << winrt::to_string(ex.message()); + return nullptr; } return std::move(rfcomm_socket); @@ -606,9 +612,7 @@ bool BluetoothClassicMedium::StartAdvertising(bool radio_discoverable) { return false; } - server_socket_->SetCloseNotifier([&]() { - StopAdvertising(); - }); + server_socket_->SetCloseNotifier([&]() { StopAdvertising(); }); // Set the SDP attributes and start Bluetooth advertising InitializeServiceSdpAttributes(rfcomm_provider_, service_name_);