summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Buhr <andreas.buhr@qt.io>2022-02-28 18:27:47 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-20 11:19:38 +0000
commit7959628aeaa111c19eeed320d75d0b338ae13477 (patch)
tree8da99d05776335b647259e4303348b30ea2ac6c2
parent6c40c21588e58e4d97167117726643b8d15ac274 (diff)
Repair tst_QBluetoothDeviceDiscoveryAgent unit test on Android
tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries was broken on Android. The sequence QBluetoothDeviceDiscoveryAgent::start() QBluetoothDeviceDiscoveryAgent::stop() QBluetoothDeviceDiscoveryAgent::start() QBluetoothDeviceDiscoveryAgent::stop() is called rather quickly. The first stop() results in the state pendingCancel=true, pendingStart=false. The second start() results in the state pendingCancel=true, pendingStart=true. The second stop() then did nothing because pendingCancel=true. Then, after the whole sequence, discovery started because pendingStart=true. This patch repairs it by setting pendingStart=false in the stop() method. Change-Id: I55486b5b494265c90149e72461a1d0529adaa2f0 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit 32b859dc9c83c7fb440e53335917021ef7eab15d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
index f1569266..a1a2ad58 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
@@ -243,15 +243,20 @@ void QBluetoothDeviceDiscoveryAgentPrivate::stop()
{
Q_Q(QBluetoothDeviceDiscoveryAgent);
+ pendingStart = false;
+
if (m_active == NoScanActive)
return;
if (m_active == SDPScanActive) {
- if (pendingCancel)
+ if (pendingCancel) {
+ // If we had both a pending cancel and a pending start,
+ // we now have only a pending cancel.
+ // The pending start was canceled above.
return;
+ }
pendingCancel = true;
- pendingStart = false;
bool success = adapter.callMethod<jboolean>("cancelDiscovery");
if (!success) {
lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;