Commit 7dd40118 authored by John David Taylor's avatar John David Taylor Committed by GitHub

Added an extra check on whether there's a rotation vector. (#157)

* Added an extra check on whether there's a rotation vector - can we actually successfully register a listener?
Log to analytics if we ever find such a beast.  Hard to test since I have no devices which exhibit this behavior.

* Fix a comment
parent bb680544
......@@ -19,6 +19,8 @@ import;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build;
import android.preference.PreferenceManager;
......@@ -280,6 +282,30 @@ public class StardroidApplication extends Application {
private boolean hasDefaultSensor(int sensorType) {
return sensorManager != null && sensorManager.getDefaultSensor(sensorType) != null;
if (sensorManager == null) {
return false;
Sensor sensor = sensorManager.getDefaultSensor(sensorType);
if (sensor == null) {
return false;
SensorEventListener dummy = new SensorEventListener() {
public void onSensorChanged(SensorEvent event) {
// Nothing
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// Nothing
boolean success = sensorManager.registerListener(
dummy, sensor, SensorManager.SENSOR_DELAY_UI);
Analytics.SENSOR_CATEGORY, Analytics.SENSOR_LIAR, Analytics.getSafeNameForSensor(sensor),
return success;
......@@ -111,6 +111,8 @@ public class Analytics {
public static final String SENSOR_NAME = "Sensor Name";
public static final String HIGH_SENSOR_ACCURACY_ACHIEVED = "High Accuracy Achieved";
public static final String SENSOR_ACCURACY_CHANGED = "Sensor Accuracy Changed";
// Phone claims to have a sensor, but then doesn't allow registration of a listener.
public static final String SENSOR_LIAR = "Sensor Liar";
Analytics(StardroidApplication application) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment