From 31c2c2403028854dbc20083581234a6840f05a7d Mon Sep 17 00:00:00 2001
From: Alex Blasche <alexander.blasche@theqtcompany.com>
Date: Wed, 23 Dec 2015 09:56:28 +0100
Subject: [PATCH] Android: Invalidate services after a disconnect from the
 peripheral side

So far, invalidation only took place when the local/central side
disconnected the connection.

Task-number: QTBUG-50125
Change-Id: Ic01725d1b83e49ad7df6971d980b480f839d550b
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
---
 src/bluetooth/qlowenergycontroller_android.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp
index fd4ea753..cb08b6f9 100644
--- a/src/bluetooth/qlowenergycontroller_android.cpp
+++ b/src/bluetooth/qlowenergycontroller_android.cpp
@@ -326,6 +326,14 @@ void QLowEnergyControllerPrivate::connectionUpdated(
     if (newState == QLowEnergyController::UnconnectedState
             && !(oldState == QLowEnergyController::UnconnectedState
                 || oldState == QLowEnergyController::ConnectingState)) {
+
+        // Invalidate the services if the disconnect came from the remote end.
+        // Qtherwise we disconnected via QLowEnergyController::disconnectDevice() which
+        // triggered invalidation already
+        if (!serviceList.isEmpty()) {
+            Q_ASSERT(oldState != QLowEnergyController::ClosingState);
+            invalidateServices();
+        }
         emit q->disconnected();
     } else if (newState == QLowEnergyController::ConnectedState
                && oldState != QLowEnergyController::ConnectedState ) {
-- 
GitLab