From 996f86d93f526616f4b5f857b108c929d2e0c1bf Mon Sep 17 00:00:00 2001 From: Guogang Li Date: Tue, 30 May 2023 22:01:04 -0700 Subject: [PATCH] Fixed the issue start/stop BLE advertisement PiperOrigin-RevId: 536599497 --- .../implementation/windows/ble_gatt_server.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/platform/implementation/windows/ble_gatt_server.cc b/internal/platform/implementation/windows/ble_gatt_server.cc index b9b2f7aa..bfb14e6e 100644 --- a/internal/platform/implementation/windows/ble_gatt_server.cc +++ b/internal/platform/implementation/windows/ble_gatt_server.cc @@ -200,7 +200,10 @@ void BleGattServer::Stop() { return; } - gatt_service_provider_.StopAdvertising(); + if (is_advertising_) { + gatt_service_provider_.StopAdvertising(); + } + gatt_characteristic_datas_.clear(); service_uuid_ = Uuid(); gatt_service_provider_ = nullptr; @@ -413,10 +416,19 @@ bool BleGattServer::StopAdvertisement() { if (gatt_service_provider_ == nullptr) { NEARBY_LOGS(WARNING) << __func__ << ": no GATT server is running."; + is_advertising_ = false; + return true; + } + + if (gatt_service_provider_.AdvertisementStatus() == + GattServiceProviderAdvertisementStatus ::Stopped) { + NEARBY_LOGS(WARNING) << __func__ << ": no GATT advertisement is running."; + is_advertising_ = false; return true; } gatt_service_provider_.StopAdvertising(); + is_advertising_ = false; NEARBY_LOGS(INFO) << __func__ << ": GATT server stopped."; return true; } catch (std::exception exception) {