From 0313535fd9ccb05b60c5e421c1c986e48564e254 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 6 Dec 2019 13:40:20 +0100 Subject: Android: Fix failing re-addvertisement of BTLE service after disconnect The BTLE server can disconnect by own choice and by remotely initiated disconnect. Often the app might want to readvertise the same service right after the disconnect. Such a readvertisement fails when the BluetoothGattServer instance is not recreated, before calling BluetoothGattServer.addService(). In the case of remote disconnects we never recreated the BluetoothGattServer instance therefore the readvertisement always failed. This patch fixes the issue by ensureing the previous instance is properly discarded. Change-Id: I39380ee6f1f39bd71a5b73ec82bb786b3e199665 Reviewed-by: Timur Pocheptsov --- .../src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java index cdd16686..9ef254f5 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java @@ -237,6 +237,7 @@ public class QtBluetoothLEServer { qtControllerState = 0; // QLowEnergyController::UnconnectedState clientCharacteristicManager.markDeviceConnectivity(device, false); mGattServer.close(); + mGattServer = null; break; case BluetoothProfile.STATE_CONNECTED: clientCharacteristicManager.markDeviceConnectivity(device, true); @@ -461,7 +462,8 @@ public class QtBluetoothLEServer { return; } - mGattServer.addService(service); + boolean success = mGattServer.addService(service); + Log.w(TAG, "Services successfully added: " + success); } /* -- cgit v1.2.3