From 330439186653e3557643424cc13ab437cc01f7dd Mon Sep 17 00:00:00 2001 From: Tarja Sundqvist Date: Mon, 7 Jun 2021 18:01:35 +0300 Subject: Bump version --- .qmake.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.qmake.conf b/.qmake.conf index e62ae21d..d7055d75 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -2,4 +2,4 @@ load(qt_build_config) DEFINES += QT_NO_FOREACH QT_NO_JAVA_STYLE_ITERATORS QT_NO_LINKED_LIST -MODULE_VERSION = 5.15.5 +MODULE_VERSION = 5.15.6 -- cgit v1.2.3 From 52fdaeec67e87250f41ecf64901f2401a9a49091 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Fri, 9 Jul 2021 11:20:16 +0200 Subject: Improve detection of enabled location service on SDK<28 Bluetooth seems to be non-functional when location services are disabled. This is not documented in Android's documentations, but several bug entries exist about this which are closed as "works as intended". See the linked bug entry for details. Our code thus tries to detect whether location services are enabled. This patch improves the detection of enabled location services. While the previous code did only check for GPS and Network location providers, the new code should detect any enabled location provider. Fixes: QTBUG-90760 Change-Id: I0c670296d0af62161dbc3fca40889996fa91f0ca Reviewed-by: Oliver Wolff Reviewed-by: Alex Blasche (cherry picked from commit 4fdcd2d8d2c2b47ec142b744ad291c1e134db7d4) Reviewed-by: Qt CI Bot --- .../qbluetoothdevicediscoveryagent_android.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp index 2ca6f881..92140ced 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp @@ -198,18 +198,15 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent if (QtAndroid::androidSdkVersion() >= 28) { locationTurnedOn = bool(locService.callMethod("isLocationEnabled")); } else { - // try GPS and network provider - QAndroidJniObject provider = QAndroidJniObject::getStaticObjectField( - "android/location/LocationManager", "GPS_PROVIDER", "Ljava/lang/String;"); - bool gpsTurnedOn = bool(locService.callMethod("isProviderEnabled", - "(Ljava/lang/String;)Z", provider.object())); - - provider = QAndroidJniObject::getStaticObjectField( - "android/location/LocationManager", "NETWORK_PROVIDER", "Ljava/lang/String;"); - bool providerTurnedOn = bool(locService.callMethod("isProviderEnabled", - "(Ljava/lang/String;)Z", provider.object())); - - locationTurnedOn = gpsTurnedOn || providerTurnedOn; + // check whether there is any enabled provider + QAndroidJniObject listOfEnabledProviders = + locService.callObjectMethod("getProviders", "(Z)Ljava/util/List;", true); + + if (listOfEnabledProviders.isValid()) { + int size = listOfEnabledProviders.callMethod("size", "()I"); + locationTurnedOn = size > 0; + qCDebug(QT_BT_ANDROID) << size << "enabled location providers detected."; + } } } -- cgit v1.2.3 From 7e727310cf48f3a315ec66d2440bd03676f5982a Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Wed, 31 Mar 2021 10:30:08 +0200 Subject: QWinRTBluetoothDeviceDiscoveryWorker: Add error handling Instead of asserting everywhere, we at least set the error and return gracefully. Fixes: QTBUG-90369 Fixes: QTBUG-95156 Change-Id: I143408b4b30322bb8b490d5848f731f753669015 Reviewed-by: Alex Blasche Reviewed-by: Andreas Buhr (cherry picked from commit 085af5ef811e293377ba92cd12dbda926db27620) --- src/bluetooth/qbluetoothdevicediscoveryagent_p.h | 1 + .../qbluetoothdevicediscoveryagent_winrt.cpp | 286 ++++++++++++++++----- 2 files changed, 221 insertions(+), 66 deletions(-) diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h index c7b4c2b8..4fbaf734 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h @@ -224,6 +224,7 @@ private slots: void registerDevice(const QBluetoothDeviceInfo &info); void updateDeviceData(const QBluetoothAddress &address, QBluetoothDeviceInfo::Fields fields, qint16 rssi, ManufacturerData manufacturerData); + void onErrorOccured(QBluetoothDeviceDiscoveryAgent::Error e); void onScanFinished(); private: diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index a861ae6d..a64f7f0f 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -77,6 +77,13 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(QT_BT_WINRT) +#define EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED(msg, error, ret) \ + if (FAILED(hr)) { \ + emit errorOccured(error); \ + qCWarning(QT_BT_WINRT) << msg; \ + ret; \ + } + #define WARN_AND_RETURN_IF_FAILED(msg, ret) \ if (FAILED(hr)) { \ qCWarning(QT_BT_WINRT) << msg; \ @@ -156,6 +163,7 @@ Q_SIGNALS: void deviceFound(const QBluetoothDeviceInfo &info); void deviceDataChanged(const QBluetoothAddress &address, QBluetoothDeviceInfo::Fields, qint16 rssi, ManufacturerData manufacturerData); + void errorOccured(QBluetoothDeviceDiscoveryAgent::Error error); void scanFinished(); public: @@ -193,9 +201,13 @@ QWinRTBluetoothDeviceDiscoveryWorker::QWinRTBluetoothDeviceDiscoveryWorker(QBlue CoInitialize(NULL); #endif HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Bluetooth_BluetoothDevice).Get(), &m_deviceStatics); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain bluetooth device factory", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return) hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Bluetooth_BluetoothLEDevice).Get(), &m_leDeviceStatics); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain bluetooth le device factory", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return) } QWinRTBluetoothDeviceDiscoveryWorker::~QWinRTBluetoothDeviceDiscoveryWorker() @@ -226,10 +238,14 @@ void QWinRTBluetoothDeviceDiscoveryWorker::stopLEWatcher() { if (m_leWatcher) { HRESULT hr = m_leWatcher->Stop(); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not stop le watcher", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return) if (m_leDeviceAddedToken.value) { hr = m_leWatcher->remove_Received(m_leDeviceAddedToken); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could remove le watcher token", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return) } } } @@ -239,14 +255,18 @@ void QWinRTBluetoothDeviceDiscoveryWorker::startDeviceDiscovery(QBluetoothDevice HString deviceSelector; ComPtr deviceInformationStatics; HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Enumeration_DeviceInformation).Get(), &deviceInformationStatics); - WARN_AND_RETURN_IF_FAILED("Could not obtain device information statics", return); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device information statics", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); if (mode == QBluetoothDeviceDiscoveryAgent::LowEnergyMethod) m_leDeviceStatics->GetDeviceSelector(deviceSelector.GetAddressOf()); else m_deviceStatics->GetDeviceSelector(deviceSelector.GetAddressOf()); ComPtr> op; hr = deviceInformationStatics->FindAllAsyncAqsFilter(deviceSelector.Get(), &op); - WARN_AND_RETURN_IF_FAILED("Could not start bluetooth device discovery operation", return); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not start bluetooth device discovery operation", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); QPointer thisPointer(this); hr = op->put_Completed( Callback>([thisPointer, mode](IAsyncOperation *op, AsyncStatus status) { @@ -254,7 +274,9 @@ void QWinRTBluetoothDeviceDiscoveryWorker::startDeviceDiscovery(QBluetoothDevice thisPointer->onDeviceDiscoveryFinished(op, mode); return S_OK; }).Get()); - WARN_AND_RETURN_IF_FAILED("Could not add callback to bluetooth device discovery operation", return); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not add device discovery callback", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); } void QWinRTBluetoothDeviceDiscoveryWorker::onDeviceDiscoveryFinished(IAsyncOperation *op, QBluetoothDeviceDiscoveryAgent::DiscoveryMethod mode) @@ -264,10 +286,14 @@ void QWinRTBluetoothDeviceDiscoveryWorker::onDeviceDiscoveryFinished(IAsyncOpera ComPtr> devices; HRESULT hr; hr = op->GetResults(&devices); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain discovery result", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); quint32 deviceCount; hr = devices->get_Size(&deviceCount); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain discovery result size", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); // For classic discovery only paired devices will be found. If we only do classic disovery and // no device is found, the scan is finished. @@ -286,7 +312,9 @@ void QWinRTBluetoothDeviceDiscoveryWorker::gatherDeviceInformation(IDeviceInform HString deviceId; HRESULT hr; hr = deviceInfo->get_Id(deviceId.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device ID", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); if (mode == QBluetoothDeviceDiscoveryAgent::LowEnergyMethod) leBluetoothInfoFromDeviceIdAsync(deviceId.Get()); else @@ -299,7 +327,9 @@ void QWinRTBluetoothDeviceDiscoveryWorker::gatherMultipleDeviceInformation(quint ComPtr device; HRESULT hr; hr = devices->GetAt(i, &device); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); gatherDeviceInformation(device.Get(), mode); } } @@ -307,24 +337,34 @@ void QWinRTBluetoothDeviceDiscoveryWorker::gatherMultipleDeviceInformation(quint void QWinRTBluetoothDeviceDiscoveryWorker::setupLEDeviceWatcher() { HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Devices_Bluetooth_Advertisement_BluetoothLEAdvertisementWatcher).Get(), &m_leWatcher); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not create advertisment watcher", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); #if QT_CONFIG(winrt_btle_no_pairing) if (supportsNewLEApi()) { hr = m_leWatcher->put_ScanningMode(BluetoothLEScanningMode_Active); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not set scanning mode", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); } #endif // winrt_btle_no_pairing hr = m_leWatcher->add_Received(Callback>([this](IBluetoothLEAdvertisementWatcher *, IBluetoothLEAdvertisementReceivedEventArgs *args) { quint64 address; HRESULT hr; hr = args->get_BluetoothAddress(&address); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain bluetooth address", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); qint16 rssi; hr = args->get_RawSignalStrengthInDBm(&rssi); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain signal strength", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); ComPtr ad; hr = args->get_Advertisement(&ad); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could get advertisement", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); const ManufacturerData manufacturerData = extractManufacturerData(ad); QBluetoothDeviceInfo::Fields changedFields = QBluetoothDeviceInfo::Field::None; if (!m_foundLEManufacturerData.contains(address)) { @@ -338,15 +378,21 @@ void QWinRTBluetoothDeviceDiscoveryWorker::setupLEDeviceWatcher() if (supportsNewLEApi()) { ComPtr> guids; hr = ad->get_ServiceUuids(&guids); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain service uuid list", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); quint32 size; hr = guids->get_Size(&size); - Q_ASSERT_SUCCEEDED(hr); QVector serviceUuids; + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain service uuid list size", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); for (quint32 i = 0; i < size; ++i) { GUID guid; hr = guids->GetAt(i, &guid); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain uuid", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); QBluetoothUuid uuid(guid); serviceUuids.append(uuid); } @@ -409,9 +455,13 @@ void QWinRTBluetoothDeviceDiscoveryWorker::setupLEDeviceWatcher() leBluetoothInfoFromAddressAsync(address); return S_OK; }).Get(), &m_leDeviceAddedToken); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not add device callback", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); hr = m_leWatcher->Start(); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not start device watcher", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return); } void QWinRTBluetoothDeviceDiscoveryWorker::finishDiscovery() @@ -458,7 +508,12 @@ void QWinRTBluetoothDeviceDiscoveryWorker::classicBluetoothInfoFromDeviceIdAsync } return S_OK; }); - Q_ASSERT_SUCCEEDED(hr); + if (FAILED(hr)) { + emit errorOccured(QBluetoothDeviceDiscoveryAgent::UnknownError); + --m_pendingPairedDevices; + qCWarning(QT_BT_WINRT) << "Could not obtain bluetooth device from id"; + return; + } } // "deviceFound" will be emitted at the end of the deviceFromIdOperation callback @@ -492,7 +547,12 @@ void QWinRTBluetoothDeviceDiscoveryWorker::leBluetoothInfoFromDeviceIdAsync(HSTR } return S_OK; }); - Q_ASSERT_SUCCEEDED(hr); + if (FAILED(hr)) { + emit errorOccured(QBluetoothDeviceDiscoveryAgent::UnknownError); + --m_pendingPairedDevices; + qCWarning(QT_BT_WINRT) << "Could not obtain bluetooth device from id"; + return; + } } // "deviceFound" will be emitted at the end of the deviceFromAdressOperation callback @@ -522,7 +582,11 @@ void QWinRTBluetoothDeviceDiscoveryWorker::leBluetoothInfoFromAddressAsync(quint } return S_OK; }); - Q_ASSERT_SUCCEEDED(hr); + if (FAILED(hr)) { + emit errorOccured(QBluetoothDeviceDiscoveryAgent::UnknownError); + qCWarning(QT_BT_WINRT) << "Could not obtain bluetooth device from id"; + return; + } } HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onPairedClassicBluetoothDeviceFoundAsync(IAsyncOperation *op, AsyncStatus status) @@ -533,7 +597,9 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onPairedClassicBluetoothDeviceFoun ComPtr device; HRESULT hr = op->GetResults(&device); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain bluetooth device", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); if (!device) return S_OK; @@ -543,35 +609,53 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onPairedClassicBluetoothDeviceFoun ComPtr classOfDevice; UINT32 classOfDeviceInt; hr = device->get_BluetoothAddress(&address); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain bluetooth address", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); hr = device->get_Name(name.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device name", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); const QString btName = QString::fromWCharArray(WindowsGetStringRawBuffer(name.Get(), nullptr)); hr = device->get_ClassOfDevice(&classOfDevice); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device class", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); hr = classOfDevice->get_RawValue(&classOfDeviceInt); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain raw value of device class", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); IVectorView *deviceServices; hr = device->get_RfcommServices(&deviceServices); 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); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device services", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); uint serviceCount; hr = deviceServices->get_Size(&serviceCount); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain service list size", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); QVector uuids; for (uint i = 0; i < serviceCount; ++i) { ComPtr service; hr = deviceServices->GetAt(i, &service); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device service", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); ComPtr id; hr = service->get_ServiceId(&id); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain service id", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); GUID uuid; hr = id->get_Uuid(&uuid); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain uuid", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); uuids.append(QBluetoothUuid(uuid)); } @@ -600,7 +684,9 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onPairedBluetoothLEDeviceFoundAsyn ComPtr device; HRESULT hr; hr = op->GetResults(&device); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain bluetooth le device", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); #if QT_CONFIG(winrt_btle_no_pairing) if (supportsNewLEApi()) return onBluetoothLEDeviceFound(device); @@ -617,7 +703,9 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onBluetoothLEDeviceFoundAsync(IAsy ComPtr device; HRESULT hr; hr = op->GetResults(&device); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain bluetooth le device", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); #if QT_CONFIG(winrt_btle_no_pairing) if (supportsNewLEApi()) return onBluetoothLEDeviceFound(device); @@ -636,31 +724,45 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onBluetoothLEDeviceFound(ComPtr device2; HRESULT hr = device.As(&device2); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not cast device to Device2", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); ComPtr deviceInfo; hr = device2->get_DeviceInformation(&deviceInfo); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device info", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); if (!deviceInfo) { qCDebug(QT_BT_WINRT) << "onBluetoothLEDeviceFound: Could not obtain device information"; return S_OK; } ComPtr deviceInfo2; hr = deviceInfo.As(&deviceInfo2); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not cast device to DeviceInfo2", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); ComPtr pairing; hr = deviceInfo2->get_Pairing(&pairing); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain pairing information", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); boolean isPaired; hr = pairing->get_IsPaired(&isPaired); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain pairing status", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); // We need a paired device in order to be able to obtain its information if (!isPaired) { ComPtr> pairingOp; QPointer tPointer(this); hr = pairing.Get()->PairAsync(&pairingOp); - Q_ASSERT_SUCCEEDED(hr); - pairingOp->put_Completed( - Callback>([device, tPointer](IAsyncOperation *op, AsyncStatus status) { + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not initiate pairing", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); + hr = pairingOp->put_Completed( + Callback> + ([device, tPointer] + (IAsyncOperation *op, AsyncStatus status) { if (!tPointer) return S_OK; @@ -670,19 +772,28 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onBluetoothLEDeviceFound(ComPtr result; - op->GetResults(&result); + HRESULT hr; + hr = op->GetResults(&result); + if (FAILED(hr)) { + emit tPointer->errorOccured(QBluetoothDeviceDiscoveryAgent::UnknownError); + qCWarning(QT_BT_WINRT) << "Could not obtain pairing result"; + return S_OK; + } DevicePairingResultStatus pairingStatus; - result.Get()->get_Status(&pairingStatus); - - if (pairingStatus != DevicePairingResultStatus_Paired) { - qCDebug(QT_BT_WINRT) << "Could not pair device"; + hr = result.Get()->get_Status(&pairingStatus); + if (FAILED(hr) || pairingStatus != DevicePairingResultStatus_Paired) { + emit tPointer->errorOccured(QBluetoothDeviceDiscoveryAgent::UnknownError); + qCWarning(QT_BT_WINRT) << "Device pairing failed"; return S_OK; } tPointer->onBluetoothLEDeviceFound(device, OmitPairingCheck); return S_OK; }).Get()); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain register pairing callback", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); return S_OK; } } @@ -690,25 +801,37 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onBluetoothLEDeviceFound(ComPtrget_BluetoothAddress(&address); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain bluetooth address", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); hr = device->get_Name(name.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device name", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); const QString btName = QString::fromWCharArray(WindowsGetStringRawBuffer(name.Get(), nullptr)); IVectorView *deviceServices; hr = device->get_GattServices(&deviceServices); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain gatt service list", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); uint serviceCount; hr = deviceServices->get_Size(&serviceCount); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain gatt service list size", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); QVector uuids; for (uint i = 0; i < serviceCount; ++i) { ComPtr service; hr = deviceServices->GetAt(i, &service); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain gatt service", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); ComPtr id; GUID uuid; hr = service->get_Uuid(&uuid); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain gatt service uuid", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); uuids.append(QBluetoothUuid(uuid)); } const qint16 rssi = m_foundLEDevices.value(address); @@ -742,30 +865,44 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onBluetoothLEDeviceFound(ComPtrget_BluetoothAddress(&address); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain bluetooth address", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); hr = device->get_Name(name.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device name", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); const QString btName = QString::fromWCharArray(WindowsGetStringRawBuffer(name.Get(), nullptr)); ComPtr device2; hr = device.As(&device2); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not cast device", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); ComPtr deviceInfo; hr = device2->get_DeviceInformation(&deviceInfo); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain device info", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); if (!deviceInfo) { qCDebug(QT_BT_WINRT) << "onBluetoothLEDeviceFound: Could not obtain device information"; return S_OK; } ComPtr deviceInfo2; hr = deviceInfo.As(&deviceInfo2); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain cast device info", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); ComPtr pairing; hr = deviceInfo2->get_Pairing(&pairing); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain pairing information", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); boolean isPaired; hr = pairing->get_IsPaired(&isPaired); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain pairing status", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); QVector uuids; const LEAdvertisingInfo adInfo = m_foundLEDevicesMap.value(address); @@ -776,17 +913,25 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onBluetoothLEDeviceFound(ComPtr *deviceServices; hr = device->get_GattServices(&deviceServices); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain gatt service list", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); uint serviceCount; hr = deviceServices->get_Size(&serviceCount); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain gatt service list size", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); for (uint i = 0; i < serviceCount; ++i) { ComPtr service; hr = deviceServices->GetAt(i, &service); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain gatt service", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); GUID uuid; hr = service->get_Uuid(&uuid); - Q_ASSERT_SUCCEEDED(hr); + EMIT_WORKER_ERROR_AND_RETURN_IF_FAILED("Could not obtain uuid", + QBluetoothDeviceDiscoveryAgent::Error::UnknownError, + return S_OK); uuids.append(QBluetoothUuid(uuid)); } } @@ -849,6 +994,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent this, &QBluetoothDeviceDiscoveryAgentPrivate::registerDevice); connect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::deviceDataChanged, this, &QBluetoothDeviceDiscoveryAgentPrivate::updateDeviceData); + connect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::errorOccured, + this, &QBluetoothDeviceDiscoveryAgentPrivate::onErrorOccured); connect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::scanFinished, this, &QBluetoothDeviceDiscoveryAgentPrivate::onScanFinished); worker->start(); @@ -925,6 +1072,13 @@ void QBluetoothDeviceDiscoveryAgentPrivate::updateDeviceData(const QBluetoothAdd } } +void QBluetoothDeviceDiscoveryAgentPrivate::onErrorOccured(QBluetoothDeviceDiscoveryAgent::Error e) +{ + Q_Q(QBluetoothDeviceDiscoveryAgent); + lastError = e; + emit q->error(e); +} + void QBluetoothDeviceDiscoveryAgentPrivate::onScanFinished() { Q_Q(QBluetoothDeviceDiscoveryAgent); -- cgit v1.2.3 From 62a6402d44fe336253af976b01164ae72bbf80e4 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Mon, 26 Jul 2021 12:21:51 +0200 Subject: Doc: Fix typo Fixes: QTBUG-95349 Change-Id: Ie1a7c71a33e5d620d914ffce193a89d080d81af9 Reviewed-by: Alex Blasche (cherry picked from commit eef11fe06c8458b9668f367502a479497831db62) Reviewed-by: Qt Cherry-pick Bot --- src/bluetooth/doc/src/bluetooth-le-overview.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bluetooth/doc/src/bluetooth-le-overview.qdoc b/src/bluetooth/doc/src/bluetooth-le-overview.qdoc index 60181240..7bfc0c44 100644 --- a/src/bluetooth/doc/src/bluetooth-le-overview.qdoc +++ b/src/bluetooth/doc/src/bluetooth-le-overview.qdoc @@ -120,7 +120,7 @@ Low Energy devices. \row \li 0x0004 \li 0x2803 - \li UUID 0x2A08, Value handle: 0x0006 + \li UUID 0x2A08, Value handle: 0x0005 \li Characteristic of type Date Time \row \li 0x0005 -- cgit v1.2.3