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) {