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

Commit 380043de authored by Jaikumar Ganesh's avatar Jaikumar Ganesh Committed by Android Git Automerger
Browse files

am 9a8df4dc: Add new sensor types.

* commit '9a8df4dc':
  Add new sensor types.
parents 8111f049 9a8df4dc
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -10296,16 +10296,20 @@ package android.hardware {
    field public static final int TYPE_ACCELEROMETER = 1; // 0x1
    field public static final int TYPE_ALL = -1; // 0xffffffff
    field public static final int TYPE_AMBIENT_TEMPERATURE = 13; // 0xd
    field public static final int TYPE_GAME_ROTATION_VECTOR = 15; // 0xf
    field public static final int TYPE_GRAVITY = 9; // 0x9
    field public static final int TYPE_GYROSCOPE = 4; // 0x4
    field public static final int TYPE_GYROSCOPE_UNCALIBRATED = 16; // 0x10
    field public static final int TYPE_LIGHT = 5; // 0x5
    field public static final int TYPE_LINEAR_ACCELERATION = 10; // 0xa
    field public static final int TYPE_MAGNETIC_FIELD = 2; // 0x2
    field public static final int TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14; // 0xe
    field public static final deprecated int TYPE_ORIENTATION = 3; // 0x3
    field public static final int TYPE_PRESSURE = 6; // 0x6
    field public static final int TYPE_PROXIMITY = 8; // 0x8
    field public static final int TYPE_RELATIVE_HUMIDITY = 12; // 0xc
    field public static final int TYPE_ROTATION_VECTOR = 11; // 0xb
    field public static final int TYPE_SIGNIFICANT_MOTION = 17; // 0x11
    field public static final deprecated int TYPE_TEMPERATURE = 7; // 0x7
  }
@@ -10327,6 +10331,7 @@ package android.hardware {
  }
  public abstract class SensorManager {
    method public boolean cancelTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor);
    method public static float getAltitude(float, float);
    method public static void getAngleChange(float[], float[], float[]);
    method public android.hardware.Sensor getDefaultSensor(int);
@@ -10342,6 +10347,7 @@ package android.hardware {
    method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int);
    method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, android.os.Handler);
    method public static boolean remapCoordinateSystem(float[], int, int, float[]);
    method public boolean requestTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor);
    method public deprecated void unregisterListener(android.hardware.SensorListener);
    method public deprecated void unregisterListener(android.hardware.SensorListener, int);
    method public void unregisterListener(android.hardware.SensorEventListener, android.hardware.Sensor);
