Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e360ad7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I144487d3,I893397c9

* changes:
  Indicate sensor discontinuity via SensorEvent
  Clarify optionality of velocity in head tracker sensor
parents 3d6d75b4 ddeb9c36
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16997,6 +16997,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;
@@ -17008,7 +17009,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 {
+25 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware;

import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.compat.annotation.UnsupportedAppUsage;

/**
@@ -664,16 +665,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.
     *
     * <ul>
     *  <li> values[0] : X component of Euler vector representing rotation</li>
     *  <li> values[1] : Y component of Euler vector representing rotation</li>
     *  <li> values[2] : Z component of Euler vector representing rotation</li>
     *  <li> values[3] : X component of Euler vector representing angular velocity</li>
     *  <li> values[4] : Y component of Euler vector representing angular velocity</li>
     *  <li> values[5] : Z component of Euler vector representing angular velocity</li>
     *  <li> values[3] : X component of Euler vector representing angular velocity (if
     *  supported, otherwise 0)</li>
     *  <li> values[4] : Y component of Euler vector representing angular velocity (if
     *  supported, otherwise 0)</li>
     *  <li> values[5] : Z component of Euler vector representing angular velocity (if
     *  supported, otherwise 0)</li>
     * </ul>
     *
     * <h4>{@link android.hardware.Sensor#TYPE_ACCELEROMETER_LIMITED_AXES
@@ -820,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];
+0 −19
Original line number Diff line number Diff line
@@ -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) {}
}
+4 −4
Original line number Diff line number Diff line
@@ -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;
                }
            }