summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@digia.com>2014-06-02 12:46:45 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-02 13:34:04 +0200
commit87b569ccc4df161e33d41f7a5f1f25eced6f65c3 (patch)
tree8149378e060c1bfbc32748e0bb187ed7705506e9
parent9efc5bea41e7acbce55c37b49b167092b71114a9 (diff)
downloadqtsensors-87b569ccc4df161e33d41f7a5f1f25eced6f65c3.tar.gz
qtsensors-87b569ccc4df161e33d41f7a5f1f25eced6f65c3.tar.bz2
qtsensors-87b569ccc4df161e33d41f7a5f1f25eced6f65c3.zip
Android: don't crash if Gravity is not supported
The QtSensors documentation says that if Gravity mode is not available, we should silently fall back to the default Combined mode. In addition, add null pointer checks in case we try to ask for non-existent sensors in the future. Task-number: QTBUG-39335 Change-Id: I6c18622d081db4e3a7d07c744bb0b746e3f5c6ff Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
-rw-r--r--src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java3
-rw-r--r--src/plugins/sensors/android/src/androidaccelerometer.cpp3
-rw-r--r--src/plugins/sensors/android/src/androidjnisensors.cpp2
3 files changed, 8 insertions, 0 deletions
diff --git a/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java b/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java
index 5507b07..efd1ff6 100644
--- a/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java
+++ b/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java
@@ -73,6 +73,9 @@ public class QtSensors implements SensorEventListener
{
try {
Sensor s = m_sensorManager.getDefaultSensor(sensorType);
+ if (s == null) {
+ return null;
+ }
return s.getName() + " " + s.getVendor() + " v" + s.getVersion();
} catch(Exception e) {
e.printStackTrace();
diff --git a/src/plugins/sensors/android/src/androidaccelerometer.cpp b/src/plugins/sensors/android/src/androidaccelerometer.cpp
index 76aa027..74b3d6d 100644
--- a/src/plugins/sensors/android/src/androidaccelerometer.cpp
+++ b/src/plugins/sensors/android/src/androidaccelerometer.cpp
@@ -95,5 +95,8 @@ AndroidSensors::AndroidSensorType AndroidAccelerometer::modeToSensor(QAccelerome
break;
}
+ if (type != AndroidSensors::TYPE_ACCELEROMETER && !AndroidSensors::availableSensors().contains(type))
+ type = AndroidSensors::TYPE_ACCELEROMETER;
+
return type;
}
diff --git a/src/plugins/sensors/android/src/androidjnisensors.cpp b/src/plugins/sensors/android/src/androidjnisensors.cpp
index af39e0b..87889a8 100644
--- a/src/plugins/sensors/android/src/androidjnisensors.cpp
+++ b/src/plugins/sensors/android/src/androidjnisensors.cpp
@@ -113,6 +113,8 @@ namespace AndroidSensors
jstring jstr = static_cast<jstring>(aenv.jniEnv->CallStaticObjectMethod(sensorsClass,
getSensorDescriptionMethodId,
jint(sensor)));
+ if (!jstr)
+ return QString();
const jchar *pstr = aenv.jniEnv->GetStringChars(jstr, 0);
QString ret(reinterpret_cast<const QChar *>(pstr), aenv.jniEnv->GetStringLength(jstr));
aenv.jniEnv->ReleaseStringChars(jstr, pstr);