@@ -10405,6 +10411,17 @@ package android.hardware {
    field public static final float STANDARD_GRAVITY = 9.80665f;
  }
  public final class TriggerEvent {
    field public android.hardware.Sensor sensor;
    field public long timestamp;
    field public final float[] values;
  }
  public abstract class TriggerEventListener {
    ctor public TriggerEventListener();
    method public abstract void onTrigger(android.hardware.TriggerEvent);
  }
}
package android.hardware.display {
+80 −2
Original line number Diff line number Diff line
@@ -114,11 +114,90 @@ public final class Sensor {
    /** A constant describing an ambient temperature sensor type */
    public static final int TYPE_AMBIENT_TEMPERATURE = 13;

    /**
     * A constant describing a magnetic field uncalibrated sensor type. See
     * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
     * details.
     * <p>
     * No periodic calibration is performed (ie: there are no discontinuities
     * in the data stream while using this sensor). Assumptions that the
     * magnetic field is due to the Earth's poles is avoided. Factory calibration
     * and temperature compensation is still performed.
     * </p>
     */
    public static final int TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14;

    /**
     * Identical to {@link #TYPE_ROTATION_VECTOR} except that it doesn't
     * use the geomagnetic field. Therefore the Y axis doesn't
     * point north, but instead to some other reference, that reference is
     * allowed to drift by the same order of magnitude as the gyroscope
     * drift around the Z axis.
     * <p>
     * In the ideal case, a phone rotated and returning to the same real-world
     * orientation should report the same game rotation vector
     * (without using the earth's geomagnetic field). However, the orientation
     * may drift somewhat over time.
     * </p>
     */

    public static final int TYPE_GAME_ROTATION_VECTOR = 15;

    /**
     * A constant describing a gyroscope uncalibrated sensor type. See
     * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
     * details.
     * <p>
     * No gyro-drift compensation is performed.
     * Factory calibration and temperature compensation is still applied
     * to the rate of rotation (angular speeds).
     * </p>
     */
    public static final int TYPE_GYROSCOPE_UNCALIBRATED = 16;

    /**
     * A constant describing the significant motion trigger sensor.
     * See {@link android.hardware.SensorEvent#values} for more details.
     * <p>
     * It triggers when an event occurs and then automatically disables
     * itself. The sensor continues to operate while the device is asleep
     * and will automatically wake the device to notify when significant
     * motion is detected. The application does not need to hold any wake
     * locks for this sensor to trigger.
     * </p>
     */
    public static final int TYPE_SIGNIFICANT_MOTION = 17;

    /**
     * A constant describing all sensor types.
     */
    public static final int TYPE_ALL = -1;

    /* Reporting mode constants for sensors. Each sensor will have exactly one
       reporting mode associated with it. */
    // Events are reported at a constant rate.
    static int REPORTING_MODE_CONTINUOUS = 1;

    // Events are reported only when the value changes.
    static int REPORTING_MODE_ON_CHANGE = 2;

    // Upon detection of an event, the sensor deactivates itself and then sends a single event.
    static int REPORTING_MODE_ONE_SHOT = 3;

    // Note: This needs to be updated, whenever a new sensor is added.
    private static int[] sSensorReportingModes = {
            REPORTING_MODE_CONTINUOUS, REPORTING_MODE_CONTINUOUS, REPORTING_MODE_CONTINUOUS,
            REPORTING_MODE_CONTINUOUS, REPORTING_MODE_ON_CHANGE, REPORTING_MODE_CONTINUOUS,
            REPORTING_MODE_ON_CHANGE, REPORTING_MODE_ON_CHANGE, REPORTING_MODE_CONTINUOUS,
            REPORTING_MODE_CONTINUOUS, REPORTING_MODE_CONTINUOUS, REPORTING_MODE_ON_CHANGE,
            REPORTING_MODE_ON_CHANGE, REPORTING_MODE_CONTINUOUS, REPORTING_MODE_CONTINUOUS,
            REPORTING_MODE_CONTINUOUS, REPORTING_MODE_ONE_SHOT };

    static int getReportingMode(Sensor sensor) {
        // mType starts from offset 1.
        return sSensorReportingModes[sensor.mType - 1];
    }

    /* Some of these fields are set only by the native bindings in
     * SensorManager.
     */
@@ -132,7 +211,6 @@ public final class Sensor {
    private float   mPower;
    private int     mMinDelay;


    Sensor() {
    }

+61 −61
Original line number Diff line number Diff line
@@ -17,11 +17,9 @@
package android.hardware;

/**
 * <p>
 * This class represents a {@link android.hardware.Sensor Sensor} event and
 * holds informations such as the sensor's type, the time-stamp, accuracy and of
 * course the sensor's {@link SensorEvent#values data}.
 * </p>
 *
 * <p>
 * <u>Definition of the coordinate system used by the SensorEvent API.</u>
@@ -67,15 +65,9 @@ public class SensorEvent {
     * Sensor.TYPE_ACCELEROMETER}:</h4> All values are in SI units (m/s^2)
     * 
     * <ul>
     * <p>
     * values[0]: Acceleration minus Gx on the x-axis
     * </p>
     * <p>
     * values[1]: Acceleration minus Gy on the y-axis
     * </p>
     * <p>
     * values[2]: Acceleration minus Gz on the z-axis
     * </p>
     * <li> values[0]: Acceleration minus Gx on the x-axis </li>
     * <li> values[1]: Acceleration minus Gy on the y-axis </li>
     * <li> values[2]: Acceleration minus Gz on the z-axis </li>
     * </ul>
     * 
     * <p>
@@ -165,15 +157,9 @@ public class SensorEvent {
     * definition of positive rotation and does not agree with the definition of
     * roll given earlier.
     * <ul>
     * <p>
     * values[0]: Angular speed around the x-axis
     * </p>
     * <p>
     * values[1]: Angular speed around the y-axis
     * </p>
     * <p>
     * values[2]: Angular speed around the z-axis
     * </p>
     * <li> values[0]: Angular speed around the x-axis </li>
     * <li> values[1]: Angular speed around the y-axis </li>
     * <li> values[2]: Angular speed around the z-axis </li>
     * </ul>
     * <p>
     * Typically the output of the gyroscope is integrated over time to
@@ -233,22 +219,19 @@ public class SensorEvent {
     * </p>
     * <h4>{@link android.hardware.Sensor#TYPE_LIGHT Sensor.TYPE_LIGHT}:</h4>
     * <ul>
     * <p>
     * values[0]: Ambient light level in SI lux units
     * <li>values[0]: Ambient light level in SI lux units </li>
     * </ul>
     * 
     * <h4>{@link android.hardware.Sensor#TYPE_PRESSURE Sensor.TYPE_PRESSURE}:</h4>
     * <ul>
     * <p>
     * values[0]: Atmospheric pressure in hPa (millibar)
     * <li>values[0]: Atmospheric pressure in hPa (millibar) </li>
     * </ul>
     *
     * <h4>{@link android.hardware.Sensor#TYPE_PROXIMITY Sensor.TYPE_PROXIMITY}:
     * </h4>
     * 
     * <ul>
     * <p>
     * values[0]: Proximity sensor distance measured in centimeters
     * <li>values[0]: Proximity sensor distance measured in centimeters </li>
     * </ul>
     * 
     * <p>
@@ -304,39 +287,23 @@ public class SensorEvent {
     * </p>
     *
     * <ul>
     * <p>
     * values[0]: x*sin(&#952/2)
     * </p>
     * <p>
     * values[1]: y*sin(&#952/2)
     * </p>
     * <p>
     * values[2]: z*sin(&#952/2)
     * </p>
     * <p>
     * values[3]: cos(&#952/2) <i>(optional: only if value.length = 4)</i>
     * </p>
     * <li> values[0]: x*sin(&#952/2) </li>
     * <li> values[1]: y*sin(&#952/2) </li>
     * <li> values[2]: z*sin(&#952/2) </li>
     * <li> values[3]: cos(&#952/2) <i>(optional: only if value.length = 4)</i> </li>
     * </ul>
     *
     * <h4>{@link android.hardware.Sensor#TYPE_ORIENTATION
     * Sensor.TYPE_ORIENTATION}:</h4> All values are angles in degrees.
     * 
     * <ul>
     * <p>
     * values[0]: Azimuth, angle between the magnetic north direction and the
     * <li> values[0]: Azimuth, angle between the magnetic north direction and the
     * y-axis, around the z-axis (0 to 359). 0=North, 90=East, 180=South,
     * 270=West
     * </p>
     * 
     * <p>
     * values[1]: Pitch, rotation around x-axis (-180 to 180), with positive
     * values when the z-axis moves <b>toward</b> the y-axis.
     * </p>
     * 
     * <p>
     * values[2]: Roll, rotation around y-axis (-90 to 90), with positive values
     * when the x-axis moves <b>toward</b> the z-axis.
     * </p>
     * 270=West </li>
     * <li> values[1]: Pitch, rotation around x-axis (-180 to 180), with positive
     * values when the z-axis moves <b>toward</b> the y-axis. </li>
     * <li> values[2]: Roll, rotation around y-axis (-90 to 90), with positive values
     * when the x-axis moves <b>toward</b> the z-axis. </li>
     * </ul>
     * 
     * <p>
@@ -364,9 +331,7 @@ public class SensorEvent {
     * <h4>{@link android.hardware.Sensor#TYPE_RELATIVE_HUMIDITY
     * Sensor.TYPE_RELATIVE_HUMIDITY}:</h4>
     * <ul>
     * <p>
     * values[0]: Relative ambient air humidity in percent
     * </p>
     * <li> values[0]: Relative ambient air humidity in percent </li>
     * </ul>
     * <p>
     * When relative ambient air humidity and ambient temperature are
@@ -423,14 +388,51 @@ public class SensorEvent {
     * </h4>
     *
     * <ul>
     * <p>
     * values[0]: ambient (room) temperature in degree Celsius.
     * <li> values[0]: ambient (room) temperature in degree Celsius.</li>
     * </ul>
     *
     * @see SensorEvent
     * @see GeomagneticField
     *
     * <h4>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD_UNCALIBRATED} </h4>
     * All values are in micro-Tesla (uT) and measure the ambient magnetic field
     * in the X, Y and Z axis.
     * <p>
     * No periodic calibration is performed (ie: there are no discontinuities
     * in the data stream while using this sensor). Assumptions that the the
     * magnetic field is due to the Earth's poles is avoided. Factory calibration
     * and temperature compensation is still performed.
     * </p>
     *
     * <h4> {@link android.hardware.Sensor#TYPE_GYROSCOPE_UNCALIBRATED} </h4>
     * All values are in radians/second and measure the rate of rotation
     * around the X, Y and Z axis. An estimation of the drift on each axis is
     * reported as well.
     * <p>
     * No gyro-drift compensation is performed. Factory calibration and temperature
     * compensation is still applied to the rate of rotation (angular speeds).
     * </p>
     * <p>
     * The coordinate system is the same as is used for the
     * {@link android.hardware.Sensor#TYPE_ACCELEROMETER}
     * Rotation is positive in the counter-clockwise direction (right-hand rule).
     * That is, an observer looking from some positive location on the x, y or z axis
     * at a device positioned on the origin would report positive rotation if the device
     * appeared to be rotating counter clockwise.
     * The range would at least be 17.45 rad/s (ie: ~1000 deg/s).
     * <ul>
     * <li> values[0] : angular speed (w/o drift compensation) around the X axis in rad/s </li>
     * <li> values[1] : angular speed (w/o drift compensation) around the Y axis in rad/s </li>
     * <li> values[2] : angular speed (w/o drift compensation) around the Z axis in rad/s </li>
     * <li> values[3] : estimated drift around X axis in rad/s </li>
     * <li> values[4] : estimated drift around Y axis in rad/s </li>
     * <li> values[5] : estimated drift around Z axis in rad/s </li>
     * </ul>
     * </p>
     * <h4></h4>
     * <h4> Pro Tip: Always use the length of the values array while performing operations
     * on it. In earlier versions, this used to be always 3 which has changed now. </h4>
     */

    public final float[] values;

    /**
@@ -445,13 +447,11 @@ public class SensorEvent {
     */
    public int accuracy;


    /**
     * The time in nanosecond at which the event happened
     */
    public long timestamp;


    SensorEvent(int size) {
        values = new float[size];
    }
+88 −1
Original line number Diff line number Diff line
@@ -38,7 +38,11 @@ import java.util.List;
 * hours. Note that the system will <i>not</i> disable sensors automatically when
 * the screen turns off.
 * </p>
 *
 * <p class="note">
 * Note: Don't use this mechanism with a Trigger Sensor, have a look
 * at {@link TriggerEventListener}. {@link Sensor#TYPE_SIGNIFICANT_MOTION}
 * is an example of a trigger sensor.
 * </p>
 * <pre class="prettyprint">
 * public class SensorActivity extends Activity, implements SensorEventListener {
 *     private final SensorManager mSensorManager;
@@ -515,6 +519,12 @@ public abstract class SensorManager {
    /**
     * Unregisters a listener for the sensors with which it is registered.
     *
     * <p class="note"></p>
     * Note: Don't use this method with a one shot trigger sensor such as
     * {@link Sensor#TYPE_SIGNIFICANT_MOTION}.
     * Use {@link #cancelTriggerSensor(TriggerEventListener, Sensor)} instead.
     * </p>
     *
     * @param listener
     *        a SensorEventListener object
     *
@@ -524,6 +534,7 @@ public abstract class SensorManager {
     * @see #unregisterListener(SensorEventListener)
     * @see #registerListener(SensorEventListener, Sensor, int)
     *
     * @throws IllegalArgumentException when sensor is a trigger sensor.
     */
    public void unregisterListener(SensorEventListener listener, Sensor sensor) {
        if (listener == null || sensor == null) {
@@ -558,6 +569,12 @@ public abstract class SensorManager {
     * Registers a {@link android.hardware.SensorEventListener
     * SensorEventListener} for the given sensor.
     *
     * <p class="note"></p>
     * Note: Don't use this method with a one shot trigger sensor such as
     * {@link Sensor#TYPE_SIGNIFICANT_MOTION}.
     * Use {@link #requestTriggerSensor(TriggerEventListener, Sensor)} instead.
     * </p>
     *
     * @param listener
     *        A {@link android.hardware.SensorEventListener SensorEventListener}
     *        object.
@@ -584,6 +601,7 @@ public abstract class SensorManager {
     * @see #unregisterListener(SensorEventListener)
     * @see #unregisterListener(SensorEventListener, Sensor)
     *
     * @throws IllegalArgumentException when sensor is null or a trigger sensor
     */
    public boolean registerListener(SensorEventListener listener, Sensor sensor, int rate) {
        return registerListener(listener, sensor, rate, null);
@@ -593,6 +611,12 @@ public abstract class SensorManager {
     * Registers a {@link android.hardware.SensorEventListener
     * SensorEventListener} for the given sensor.
     *
     * <p class="note"></p>
     * Note: Don't use this method with a one shot trigger sensor such as
     * {@link Sensor#TYPE_SIGNIFICANT_MOTION}.
     * Use {@link #requestTriggerSensor(TriggerEventListener, Sensor)} instead.
     * </p>
     *
     * @param listener
     *        A {@link android.hardware.SensorEventListener SensorEventListener}
     *        object.
@@ -623,6 +647,7 @@ public abstract class SensorManager {
     * @see #unregisterListener(SensorEventListener)
     * @see #unregisterListener(SensorEventListener, Sensor)
     *
     * @throws IllegalArgumentException when sensor is null or a trigger sensor
     */
    public boolean registerListener(SensorEventListener listener, Sensor sensor, int rate,
            Handler handler) {
@@ -1310,6 +1335,68 @@ public abstract class SensorManager {
        Q[3] = rv[2];
    }

    /**
     * Requests receiving trigger events for a trigger sensor.
     *
     * <p>
     * When the sensor detects a trigger event condition, such as significant motion in
     * the case of the {@link Sensor#TYPE_SIGNIFICANT_MOTION}, the provided trigger listener
     * will be invoked once and then its request to receive trigger events will be canceled.
     * To continue receiving trigger events, the application must request to receive trigger
     * events again.
     * </p>
     *
     * @param listener The listener on which the
     *        {@link TriggerEventListener#onTrigger(TriggerEvent)} will be delivered.
     * @param sensor The sensor to be enabled.
     *
     * @return true if the sensor was successfully enabled.
     *
     * @throws IllegalArgumentException when sensor is null or not a trigger sensor.
     */
    public boolean requestTriggerSensor(TriggerEventListener listener, Sensor sensor) {
        return requestTriggerSensorImpl(listener, sensor);
    }

    /**
     * @hide
     */
    protected abstract boolean requestTriggerSensorImpl(TriggerEventListener listener,
            Sensor sensor);

    /**
     * Cancels receiving trigger events for a trigger sensor.
     *
     * <p>
     * Note that a Trigger sensor will be auto disabled if
     * {@link TriggerEventListener#onTrigger(TriggerEvent)} has triggered.
     * This method is provided in case the user wants to explicitly cancel the request
     * to receive trigger events.
     * </p>
     *
     * @param listener The listener on which the
     *        {@link TriggerEventListener#onTrigger(TriggerEvent)}
     *        is delivered.It should be the same as the one used
     *        in {@link #requestTriggerSensor(TriggerEventListener, Sensor)}
     * @param sensor The sensor for which the trigger request should be canceled.
     *        If null, it cancels receiving trigger for all sensors associated
     *        with the listener.
     *
     * @return true if successfully canceled.
     *
     * @throws IllegalArgumentException when sensor is a trigger sensor.
     */
    public boolean cancelTriggerSensor(TriggerEventListener listener, Sensor sensor) {
        return cancelTriggerSensorImpl(listener, sensor);
    }

    /**
     * @hide
     */
    protected abstract boolean cancelTriggerSensorImpl(TriggerEventListener listener,
            Sensor sensor);


    private LegacySensorManager getLegacySensorManager() {
        synchronized (mSensorListByType) {
            if (mLegacySensorManager == null) {
+159 −150

File changed.

Preview size limit exceeded, changes collapsed.

Loading