From 95b437b54cac265b5eb78689a46ddc676024a720 Mon Sep 17 00:00:00 2001 From: Tarja Sundqvist Date: Mon, 8 Nov 2021 18:28:23 +0200 Subject: Bump version --- .qmake.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.qmake.conf b/.qmake.conf index ed89f696..739075aa 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -3,7 +3,7 @@ CONFIG += warning_clean DEFINES += QT_NO_JAVA_STYLE_ITERATORS QT_NO_LINKED_LIST -MODULE_VERSION = 5.15.7 +MODULE_VERSION = 5.15.8 # Adds a way to debug location. The define is needed for multiple subprojects as they # include the essential headers. -- cgit v1.2.3 From ec43d4172bf2d8243c546a737c3f930009559459 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Mon, 8 Nov 2021 17:30:12 +0100 Subject: Fix position handling in geoclue2 plugin The pre-existing code was incorrect due to the operation priority. The result of the comparison was assigned to the variables, so they were always initialized with 0 or 1 instead of real values. Also use std::numeric_limits::lowest(), because the altitude can have a negative value (when we are below sea level). This commit is a manual cherry-pick from qtpositioning.git dev branch Fixes: QTBUG-97722 Change-Id: I2d5beddfdf6d7b4fc626d6b09f4923c968016428 (cherry picked from commit 70b7818e1fc585f8bac43b721f3dd172b7489d07) Reviewed-by: Juha Vuolle --- .../position/geoclue2/qgeopositioninfosource_geoclue2.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp b/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp index 8e54a1ea..7f3eb5db 100644 --- a/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp +++ b/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp @@ -410,7 +410,8 @@ void QGeoPositionInfoSourceGeoclue2::handleNewLocation(const QDBusObjectPath &ol } else { QGeoCoordinate coordinate(location.latitude(), location.longitude()); - if (const auto altitude = location.altitude() > std::numeric_limits::min()) + const auto altitude = location.altitude(); + if (altitude > std::numeric_limits::lowest()) coordinate.setAltitude(altitude); const Timestamp ts = location.timestamp(); @@ -428,9 +429,11 @@ void QGeoPositionInfoSourceGeoclue2::handleNewLocation(const QDBusObjectPath &ol m_lastPositionFromSatellite = qFuzzyCompare(accuracy, 0.0); m_lastPosition.setAttribute(QGeoPositionInfo::HorizontalAccuracy, accuracy); - if (const auto speed = location.speed() >= 0.0) + const auto speed = location.speed(); + if (speed >= 0.0) m_lastPosition.setAttribute(QGeoPositionInfo::GroundSpeed, speed); - if (const auto heading = location.heading() >= 0.0) + const auto heading = location.heading(); + if (heading >= 0.0) m_lastPosition.setAttribute(QGeoPositionInfo::Direction, heading); emit positionUpdated(m_lastPosition); -- cgit v1.2.3 From 45ff6ea68b3d0d510a279f6512cd4b8fc352c729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Heskestad?= Date: Wed, 10 Nov 2021 13:01:34 +0100 Subject: Fix positioning must be enabled and authorized at startup to work on iOS Positioning updates were never starting on iOS if startUpdates was called when positioning was not enabled and authorized. Also removed call to authorizationStatus, with is deprecated and the replacement is too new to be used. [ChangeLog] Fix positioning must be enabled and authorized on startup to work on iOS Fixes: QTBUG-78705 Fixes: QTBUG-92261 Change-Id: Id0c6c6491edd2a55dd47627b4c99984764bca983 (cherry picked from commit 0fe43dd0722b0aca86bdbb11f621cf12da8a5fb7) Reviewed-by: Timur Pocheptsov Reviewed-by: Qt CI Bot --- .../corelocation/qgeopositioninfosource_cl.mm | 94 ++++++++++------------ .../corelocation/qgeopositioninfosource_cl_p.h | 21 ++--- 2 files changed, 53 insertions(+), 62 deletions(-) diff --git a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm index a9a88ebc..24ac1f5f 100644 --- a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm +++ b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm @@ -63,9 +63,8 @@ } - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { - Q_UNUSED(manager) - if (status == kCLAuthorizationStatusNotDetermined) - m_positionInfoSource->requestUpdate(MINIMUM_UPDATE_INTERVAL); + Q_UNUSED(manager); + m_positionInfoSource->changeAuthorizationStatus(status); } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation @@ -112,12 +111,12 @@ QT_BEGIN_NAMESPACE QGeoPositionInfoSourceCL::QGeoPositionInfoSourceCL(QObject *parent) - : QGeoPositionInfoSource(parent) - , m_locationManager(0) - , m_started(false) - , m_updateTimer(0) - , m_updateTimeout(0) - , m_positionError(QGeoPositionInfoSource::NoError) + : QGeoPositionInfoSource(parent), + m_locationManager(0), + m_updatesWanted(false), + m_updateTimer(0), + m_updateTimeout(0), + m_positionError(QGeoPositionInfoSource::NoError) { } @@ -138,45 +137,14 @@ void QGeoPositionInfoSourceCL::setUpdateInterval(int msec) // Must timeout if update takes longer than specified interval m_updateTimeout = msec; - if (m_started) setTimeoutInterval(m_updateTimeout); + if (m_updatesWanted) + setTimeoutInterval(m_updateTimeout); } bool QGeoPositionInfoSourceCL::enableLocationManager() { if (!m_locationManager) { - if ([CLLocationManager locationServicesEnabled]) { - // Location Services Are Enabled - switch ([CLLocationManager authorizationStatus]) { - case kCLAuthorizationStatusNotDetermined: - // User has not yet made a choice with regards to this application - break; - case kCLAuthorizationStatusRestricted: - // This application is not authorized to use location services. Due - // to active restrictions on location services, the user cannot change - // this status, and may not have personally denied authorization - return false; - case kCLAuthorizationStatusDenied: - // User has explicitly denied authorization for this application, or - // location services are disabled in Settings - return false; - case kCLAuthorizationStatusAuthorizedAlways: - // This app is authorized to start location services at any time. - break; -#ifndef Q_OS_MACOS - case kCLAuthorizationStatusAuthorizedWhenInUse: - // This app is authorized to start most location services while running in the foreground. - break; -#endif - default: - // By default, try to enable it - break; - } - } else { - // Location Services Disabled - return false; - } - - m_locationManager = [[CLLocationManager alloc] init]; + m_locationManager = [[CLLocationManager alloc] init]; #if defined(Q_OS_IOS) || defined(Q_OS_WATCHOS) if (__builtin_available(watchOS 4.0, *)) { @@ -232,32 +200,37 @@ void QGeoPositionInfoSourceCL::setTimeoutInterval(int msec) void QGeoPositionInfoSourceCL::startUpdates() { + m_positionError = QGeoPositionInfoSource::NoError; + m_updatesWanted = true; if (enableLocationManager()) { #ifdef Q_OS_TVOS [m_locationManager requestLocation]; // service will run long enough for one location update #else [m_locationManager startUpdatingLocation]; #endif - m_started = true; - setTimeoutInterval(m_updateTimeout); - } else setError(QGeoPositionInfoSource::AccessError); + } else { + setError(QGeoPositionInfoSource::AccessError); + } } void QGeoPositionInfoSourceCL::stopUpdates() { if (m_locationManager) { [m_locationManager stopUpdatingLocation]; - m_started = false; + m_updatesWanted = false; // Stop timeout timer setTimeoutInterval(0); - } else setError(QGeoPositionInfoSource::AccessError); + } else { + setError(QGeoPositionInfoSource::AccessError); + } } void QGeoPositionInfoSourceCL::requestUpdate(int timeout) { // Get a single update within timeframe + m_positionError = QGeoPositionInfoSource::NoError; if (timeout < minimumUpdateInterval() && timeout != 0) emit updateTimeout(); else if (enableLocationManager()) { @@ -270,7 +243,21 @@ void QGeoPositionInfoSourceCL::requestUpdate(int timeout) #endif setTimeoutInterval(timeout); - } else setError(QGeoPositionInfoSource::AccessError); + } else { + setError(QGeoPositionInfoSource::AccessError); + } +} + +void QGeoPositionInfoSourceCL::changeAuthorizationStatus(CLAuthorizationStatus status) +{ + if (status == kCLAuthorizationStatusAuthorizedAlways +#ifndef Q_OS_MACOS + || status == kCLAuthorizationStatusAuthorizedWhenInUse +#endif + ) { + if (m_updatesWanted) + startUpdates(); + } } void QGeoPositionInfoSourceCL::timerEvent( QTimerEvent * event ) @@ -283,7 +270,8 @@ void QGeoPositionInfoSourceCL::timerEvent( QTimerEvent * event ) setTimeoutInterval(0); // Started for single update? - if (!m_started) stopUpdates(); + if (!m_updatesWanted) + stopUpdates(); } } @@ -305,7 +293,8 @@ void QGeoPositionInfoSourceCL::locationDataAvailable(QGeoPositionInfo location) emit positionUpdated(location); // Started for single update? - if (!m_started) stopUpdates(); + if (!m_updatesWanted) + stopUpdates(); // ...otherwise restart timeout timer else setTimeoutInterval(m_updateTimeout); } @@ -325,7 +314,8 @@ QGeoPositionInfoSource::Error QGeoPositionInfoSourceCL::error() const void QGeoPositionInfoSourceCL::setError(QGeoPositionInfoSource::Error positionError) { m_positionError = positionError; - emit QGeoPositionInfoSource::error(positionError); + if (m_positionError != QGeoPositionInfoSource::NoError) + emit QGeoPositionInfoSource::error(positionError); } QT_END_NAMESPACE diff --git a/src/plugins/position/corelocation/qgeopositioninfosource_cl_p.h b/src/plugins/position/corelocation/qgeopositioninfosource_cl_p.h index 06367c21..0fb009f9 100644 --- a/src/plugins/position/corelocation/qgeopositioninfosource_cl_p.h +++ b/src/plugins/position/corelocation/qgeopositioninfosource_cl_p.h @@ -65,33 +65,34 @@ public: QGeoPositionInfoSourceCL(QObject *parent = 0); ~QGeoPositionInfoSourceCL(); - QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const; - PositioningMethods supportedPositioningMethods() const; + QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const override; + PositioningMethods supportedPositioningMethods() const override; - void setUpdateInterval(int msec); - int minimumUpdateInterval() const; - Error error() const; + void setUpdateInterval(int msec) override; + int minimumUpdateInterval() const override; + Error error() const override; void locationDataAvailable(QGeoPositionInfo location); void setError(QGeoPositionInfoSource::Error positionError); + void changeAuthorizationStatus(CLAuthorizationStatus status); private: bool enableLocationManager(); void setTimeoutInterval(int msec); public Q_SLOTS: - void startUpdates(); - void stopUpdates(); + void startUpdates() override; + void stopUpdates() override; - void requestUpdate(int timeout = 0); + void requestUpdate(int timeout = 0) override; protected: - virtual void timerEvent(QTimerEvent *event); + void timerEvent(QTimerEvent *event) override; private: Q_DISABLE_COPY(QGeoPositionInfoSourceCL); CLLocationManager *m_locationManager; - bool m_started; + bool m_updatesWanted; QGeoPositionInfo m_lastUpdate; -- cgit v1.2.3