From 0c285639a7c8f45bb91eb0cc9f5bb3fe712eb6f6 Mon Sep 17 00:00:00 2001 From: Brian Duddie Date: Mon, 14 Feb 2022 10:41:29 -0800 Subject: [PATCH 1/2] Clarify optionality of velocity in head tracker sensor Bug: 218911221 Test: n/a, comment update only Change-Id: I893397c9446e5c976e3dc9e68d65d67e7128ba9e --- core/java/android/hardware/SensorEvent.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/java/android/hardware/SensorEvent.java b/core/java/android/hardware/SensorEvent.java index 45d4c09921a64..f68fb9d5db566 100644 --- a/core/java/android/hardware/SensorEvent.java +++ b/core/java/android/hardware/SensorEvent.java @@ -664,16 +664,20 @@ public class SensorEvent { * The first three elements provide the transform from the (arbitrary, possibly slowly drifting) * reference frame to the head frame. The magnitude of this vector is in range [0, π] * radians, while the value of individual axes is in range [-π, π]. The next three - * elements provide the estimated rotational velocity of the user's head relative to itself, in - * radians per second. + * elements optionally provide the estimated rotational velocity of the user's head relative to + * itself, in radians per second. If a given sensor does not support determining velocity, these + * elements are set to 0. * * * *

{@link android.hardware.Sensor#TYPE_ACCELEROMETER_LIMITED_AXES From ddeb9c3680100b416fc04fedc4429d52f593511d Mon Sep 17 00:00:00 2001 From: Brian Duddie Date: Mon, 14 Feb 2022 10:42:04 -0800 Subject: [PATCH 2/2] 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 --- core/api/current.txt | 2 +- core/java/android/hardware/SensorEvent.java | 16 ++++++++++++++++ .../android/hardware/SensorEventCallback.java | 19 ------------------- .../android/hardware/SystemSensorManager.java | 8 ++++---- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 4d1e280f798f9..422fdd03e0516 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -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 { diff --git a/core/java/android/hardware/SensorEvent.java b/core/java/android/hardware/SensorEvent.java index f68fb9d5db566..6113932742852 100644 --- a/core/java/android/hardware/SensorEvent.java +++ b/core/java/android/hardware/SensorEvent.java @@ -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]; diff --git a/core/java/android/hardware/SensorEventCallback.java b/core/java/android/hardware/SensorEventCallback.java index 7b0092da1196c..bac212ab5b209 100644 --- a/core/java/android/hardware/SensorEventCallback.java +++ b/core/java/android/hardware/SensorEventCallback.java @@ -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) {} } diff --git a/core/java/android/hardware/SystemSensorManager.java b/core/java/android/hardware/SystemSensorManager.java index 32a5ee77508ec..18d86d69206f2 100644 --- a/core/java/android/hardware/SystemSensorManager.java +++ b/core/java/android/hardware/SystemSensorManager.java @@ -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; } }