From ef332e4deedc914fe33bab68107f902182e03356 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 27 Apr 2018 14:04:14 +0200 Subject: Fix crash when entries is empty (caused by disconnect somewhere else) The patch fixes the obvious problem of the crash. The question is however what might have caused entries to be empty. The only theoretical explanation is the remote device being disconnected (which resets most internal data). Task-number: QTBUG-65826 Change-Id: I6b3509248f795d9cee5dcfe0c6e0caf06405b4e4 Reviewed-by: Timur Pocheptsov --- .../qt5/android/bluetooth/QtBluetoothLE.java | 39 +++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java index 1b527ae3..4063537b 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java @@ -1141,16 +1141,24 @@ public class QtBluetoothLE { if (handle == HANDLE_FOR_MTU_EXCHANGE) return; - GattEntry entry = entries.get(handle); - if (entry == null) - return; - if (entry.valueKnown) - return; - entry.valueKnown = true; + try { + synchronized (this) { - GattEntry serviceEntry = entries.get(entry.associatedServiceHandle); - if (serviceEntry != null && serviceEntry.endHandle == handle) - finishCurrentServiceDiscovery(entry.associatedServiceHandle); + GattEntry entry = entries.get(handle); + if (entry == null) + return; + if (entry.valueKnown) + return; + entry.valueKnown = true; + + GattEntry serviceEntry = entries.get(entry.associatedServiceHandle); + if (serviceEntry != null && serviceEntry.endHandle == handle) + finishCurrentServiceDiscovery(entry.associatedServiceHandle); + } + } catch (IndexOutOfBoundsException outOfBounds) { + Log.w(TAG, "interruptCurrentIO(): Unknown gatt entry, index: " + + handle + " size: " + entries.size()); + } } /* @@ -1271,9 +1279,16 @@ public class QtBluetoothLE { } // last entry of current discovery run? - GattEntry serviceEntry = entries.get(entry.associatedServiceHandle); - if (serviceEntry.endHandle == handle) - finishCurrentServiceDiscovery(entry.associatedServiceHandle); + synchronized (this) { + try { + GattEntry serviceEntry = entries.get(entry.associatedServiceHandle); + if (serviceEntry.endHandle == handle) + finishCurrentServiceDiscovery(entry.associatedServiceHandle); + } catch (IndexOutOfBoundsException outOfBounds) { + Log.w(TAG, "performNextIO(): Unknown service for entry, index: " + + entry.associatedServiceHandle + " size: " + entries.size()); + } + } } else { int errorCode = 0; -- cgit v1.2.3