summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2019-01-03 10:46:38 +0100
committerOliver Wolff <oliver.wolff@qt.io>2019-01-14 12:43:13 +0000
commit9dbd90e65b23d4b5fda883d03d24bedc5127229b (patch)
tree08382b52d58cd68f47172e503c4d3c9da8f2518b
parentab3b9aa97eed760993ffa6908066aaf85ec77920 (diff)
downloadqtlocation-9dbd90e65b23d4b5fda883d03d24bedc5127229b.tar.gz
winrt: Check access to location service on every call
The access to location services can change while the application is running so checking the access only once does not work. If access is not granted set the proper error code. Change-Id: I00d82dd166d049363de1dc9b0ca7015bc494baf5 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp b/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp
index c4c2c1ca..ac841be7 100644
--- a/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp
+++ b/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp
@@ -314,8 +314,10 @@ bool QGeoPositionInfoSourceWinRT::startHandler()
return false;
}
- if (!requestAccess())
+ if (!requestAccess()) {
+ setError(QGeoPositionInfoSource::AccessError);
return false;
+ }
HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([this, d]() {
HRESULT hr;
@@ -436,6 +438,13 @@ QGeoPositionInfoSource::Error QGeoPositionInfoSourceWinRT::error() const
{
Q_D(const QGeoPositionInfoSourceWinRT);
qCDebug(lcPositioningWinRT) << __FUNCTION__ << d->positionError;
+
+ // If the last encountered error was "Access denied", it is possible that the location service
+ // has been enabled by now so that we are clear again.
+ if ((d->positionError == QGeoPositionInfoSource::AccessError
+ || d->positionError == QGeoPositionInfoSource::UnknownSourceError) && requestAccess())
+ return QGeoPositionInfoSource::NoError;
+
return d->positionError;
}
@@ -595,21 +604,18 @@ HRESULT QGeoPositionInfoSourceWinRT::onStatusChanged(IGeolocator *, IStatusChang
bool QGeoPositionInfoSourceWinRT::requestAccess() const
{
qCDebug(lcPositioningWinRT) << __FUNCTION__;
- static GeolocationAccessStatus accessStatus = GeolocationAccessStatus_Unspecified;
+ GeolocationAccessStatus accessStatus;
static ComPtr<IGeolocatorStatics> statics;
- if (accessStatus == GeolocationAccessStatus_Allowed)
- return true;
- else if (accessStatus == GeolocationAccessStatus_Denied)
- return false;
-
ComPtr<IAsyncOperation<GeolocationAccessStatus>> op;
HRESULT hr;
hr = QEventDispatcherWinRT::runOnXamlThread([&op]() {
HRESULT hr;
- hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Geolocation_Geolocator).Get(),
- IID_PPV_ARGS(&statics));
- RETURN_HR_IF_FAILED("Could not access Geolocation Statics.");
+ if (!statics) {
+ hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Geolocation_Geolocator).Get(),
+ IID_PPV_ARGS(&statics));
+ RETURN_HR_IF_FAILED("Could not access Geolocation Statics.");
+ }
hr = statics->RequestAccessAsync(&op);
return hr;