Remove the use of the deprecated TYPE_ORIENTATION sensor.

The compass engine has not adjusted the heading according to the device orientation. This causes wrong heading if the device is not in its normal orientation.
This commit is contained in:
Tsoi Yat Shing
2020-04-16 11:31:25 +08:00
committed by Łukasz Paczos
parent ec15d862db
commit 7367a49de0

View File

@@ -69,16 +69,10 @@ class LocationComponentCompassEngine implements CompassEngine, SensorEventListen
this.sensorManager = sensorManager;
compassSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
if (compassSensor == null) {
if (isGyroscopeAvailable()) {
Logger.d(TAG, "Rotation vector sensor not supported on device, "
+ "falling back to orientation.");
compassSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
} else {
Logger.d(TAG, "Rotation vector sensor not supported on device, "
+ "falling back to accelerometer and magnetic field.");
gravitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magneticFieldSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
}
Logger.d(TAG, "Rotation vector sensor not supported on device, "
+ "falling back to accelerometer and magnetic field.");
gravitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magneticFieldSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
}
}
@@ -122,8 +116,6 @@ class LocationComponentCompassEngine implements CompassEngine, SensorEventListen
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
rotationVectorValue = getRotationVectorFromSensorEvent(event);
updateOrientation();
} else if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {
notifyCompassChangeListeners((event.values[0] + 360) % 360);
} else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
gravityValues = lowPassFilter(getRotationVectorFromSensorEvent(event), gravityValues);
updateOrientation();
@@ -146,10 +138,6 @@ class LocationComponentCompassEngine implements CompassEngine, SensorEventListen
}
}
private boolean isGyroscopeAvailable() {
return sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null;
}
@SuppressWarnings("SuspiciousNameCombination")
private void updateOrientation() {
if (rotationVectorValue != null) {