diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2023-11-09 15:45:26 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2023-11-10 10:31:09 +0100 |
commit | 9815fa235e21321a2f4719a8f4b6f9837904d976 (patch) | |
tree | 2532af532884d5cba448e6bea34fdc216400775b | |
parent | f323f632ce1f25cbefd13daa613ab8c471ef47e5 (diff) |
BlueZ: treat AuthenticationCanceled as a PairingError
... when it is not triggered from our side.
The linked Jira ticket, as well as some searches over the internet,
show that some devices report org.bluez.Error.AuthenticationCanceled
error when the authentication fails, not when it is canceled.
At the same time, it is also possible to get this error code by trying
to pair with the device, and then immideately cancelling the pairing,
like this:
QBluetoothLocalDevice dev;
dev.requestPairing(address, QBluetoothLocalDevice::Paired);
dev.requestPairing(address, QBluetoothLocalDevice::Unpaired);
The pre-existing code was only considering the latter usecase, and so
was not reporting AuthenticationCanceled as a PairingError.
This patch introduces an extra flag to check if the pairing was canceled
from our side. If that's the case - the old behavior is preserved, and
we do not report an error. In other cases, a PairingError is reported.
Fixes: QTBUG-118895
Pick-to: 6.6 6.5
Change-Id: I1fe246eb8a0da6efb62eddc9a843de7be0f7b2c5
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_bluez.cpp | 10 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_p.h | 1 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp index 63ac8911..7bac1de8 100644 --- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp @@ -169,6 +169,7 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai if (d_ptr->pairingTarget) { qCDebug(QT_BT_BLUEZ) << "Cancelling pending pairing request to" << d_ptr->pairingTarget->address(); QDBusPendingReply<> cancelReply = d_ptr->pairingTarget->CancelPairing(); + d_ptr->pairingRequestCanceled = true; cancelReply.waitForFinished(); delete d_ptr->pairingTarget; d_ptr->pairingTarget = nullptr; @@ -641,12 +642,19 @@ void QBluetoothLocalDevicePrivate::pairingCompleted(QDBusPendingCallWatcher *wat if (reply.isError()) { qCWarning(QT_BT_BLUEZ) << "Failed to create pairing" << reply.error().name(); - if (reply.error().name() != QStringLiteral("org.bluez.Error.AuthenticationCanceled")) + const bool canceledByUs = + (reply.error().name() == QStringLiteral("org.bluez.Error.AuthenticationCanceled")) + && pairingRequestCanceled; + if (!canceledByUs) emit q->errorOccurred(QBluetoothLocalDevice::PairingError); + + pairingRequestCanceled = false; watcher->deleteLater(); return; } + pairingRequestCanceled = false; + if (adapter) { if (!pairingTarget) { qCWarning(QT_BT_BLUEZ) << "Pairing target expected but found null pointer."; diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h index e0a4eb97..d0dad8d7 100644 --- a/src/bluetooth/qbluetoothlocaldevice_p.h +++ b/src/bluetooth/qbluetoothlocaldevice_p.h @@ -120,6 +120,7 @@ public: QTimer *pairingDiscoveryTimer = nullptr; QBluetoothLocalDevice::HostMode currentMode; int pendingHostModeChange; + bool pairingRequestCanceled = false; public slots: void pairingCompleted(QDBusPendingCallWatcher *); |