Fixed the crash when connecting a remote target from Win to Phone

PiperOrigin-RevId: 472502070
This commit is contained in:
Guogang Li
2022-09-06 10:50:21 -07:00
committed by Copybara-Service
parent 525283a166
commit 851f5ec0dd
@@ -284,6 +284,12 @@ std::unique_ptr<api::BluetoothSocket> 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_);