summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2022-09-06 13:25:47 +0300
committerJuha Vuolle <juha.vuolle@insta.fi>2022-09-23 09:19:42 +0300
commit3284614452f011b1788f7500e22c297f9c801633 (patch)
treecb40a33d1002839f73388c8e27afa08ff05fbb80
parent674080a59307cf588126f74a65711a10762f29df (diff)
downloadqtconnectivity-3284614452f011b1788f7500e22c297f9c801633.tar.gz
Clear previous bluetooth device/service discovery errors on restart
An example of the problem is when discovery is first tried while bluetooth is OFF, and one gets the corresponding error. Then the bluetooth is switched ON, and the discovery is restarted successfully. However in this case the error() still remains as "power OFF" error instead of "no error", which is misleading. With device discovery agent the clearing is done at each individual backend, rather than at the common public class start(). This is due to the pending cancel/start logic, which we probably shouldn't interfere with by clearing errors amidst pending operation. The Darwin backend already cleared the error in its start(), and with this commit the intent is to add similar clearing to the Android/Bluez/Win. Fixes: QTBUG-104473 Change-Id: I713590a26eb2b8d4ee7873f3fe84e63e504523df Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 14db1fabef1ba2eb1a889c968e3b038f7978d6bd)
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent.cpp4
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp2
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp2
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp2
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.cpp8
5 files changed, 17 insertions, 1 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
index 727ea690..77a483fb 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
@@ -381,6 +381,8 @@ bool QBluetoothDeviceDiscoveryAgent::isActive() const
/*!
Returns the last error.
+
+ Any possible previous errors are cleared upon restarting the discovery.
*/
QBluetoothDeviceDiscoveryAgent::Error QBluetoothDeviceDiscoveryAgent::error() const
{
@@ -391,6 +393,8 @@ QBluetoothDeviceDiscoveryAgent::Error QBluetoothDeviceDiscoveryAgent::error() co
/*!
Returns a human-readable description of the last error.
+
+ \sa error(), errorOccurred()
*/
QString QBluetoothDeviceDiscoveryAgent::errorString() const
{
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
index a79fea79..b6d7fe37 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
@@ -238,6 +238,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent
QObject::connect(receiver, SIGNAL(finished()), this, SLOT(processSdpDiscoveryFinished()));
}
+ lastError = QBluetoothDeviceDiscoveryAgent::NoError;
+ errorString.clear();
discoveredDevices.clear();
// by arbitrary definition we run classic search first
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index 3945e918..7c68a950 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -109,6 +109,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent
return;
}
+ lastError = QBluetoothDeviceDiscoveryAgent::NoError;
+ errorString.clear();
discoveredDevices.clear();
devicesProperties.clear();
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
index c6e77e1d..62fb809d 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
@@ -799,6 +799,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent
worker = std::make_shared<QWinRTBluetoothDeviceDiscoveryWorker>(methods,
lowEnergySearchTimeout);
+ lastError = QBluetoothDeviceDiscoveryAgent::NoError;
+ errorString.clear();
discoveredDevices.clear();
connect(worker.get(), &QWinRTBluetoothDeviceDiscoveryWorker::deviceFound,
this, &QBluetoothDeviceDiscoveryAgentPrivate::registerDevice);
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
index 56be94db..865f6e2a 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
@@ -341,6 +341,9 @@ void QBluetoothServiceDiscoveryAgent::start(DiscoveryMode mode)
d->foundHostAdapterPath.clear();
#endif
d->setDiscoveryMode(mode);
+ // Clear any possible previous errors
+ d->error = QBluetoothServiceDiscoveryAgent::NoError;
+ d->errorString.clear();
if (d->deviceAddress.isNull()) {
d->startDeviceDiscovery();
} else {
@@ -411,9 +414,10 @@ bool QBluetoothServiceDiscoveryAgent::isActive() const
discovered by a scan, errors during service discovery on individual
devices are not saved and no signals are emitted. In this case, errors are
fairly normal as some devices may not respond to discovery or
- may no longer be in range. Such errors are surpressed. If no services
+ may no longer be in range. Such errors are suppressed. If no services
are returned, it can be assumed no services could be discovered.
+ Any possible previous errors are cleared upon restarting the discovery.
*/
QBluetoothServiceDiscoveryAgent::Error QBluetoothServiceDiscoveryAgent::error() const
{
@@ -425,6 +429,8 @@ QBluetoothServiceDiscoveryAgent::Error QBluetoothServiceDiscoveryAgent::error()
/*!
Returns a human-readable description of the last error that occurred during the
service discovery.
+
+ \sa error(), errorOccurred()
*/
QString QBluetoothServiceDiscoveryAgent::errorString() const
{