diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2018-11-23 09:49:07 +0100 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2018-11-28 06:36:20 +0000 |
commit | 4f6e1d3d5542749e265c0d3ed0953ca66174ce49 (patch) | |
tree | 9d2e89a0876acb5b6c125c7b5352c53d75db46f7 | |
parent | d16a2c0849ad7280893f3fe5259fd6fbd974ce72 (diff) | |
download | qtlocation-4f6e1d3d5542749e265c0d3ed0953ca66174ce49.tar.gz |
winrt: Check availability in requestAccess on desktop builds
For some reason the native status is always Disabled for desktop builds
(even though the location service is running).
So with desktop builds we have to use requestAccess to gain information
about the state of the location service. As the functionality is async the
important parts of QWinRTFunctions are shadowed locally.
Change-Id: I575ee0b161de734c29453a7a07350bc8d09720e8
Reviewed-by: Andre de la Rocha <andre.rocha@qt.io>
Reviewed-by: Miguel Costa <miguel.costa@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r-- | src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp b/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp index 1a2554b0..025a2c9c 100644 --- a/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp +++ b/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp @@ -73,7 +73,36 @@ HRESULT runOnXamlThread(const std::function<HRESULT ()> &delegate, bool waitForR return delegate(); } } -#endif + +static inline HRESULT await(const ComPtr<IAsyncOperation<GeolocationAccessStatus>> &asyncOp, + GeolocationAccessStatus *result) +{ + ComPtr<IAsyncInfo> asyncInfo; + HRESULT hr = asyncOp.As(&asyncInfo); + if (FAILED(hr)) + return hr; + + AsyncStatus status; + while (SUCCEEDED(hr = asyncInfo->get_Status(&status)) && status == AsyncStatus::Started) + QThread::yieldCurrentThread(); + + if (FAILED(hr) || status != AsyncStatus::Completed) { + HRESULT ec; + hr = asyncInfo->get_ErrorCode(&ec); + if (FAILED(hr)) + return hr; + hr = asyncInfo->Close(); + if (FAILED(hr)) + return hr; + return ec; + } + + if (FAILED(hr)) + return hr; + + return asyncOp->GetResults(result); +} +#endif // !Q_OS_WINRT class QGeoPositionInfoSourceWinRTPrivate { public: @@ -92,6 +121,7 @@ public: PositionStatus QGeoPositionInfoSourceWinRTPrivate::nativeStatus() const { +#ifdef Q_OS_WINRT qCDebug(lcPositioningWinRT) << __FUNCTION__; PositionStatus status; @@ -103,8 +133,12 @@ PositionStatus QGeoPositionInfoSourceWinRTPrivate::nativeStatus() const return PositionStatus_NotAvailable; } return status; +#else + return PositionStatus_Ready; +#endif } + QGeoPositionInfoSourceWinRT::QGeoPositionInfoSourceWinRT(QObject *parent) : QGeoPositionInfoSource(parent) , d_ptr(new QGeoPositionInfoSourceWinRTPrivate) @@ -570,7 +604,6 @@ HRESULT QGeoPositionInfoSourceWinRT::onStatusChanged(IGeolocator*, IStatusChange bool QGeoPositionInfoSourceWinRT::requestAccess() const { -#ifdef Q_OS_WINRT qCDebug(lcPositioningWinRT) << __FUNCTION__; static GeolocationAccessStatus accessStatus = GeolocationAccessStatus_Unspecified; static ComPtr<IGeolocatorStatics> statics; @@ -594,11 +627,12 @@ bool QGeoPositionInfoSourceWinRT::requestAccess() const Q_ASSERT_SUCCEEDED(hr); // We cannot wait inside the XamlThread as that would deadlock +#ifdef Q_OS_WINRT QWinRTFunctions::await(op, &accessStatus); +#else + await(op, &accessStatus); +#endif return accessStatus == GeolocationAccessStatus_Allowed; -#else // Q_OS_WINRT - return true; -#endif // Q_OS_WINRT } QT_END_NAMESPACE |