From 1125e32c564158ac9c6cbd22308a75de30e21484 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 6 Jun 2023 14:54:40 +0200 Subject: Windows: fix bluetooth pairing status request When requesting for pairing status, we do not really know if the device is LE or Classic bluetooth device. Because of that, we try both options. The pre-existing code was trying to get an instance of BluetoothDevice first. In practice, the BluetoothDevice::FromBluetoothAddressAsync() method returned a correct BluetoothDevice even for LE devices, which was later leading to an incorrect pairing status, when accessing device.DeviceInformation().PairingStatus(). This patch re-orders the checks, trying to obtain an LE device first. My tests show that this approach works correctly for both LE and Classic devices, because the LE check fails for Classic devices. Note: Qt 6.2 is unaffected by this bug, because it already checks LE devices first. The bug was introduces during one of the later refactorings. Fixes: QTBUG-113318 Change-Id: I93ada1ca681ec2597809ecba117808d68c2dcb8c Reviewed-by: Juha Vuolle (cherry picked from commit 3d234d3b182f1759ecf8e5c092948c15f5c3ea4c) Reviewed-by: Qt Cherry-pick Bot --- src/bluetooth/qbluetoothlocaldevice_winrt.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bluetooth/qbluetoothlocaldevice_winrt.cpp b/src/bluetooth/qbluetoothlocaldevice_winrt.cpp index 72cc4e6a..ec0787dd 100644 --- a/src/bluetooth/qbluetoothlocaldevice_winrt.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_winrt.cpp @@ -465,16 +465,16 @@ static DeviceInformationCollection getAvailableAdapters() DeviceInformationPairing pairingInfoFromAddress(const QBluetoothAddress &address) { const quint64 addr64 = address.toUInt64(); - BluetoothDevice device(nullptr); - bool res = await(BluetoothDevice::FromBluetoothAddressAsync(addr64), device, 5000); - if (res && device) - return device.DeviceInformation().Pairing(); - BluetoothLEDevice leDevice(nullptr); - res = await(BluetoothLEDevice::FromBluetoothAddressAsync(addr64), leDevice, 5000); + bool res = await(BluetoothLEDevice::FromBluetoothAddressAsync(addr64), leDevice, 5000); if (res && leDevice) return leDevice.DeviceInformation().Pairing(); + BluetoothDevice device(nullptr); + res = await(BluetoothDevice::FromBluetoothAddressAsync(addr64), device, 5000); + if (res && device) + return device.DeviceInformation().Pairing(); + return nullptr; } -- cgit v1.2.3