|
| 1 | +diff --git a/src/plugins/position/android/jar/src/org/qtproject/qt/android/positioning/QtPositioning.java b/src/plugins/position/android/jar/src/org/qtproject/qt/android/positioning/QtPositioning.java |
| 2 | +index e4163b09..afb2889e 100644 |
| 3 | +--- a/src/plugins/position/android/jar/src/org/qtproject/qt/android/positioning/QtPositioning.java |
| 4 | ++++ b/src/plugins/position/android/jar/src/org/qtproject/qt/android/positioning/QtPositioning.java |
| 5 | +@@ -112,6 +112,8 @@ class QtPositioning implements LocationListener |
| 6 | + static private void addMslAltitude(Location location) |
| 7 | + { |
| 8 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { |
| 9 | ++ if (location.hasMslAltitude()) // Nothing to be done |
| 10 | ++ return; |
| 11 | + if (altitudeConverter == null) |
| 12 | + altitudeConverter = new AltitudeConverter(); |
| 13 | + try { |
| 14 | +diff --git a/src/plugins/position/android/src/jnipositioning.cpp b/src/plugins/position/android/src/jnipositioning.cpp |
| 15 | +index 2b2919fa..0abc2cad 100644 |
| 16 | +--- a/src/plugins/position/android/src/jnipositioning.cpp |
| 17 | ++++ b/src/plugins/position/android/src/jnipositioning.cpp |
| 18 | +@@ -220,7 +220,7 @@ namespace AndroidPositioning { |
| 19 | + return ret; |
| 20 | + } |
| 21 | + |
| 22 | +- QGeoPositionInfo positionInfoFromJavaLocation(const jobject &location) |
| 23 | ++ QGeoPositionInfo positionInfoFromJavaLocation(const jobject &location, bool useAltConverter) |
| 24 | + { |
| 25 | + QGeoPositionInfo info; |
| 26 | + |
| 27 | +@@ -241,8 +241,11 @@ namespace AndroidPositioning { |
| 28 | + coordinate.setAltitude(value); |
| 29 | + } |
| 30 | + // MSL altitude, available in API Level 34+. |
| 31 | +- // It will be available only if we requested it when starting updates. |
| 32 | +- if (QNativeInterface::QAndroidApplication::sdkVersion() >= 34) { |
| 33 | ++ // In API Level 34 it was available only if we manually added it. |
| 34 | ++ // In API Level 35 (and potentially later), it's automatically added |
| 35 | ++ // to the location object, so we need to use it *only* when the user |
| 36 | ++ // set the relevant plugin parameter. |
| 37 | ++ if (useAltConverter && QNativeInterface::QAndroidApplication::sdkVersion() >= 34) { |
| 38 | + attributeExists = jniObject.callMethod<jboolean>("hasMslAltitude"); |
| 39 | + if (attributeExists) { |
| 40 | + const jdouble value = jniObject.callMethod<jdouble>("getMslAltitudeMeters"); |
| 41 | +@@ -451,7 +454,7 @@ namespace AndroidPositioning { |
| 42 | + if (location == nullptr) |
| 43 | + return QGeoPositionInfo(); |
| 44 | + |
| 45 | +- const QGeoPositionInfo info = positionInfoFromJavaLocation(location); |
| 46 | ++ const QGeoPositionInfo info = positionInfoFromJavaLocation(location, useAltitudeConverter); |
| 47 | + |
| 48 | + return info; |
| 49 | + } |
| 50 | +@@ -615,7 +618,6 @@ static void positionUpdated(JNIEnv *env, jobject thiz, QtJniTypes::Location loca |
| 51 | + { |
| 52 | + Q_UNUSED(env); |
| 53 | + Q_UNUSED(thiz); |
| 54 | +- QGeoPositionInfo info = AndroidPositioning::positionInfoFromJavaLocation(location.object()); |
| 55 | + |
| 56 | + QGeoPositionInfoSourceAndroid *source = AndroidPositioning::idToPosSource()->value(androidClassKey); |
| 57 | + if (!source) { |
| 58 | +@@ -623,6 +625,10 @@ static void positionUpdated(JNIEnv *env, jobject thiz, QtJniTypes::Location loca |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | ++ const bool useAltitudeConverter = source->useAltitudeConverter(); |
| 63 | ++ QGeoPositionInfo info = |
| 64 | ++ AndroidPositioning::positionInfoFromJavaLocation(location.object(), useAltitudeConverter); |
| 65 | ++ |
| 66 | + //we need to invoke indirectly as the Looper thread is likely to be not the same thread |
| 67 | + if (!isSingleUpdate) |
| 68 | + QMetaObject::invokeMethod(source, "processPositionUpdate", Qt::AutoConnection, |
0 commit comments