summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothserviceinfo_winrt.cpp
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2018-08-06 09:58:11 +0200
committerOliver Wolff <oliver.wolff@qt.io>2018-08-13 08:47:34 +0000
commit7367f79504c5f8531ce390e2f34b8f4d4f3b1b28 (patch)
treed7870c314f326c1b8fae112bff4b98632abe41d9 /src/bluetooth/qbluetoothserviceinfo_winrt.cpp
parentbc0a27c40a588f005059f9bf0ca38915e7270959 (diff)
winrt: Make device radio discoverable when listening on socket
Microsoft changed the default behavior so that the device is no longer radio discoverable, when advertising is started. By creating the service provider from the Xaml thread we avoid messages, that it cannot be used in the background by default (even though this does not seem to have an effect on its functionality). Change-Id: Ib199adc53ef02b14fcea2884fe4359ad2fe81b8e Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth/qbluetoothserviceinfo_winrt.cpp')
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_winrt.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp
index fd77662a..66550630 100644
--- a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp
@@ -41,6 +41,7 @@
#include "qbluetoothserviceinfo_p.h"
#include "qbluetoothserver_p.h"
+#include <QtCore/private/qeventdispatcher_winrt_p.h>
#include <QtCore/QLoggingCategory>
#ifdef CLASSIC_APP_BUILD
#define Q_OS_WINRT
@@ -337,7 +338,12 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
IID_PPV_ARGS(&providerStatics));
Q_ASSERT_SUCCEEDED(hr);
ComPtr<IAsyncOperation<RfcommServiceProvider *>> op;
- hr = providerStatics->CreateAsync(serviceId.Get(), &op);
+ hr = QEventDispatcherWinRT::runOnXamlThread([providerStatics, serviceId, &op]
+ {
+ HRESULT hr;
+ hr = providerStatics->CreateAsync(serviceId.Get(), &op);
+ return hr;
+ });
Q_ASSERT_SUCCEEDED(hr);
hr = QWinRTFunctions::await(op, serviceProvider.GetAddressOf());
if (hr == HRESULT_FROM_WIN32(ERROR_DEVICE_NOT_AVAILABLE)) {
@@ -371,7 +377,14 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
return false;
}
- hr = serviceProvider->StartAdvertising(listener.Get());
+ ComPtr<IRfcommServiceProvider2> serviceProvider2;
+ hr = serviceProvider.As(&serviceProvider2);
+ Q_ASSERT_SUCCEEDED(hr);
+ hr = QEventDispatcherWinRT::runOnXamlThread([listener, serviceProvider2] {
+ HRESULT hr;
+ hr = serviceProvider2->StartAdvertisingWithRadioDiscoverability(listener.Get(), true);
+ return hr;
+ });
if (FAILED(hr)) {
qCWarning(QT_BT_WINRT) << Q_FUNC_INFO << "Could not start advertising. Check your SDP data.";
return false;