diff options
author | Andy Shaw <andy.shaw@qt.io> | 2018-01-25 10:14:16 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2018-01-25 09:42:20 +0000 |
commit | 39a7ba2d666c52c3dd732483619cadf6b7a49d60 (patch) | |
tree | f8647647bf079f995b06738a8f15ed40aac00985 | |
parent | b274a83bf4f44d0e2642a8e3bd6bada4ccdbf83c (diff) |
Windows: Do not assert due to insufficient access
If the device does not give access to obtain the list of services, then
it should not throw an assert as the connection still succeeded, but
the device cannot be used.
Change-Id: I650eaba085f30c3cdc9980dd53de63482c7e7531
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
-rw-r--r-- | src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index 6786ac54..c97325cc 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -374,34 +374,39 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onPairedClassicBluetoothDeviceFoun Q_ASSERT_SUCCEEDED(hr); IVectorView <Rfcomm::RfcommDeviceService *> *deviceServices; hr = device->get_RfcommServices(&deviceServices); - Q_ASSERT_SUCCEEDED(hr); - uint serviceCount; - hr = deviceServices->get_Size(&serviceCount); - Q_ASSERT_SUCCEEDED(hr); - QList<QBluetoothUuid> uuids; - for (uint i = 0; i < serviceCount; ++i) { - ComPtr<Rfcomm::IRfcommDeviceService> service; - hr = deviceServices->GetAt(i, &service); + if (hr == E_ACCESSDENIED) { + qCWarning(QT_BT_WINRT) << "Could not obtain device services. Please check you have " + "permission to access the device."; + } else { Q_ASSERT_SUCCEEDED(hr); - ComPtr<Rfcomm::IRfcommServiceId> id; - hr = service->get_ServiceId(&id); + uint serviceCount; + hr = deviceServices->get_Size(&serviceCount); Q_ASSERT_SUCCEEDED(hr); - GUID uuid; - hr = id->get_Uuid(&uuid); - Q_ASSERT_SUCCEEDED(hr); - uuids.append(QBluetoothUuid(uuid)); - } + QList<QBluetoothUuid> uuids; + for (uint i = 0; i < serviceCount; ++i) { + ComPtr<Rfcomm::IRfcommDeviceService> service; + hr = deviceServices->GetAt(i, &service); + Q_ASSERT_SUCCEEDED(hr); + ComPtr<Rfcomm::IRfcommServiceId> id; + hr = service->get_ServiceId(&id); + Q_ASSERT_SUCCEEDED(hr); + GUID uuid; + hr = id->get_Uuid(&uuid); + Q_ASSERT_SUCCEEDED(hr); + uuids.append(QBluetoothUuid(uuid)); + } - qCDebug(QT_BT_WINRT) << "Discovered BT device: " << QString::number(address) << btName - << "Num UUIDs" << uuids.count(); + qCDebug(QT_BT_WINRT) << "Discovered BT device: " << QString::number(address) << btName + << "Num UUIDs" << uuids.count(); - QBluetoothDeviceInfo info(QBluetoothAddress(address), btName, classOfDeviceInt); - info.setCoreConfigurations(QBluetoothDeviceInfo::BaseRateCoreConfiguration); - info.setServiceUuids(uuids, QBluetoothDeviceInfo::DataIncomplete); - info.setCached(true); + QBluetoothDeviceInfo info(QBluetoothAddress(address), btName, classOfDeviceInt); + info.setCoreConfigurations(QBluetoothDeviceInfo::BaseRateCoreConfiguration); + info.setServiceUuids(uuids, QBluetoothDeviceInfo::DataIncomplete); + info.setCached(true); - QMetaObject::invokeMethod(this, "deviceFound", Qt::AutoConnection, - Q_ARG(QBluetoothDeviceInfo, info)); + QMetaObject::invokeMethod(this, "deviceFound", Qt::AutoConnection, + Q_ARG(QBluetoothDeviceInfo, info)); + } if (!m_pendingPairedDevices && !(requestedModes & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod)) finishDiscovery(); return S_OK; |