Indicate sensor discontinuity via SensorEvent

Use a bool in SensorEvent rather than a new method in
SensorEventCallback to indicate discontinuities.

Fixes: 217364461
Test: additional CTS test cases pending
CTS-Coverage-Bug: 214618172
Change-Id: I144487d36b2d00d57265c9e3e9f542c7136a33f5
This commit is contained in:
Brian Duddie
2022-02-14 10:42:04 -08:00
parent 0c285639a7
commit ddeb9c3680
4 changed files with 21 additions and 24 deletions

View File

@@ -16988,6 +16988,7 @@ package android.hardware {
public class SensorEvent {
field public int accuracy;
field public boolean firstEventAfterDiscontinuity;
field public android.hardware.Sensor sensor;
field public long timestamp;
field public final float[] values;
@@ -16999,7 +17000,6 @@ package android.hardware {
method public void onFlushCompleted(android.hardware.Sensor);
method public void onSensorAdditionalInfo(android.hardware.SensorAdditionalInfo);
method public void onSensorChanged(android.hardware.SensorEvent);
method public void onSensorDiscontinuity(@NonNull android.hardware.Sensor);
}
public interface SensorEventListener {

View File

@@ -17,6 +17,7 @@
package android.hardware;
import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.compat.annotation.UnsupportedAppUsage;
/**
@@ -824,6 +825,21 @@ public class SensorEvent {
*/
public long timestamp;
/**
* Set to true when this is the first sensor event after a discontinuity.
*
* The exact meaning of discontinuity depends on the sensor type. For
* {@link android.hardware.Sensor#TYPE_HEAD_TRACKER Sensor.TYPE_HEAD_TRACKER}, this means that
* the reference frame has suddenly and significantly changed, for example if the head tracking
* device was removed then put back.
*
* Note that this concept is either not relevant to or not supported by most sensor types,
* {@link android.hardware.Sensor#TYPE_HEAD_TRACKER Sensor.TYPE_HEAD_TRACKER} being the notable
* exception.
*/
@SuppressLint("MutableBareField")
public boolean firstEventAfterDiscontinuity;
@UnsupportedAppUsage
SensorEvent(int valueSize) {
values = new float[valueSize];

View File

@@ -16,8 +16,6 @@
package android.hardware;
import android.annotation.NonNull;
/**
* Used for receiving sensor additional information frames.
*/
@@ -54,21 +52,4 @@ public abstract class SensorEventCallback implements SensorEventListener2 {
* reported from sensor hardware.
*/
public void onSensorAdditionalInfo(SensorAdditionalInfo info) {}
/**
* Called when the next {@link android.hardware.SensorEvent SensorEvent} to be delivered via the
* {@link #onSensorChanged(SensorEvent) onSensorChanged} method represents the first event after
* a discontinuity.
*
* The exact meaning of discontinuity depends on the sensor type. For {@link
* android.hardware.Sensor#TYPE_HEAD_TRACKER Sensor.TYPE_HEAD_TRACKER}, this means that the
* reference frame has suddenly and significantly changed.
*
* Note that this concept is either not relevant to or not supported by most sensor types,
* {@link android.hardware.Sensor#TYPE_HEAD_TRACKER Sensor.TYPE_HEAD_TRACKER} being the notable
* exception.
*
* @param sensor The {@link android.hardware.Sensor Sensor} which experienced the discontinuity.
*/
public void onSensorDiscontinuity(@NonNull Sensor sensor) {}
}

View File

@@ -881,13 +881,13 @@ public class SystemSensorManager extends SensorManager {
mListener.onAccuracyChanged(t.sensor, t.accuracy);
}
// call onSensorDiscontinuity() if the discontinuity counter changed
if (t.sensor.getType() == Sensor.TYPE_HEAD_TRACKER
&& mListener instanceof SensorEventCallback) {
// Indicate if the discontinuity count changed
if (t.sensor.getType() == Sensor.TYPE_HEAD_TRACKER) {
final int lastCount = mSensorDiscontinuityCounts.get(handle);
final int curCount = Float.floatToIntBits(values[6]);
if (lastCount >= 0 && lastCount != curCount) {
((SensorEventCallback) mListener).onSensorDiscontinuity(t.sensor);
mSensorDiscontinuityCounts.put(handle, curCount);
t.firstEventAfterDiscontinuity = true;
}
}