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

Commit 1a68f24a authored by Aravind Akella's avatar Aravind Akella Committed by Android (Google) Code Review
Browse files

Merge "Adding wakeup sensors, maxDelay to java SDK."

parents 42db9d0b 2f8b9144
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -11933,6 +11933,7 @@ package android.hardware {
  public final class Sensor {
    method public int getFifoMaxEventCount();
    method public int getFifoReservedEventCount();
    method public int getMaxDelay();
    method public float getMaximumRange();
    method public int getMinDelay();
    method public java.lang.String getName();
@@ -11942,6 +11943,9 @@ package android.hardware {
    method public int getType();
    method public java.lang.String getVendor();
    method public int getVersion();
    method public boolean isWakeUpSensor();
    field public static final java.lang.String SENSOR_STRING_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR = "android.sensor.non_wake_up_proximity_sensor";
    field public static final java.lang.String SENSOR_STRING_TYPE_WAKE_UP_TILT_DETECTOR = "android.sensor.wake_up_tilt_detector";
    field public static final java.lang.String STRING_TYPE_ACCELEROMETER = "android.sensor.accelerometer";
    field public static final java.lang.String STRING_TYPE_AMBIENT_TEMPERATURE = "android.sensor.ambient_temperature";
    field public static final java.lang.String STRING_TYPE_GAME_ROTATION_VECTOR = "android.sensor.game_rotation_vector";
@@ -11963,6 +11967,24 @@ package android.hardware {
    field public static final java.lang.String STRING_TYPE_STEP_COUNTER = "android.sensor.step_counter";
    field public static final java.lang.String STRING_TYPE_STEP_DETECTOR = "android.sensor.step_detector";
    field public static final deprecated java.lang.String STRING_TYPE_TEMPERATURE = "android.sensor.temperature";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_ACCELEROMETER = "android.sensor.wake_up_accelerometer";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_AMBIENT_TEMPERATURE = "android.sensor.wake_up_ambient_temperature";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_GAME_ROTATION_VECTOR = "android.sensor.wake_up_game_rotation_vector";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR = "android.sensor.wake_up_geomagnetic_rotation_vector";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_GRAVITY = "android.sensor.wake_up_gravity";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_GYROSCOPE = "android.sensor.wake_up_gyroscope";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED = "android.sensor.wake_up_gyroscope_uncalibrated";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_HEART_RATE = "android.sensor.wake_up_heart_rate";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_LIGHT = "android.sensor.wake_up_light";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_LINEAR_ACCELERATION = "android.sensor.wake_up_linear_acceleration";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_MAGNETIC_FIELD = "android.sensor.wake_up_magnetic_field";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED = "android.sensor.wake_up_magnetic_field_uncalibrated";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_ORIENTATION = "android.sensor.wake_up_orientation";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_PRESSURE = "android.sensor.wake_up_pressure";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_RELATIVE_HUMIDITY = "android.sensor.wake_up_relative_humidity";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_ROTATION_VECTOR = "android.sensor.wake_up_rotation_vector";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_STEP_COUNTER = "android.sensor.wake_up_step_counter";
    field public static final java.lang.String STRING_TYPE_WAKE_UP_STEP_DETECTOR = "android.sensor.wake_up_step_detector";
    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
@@ -11976,6 +11998,7 @@ package android.hardware {
    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 int TYPE_NON_WAKE_UP_PROXIMITY_SENSOR = 22; // 0x16
    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
@@ -11985,6 +12008,25 @@ package android.hardware {
    field public static final int TYPE_STEP_COUNTER = 19; // 0x13
    field public static final int TYPE_STEP_DETECTOR = 18; // 0x12
    field public static final deprecated int TYPE_TEMPERATURE = 7; // 0x7
    field public static final int TYPE_WAKE_UP_ACCELEROMETER = 23; // 0x17
    field public static final int TYPE_WAKE_UP_AMBIENT_TEMPERATURE = 33; // 0x21
    field public static final int TYPE_WAKE_UP_GAME_ROTATION_VECTOR = 35; // 0x23
    field public static final int TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR = 39; // 0x27
    field public static final int TYPE_WAKE_UP_GRAVITY = 29; // 0x1d
    field public static final int TYPE_WAKE_UP_GYROSCOPE = 26; // 0x1a
    field public static final int TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED = 36; // 0x24
    field public static final int TYPE_WAKE_UP_HEART_RATE = 40; // 0x28
    field public static final int TYPE_WAKE_UP_LIGHT = 27; // 0x1b
    field public static final int TYPE_WAKE_UP_LINEAR_ACCELERATION = 30; // 0x1e
    field public static final int TYPE_WAKE_UP_MAGNETIC_FIELD = 24; // 0x18
    field public static final int TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED = 34; // 0x22
    field public static final int TYPE_WAKE_UP_ORIENTATION = 25; // 0x19
    field public static final int TYPE_WAKE_UP_PRESSURE = 28; // 0x1c
    field public static final int TYPE_WAKE_UP_RELATIVE_HUMIDITY = 32; // 0x20
    field public static final int TYPE_WAKE_UP_ROTATION_VECTOR = 31; // 0x1f
    field public static final int TYPE_WAKE_UP_STEP_COUNTER = 38; // 0x26
    field public static final int TYPE_WAKE_UP_STEP_DETECTOR = 37; // 0x25
    field public static final int TYPE_WAKE_UP_TILT_DETECTOR = 41; // 0x29
  }
  public class SensorEvent {
+391 −3
Original line number Diff line number Diff line
@@ -142,9 +142,10 @@ public final class Sensor {
    public static final String STRING_TYPE_TEMPERATURE = "android.sensor.temperature";

    /**
     * A constant describing a proximity sensor type.
     * A constant describing a proximity sensor type. This is a wake up sensor.
     * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
     * for more details.
     * @see #isWakeUpSensor()
     */
    public static final int TYPE_PROXIMITY = 8;

@@ -307,8 +308,10 @@ public final class Sensor {
     * 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.
     * locks for this sensor to trigger. This is a wake up sensor.
     * <p>See {@link TriggerEvent} for more details.
     *
     * @see #isWakeUpSensor()
     */
    public static final int TYPE_SIGNIFICANT_MOTION = 17;

@@ -402,6 +405,321 @@ public final class Sensor {
     */
    public static final String STRING_TYPE_HEART_RATE = "android.sensor.heart_rate";

    /**
     * A non-wake up variant of proximity sensor.
     *
     * @see #TYPE_PROXIMITY
     */
    public static final int TYPE_NON_WAKE_UP_PROXIMITY_SENSOR = 22;

    /**
     * A constant string describing a non-wake up proximity sensor type.
     *
     * @see #TYPE_NON_WAKE_UP_PROXIMITY_SENSOR
     */
    public static final String SENSOR_STRING_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR =
            "android.sensor.non_wake_up_proximity_sensor";

    /**
     * A constant describing a wake up variant of accelerometer sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_ACCELEROMETER
     */
    public static final int TYPE_WAKE_UP_ACCELEROMETER = 23;

    /**
     * A constant string describing a wake up accelerometer.
     *
     * @see #TYPE_WAKE_UP_ACCELEROMETER
     */
    public static final String STRING_TYPE_WAKE_UP_ACCELEROMETER =
            "android.sensor.wake_up_accelerometer";

    /**
     * A constant describing a wake up variant of a magnetic field sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_MAGNETIC_FIELD
     */
    public static final int TYPE_WAKE_UP_MAGNETIC_FIELD = 24;

    /**
     * A constant string describing a wake up magnetic field sensor.
     *
     * @see #TYPE_WAKE_UP_MAGNETIC_FIELD
     */
    public static final String STRING_TYPE_WAKE_UP_MAGNETIC_FIELD =
            "android.sensor.wake_up_magnetic_field";

    /**
     * A constant describing a wake up variant of an orientation sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_ORIENTATION
     */
    public static final int TYPE_WAKE_UP_ORIENTATION = 25;

    /**
     * A constant string describing a wake up orientation sensor.
     *
     * @see #TYPE_WAKE_UP_ORIENTATION
     */
    public static final String STRING_TYPE_WAKE_UP_ORIENTATION =
            "android.sensor.wake_up_orientation";

    /**
     * A constant describing a wake up variant of a gyroscope sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_GYROSCOPE
     */
    public static final int TYPE_WAKE_UP_GYROSCOPE = 26;

    /**
     * A constant string describing a wake up gyroscope sensor type.
     *
     * @see #TYPE_WAKE_UP_GYROSCOPE
     */
    public static final String STRING_TYPE_WAKE_UP_GYROSCOPE = "android.sensor.wake_up_gyroscope";

    /**
     * A constant describing a wake up variant of a light sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_LIGHT
     */
    public static final int TYPE_WAKE_UP_LIGHT = 27;

    /**
     * A constant string describing a wake up light sensor type.
     *
     * @see #TYPE_WAKE_UP_LIGHT
     */
    public static final String STRING_TYPE_WAKE_UP_LIGHT = "android.sensor.wake_up_light";

    /**
     * A constant describing a wake up variant of a pressure sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_PRESSURE
     */
    public static final int TYPE_WAKE_UP_PRESSURE = 28;

    /**
     * A constant string describing a wake up pressure sensor type.
     *
     * @see #TYPE_WAKE_UP_PRESSURE
     */
    public static final String STRING_TYPE_WAKE_UP_PRESSURE = "android.sensor.wake_up_pressure";

    /**
     * A constant describing a wake up variant of a gravity sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_GRAVITY
     */
    public static final int TYPE_WAKE_UP_GRAVITY = 29;

    /**
     * A constant string describing a wake up gravity sensor type.
     *
     * @see #TYPE_WAKE_UP_GRAVITY
     */
    public static final String STRING_TYPE_WAKE_UP_GRAVITY = "android.sensor.wake_up_gravity";

    /**
     * A constant describing a wake up variant of a linear acceleration sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_LINEAR_ACCELERATION
     */
    public static final int TYPE_WAKE_UP_LINEAR_ACCELERATION = 30;

    /**
     * A constant string describing a wake up linear acceleration sensor type.
     *
     * @see #TYPE_WAKE_UP_LINEAR_ACCELERATION
     */
    public static final String STRING_TYPE_WAKE_UP_LINEAR_ACCELERATION =
            "android.sensor.wake_up_linear_acceleration";

    /**
     * A constant describing a wake up variant of a rotation vector sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_ROTATION_VECTOR
     */
    public static final int TYPE_WAKE_UP_ROTATION_VECTOR = 31;

    /**
     * A constant string describing a wake up rotation vector sensor type.
     *
     * @see #TYPE_WAKE_UP_ROTATION_VECTOR
     */
    public static final String STRING_TYPE_WAKE_UP_ROTATION_VECTOR =
            "android.sensor.wake_up_rotation_vector";

    /**
     * A constant describing a wake up variant of a relative humidity sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_RELATIVE_HUMIDITY
     */
    public static final int TYPE_WAKE_UP_RELATIVE_HUMIDITY = 32;

    /**
     * A constant string describing a wake up relative humidity sensor type.
     *
     * @see #TYPE_WAKE_UP_RELATIVE_HUMIDITY
     */
    public static final String STRING_TYPE_WAKE_UP_RELATIVE_HUMIDITY =
            "android.sensor.wake_up_relative_humidity";

    /**
     * A constant describing a wake up variant of an ambient temperature sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_AMBIENT_TEMPERATURE
     */
    public static final int TYPE_WAKE_UP_AMBIENT_TEMPERATURE = 33;

    /**
     * A constant string describing a wake up ambient temperature sensor type.
     *
     * @see #TYPE_WAKE_UP_AMBIENT_TEMPERATURE
     */
    public static final String STRING_TYPE_WAKE_UP_AMBIENT_TEMPERATURE =
            "android.sensor.wake_up_ambient_temperature";

    /**
     * A constant describing a wake up variant of an uncalibrated magnetic field sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_MAGNETIC_FIELD_UNCALIBRATED
     */
    public static final int TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED = 34;

    /**
     * A constant string describing a wake up uncalibrated magnetic field sensor type.
     *
     * @see #TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED
     */
    public static final String STRING_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED =
            "android.sensor.wake_up_magnetic_field_uncalibrated";

    /**
     * A constant describing a wake up variant of a game rotation vector sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_GAME_ROTATION_VECTOR
     */
    public static final int TYPE_WAKE_UP_GAME_ROTATION_VECTOR = 35;

    /**
     * A constant string describing a wake up game rotation vector sensor type.
     *
     * @see #TYPE_WAKE_UP_GAME_ROTATION_VECTOR
     */
    public static final String STRING_TYPE_WAKE_UP_GAME_ROTATION_VECTOR =
            "android.sensor.wake_up_game_rotation_vector";

    /**
     * A constant describing a wake up variant of an uncalibrated gyroscope sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_GYROSCOPE_UNCALIBRATED
     */
    public static final int TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED = 36;

    /**
     * A constant string describing a wake up uncalibrated gyroscope sensor type.
     *
     * @see #TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED
     */
    public static final String STRING_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED =
            "android.sensor.wake_up_gyroscope_uncalibrated";

    /**
     * A constant describing a wake up variant of a step detector sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_STEP_DETECTOR
     */
    public static final int TYPE_WAKE_UP_STEP_DETECTOR = 37;

    /**
     * A constant string describing a wake up step detector sensor type.
     *
     * @see #TYPE_WAKE_UP_STEP_DETECTOR
     */
    public static final String STRING_TYPE_WAKE_UP_STEP_DETECTOR =
            "android.sensor.wake_up_step_detector";

    /**
     * A constant describing a wake up variant of a step counter sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_STEP_COUNTER
     */
    public static final int TYPE_WAKE_UP_STEP_COUNTER = 38;

    /**
     * A constant string describing a wake up step counter sensor type.
     *
     * @see #TYPE_WAKE_UP_STEP_COUNTER
     */
    public static final String STRING_TYPE_WAKE_UP_STEP_COUNTER =
            "android.sensor.wake_up_step_counter";

    /**
     * A constant describing a wake up variant of a geomagnetic rotation vector sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_GEOMAGNETIC_ROTATION_VECTOR
     */
    public static final int TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR = 39;

    /**
     * A constant string describing a wake up geomagnetic rotation vector sensor type.
     *
     * @see #TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR
     */
    public static final String STRING_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR =
            "android.sensor.wake_up_geomagnetic_rotation_vector";

    /**
     * A constant describing a wake up variant of a heart rate sensor type.
     *
     * @see #isWakeUpSensor()
     * @see #TYPE_HEART_RATE
     */
    public static final int TYPE_WAKE_UP_HEART_RATE = 40;

    /**
     * A constant string describing a wake up heart rate sensor type.
     *
     * @see #TYPE_WAKE_UP_HEART_RATE
     */
    public static final String STRING_TYPE_WAKE_UP_HEART_RATE = "android.sensor.wake_up_heart_rate";

    /**
     * A sensor of this type generates an event each time a tilt event is detected. A tilt event
     * is generated if the direction of the 2-seconds window average gravity changed by at
     * least 35 degrees since the activation of the sensor. It is a wake up sensor.
     *
     * @see #isWakeUpSensor()
     */
    public static final int TYPE_WAKE_UP_TILT_DETECTOR = 41;

    /**
     * A constant string describing a wake up tilt detector sensor type.
     *
     * @see #TYPE_WAKE_UP_TILT_DETECTOR
     */
    public static final String SENSOR_STRING_TYPE_WAKE_UP_TILT_DETECTOR =
            "android.sensor.wake_up_tilt_detector";

    /**
     * A constant describing a wake gesture sensor.
     * <p>
@@ -416,6 +734,7 @@ public final class Sensor {
     * the device. This sensor must be low power, as it is likely to be activated 24/7.
     * Values of events created by this sensors should not be used.
     *
     * @see #isWakeUpSensor()
     * @hide This sensor is expected to only be used by the power manager
     */
    public static final int TYPE_WAKE_GESTURE = 42;
@@ -473,7 +792,29 @@ public final class Sensor {
            REPORTING_MODE_ON_CHANGE,  1, // SENSOR_TYPE_STEP_DETECTOR
            REPORTING_MODE_ON_CHANGE,  1, // SENSOR_TYPE_STEP_COUNTER
            REPORTING_MODE_CONTINUOUS, 5, // SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
            REPORTING_MODE_ON_CHANGE, 1  // SENSOR_TYPE_HEART_RATE_MONITOR
            REPORTING_MODE_ON_CHANGE,  1, // SENSOR_TYPE_HEART_RATE_MONITOR
            REPORTING_MODE_ON_CHANGE,  3, // SENSOR_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR
            // wake up variants of base sensors
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_WAKE_UP_ACCELEROMETER
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_WAKE_UP_ORIENTATION
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_WAKE_UP_GYROSCOPE
            REPORTING_MODE_ON_CHANGE,  3, // SENSOR_TYPE_WAKE_UP_LIGHT
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_WAKE_UP_PRESSURE
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_WAKE_UP_GRAVITY
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_WAKE_UP_LINEAR_ACCELERATION
            REPORTING_MODE_CONTINUOUS, 5, // SENSOR_TYPE_WAKE_UP_ROTATION_VECTOR
            REPORTING_MODE_ON_CHANGE,  3, // SENSOR_TYPE_WAKE_UP_RELATIVE_HUMIDITY
            REPORTING_MODE_ON_CHANGE,  3, // SENSOR_TYPE_WAKE_UP_AMBIENT_TEMPERATURE
            REPORTING_MODE_CONTINUOUS, 6, // SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED
            REPORTING_MODE_CONTINUOUS, 4, // SENSOR_TYPE_WAKE_UP_GAME_ROTATION_VECTOR
            REPORTING_MODE_CONTINUOUS, 6, // SENSOR_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED
            REPORTING_MODE_ON_CHANGE,  1, // SENSOR_TYPE_WAKE_UP_STEP_DETECTOR
            REPORTING_MODE_ON_CHANGE,  1, // SENSOR_TYPE_WAKE_UP_STEP_COUNTER
            REPORTING_MODE_CONTINUOUS, 5, // SENSOR_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR
            REPORTING_MODE_ON_CHANGE,  1, // SENSOR_TYPE_WAKE_UP_HEART_RATE_MONITOR
            REPORTING_MODE_ON_CHANGE,  1, // SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
            REPORTING_MODE_ONE_SHOT,   1, // SENSOR_TYPE_WAKE_GESTURE
    };

    static int getReportingMode(Sensor sensor) {
@@ -531,6 +872,8 @@ public final class Sensor {
    private int     mFifoMaxEventCount;
    private String  mStringType;
    private String  mRequiredPermission;
    private int     mMaxDelay;
    private boolean mWakeUpSensor;

    Sensor() {
    }
@@ -631,6 +974,51 @@ public final class Sensor {
        return mHandle;
    }

    /**
     * This value is defined only for continuous mode sensors. It is the delay between two
     * sensor events corresponding to the lowest frequency that this sensor supports. When
     * lower frequencies are requested through registerListener() the events will be generated
     * at this frequency instead. It can be used to estimate when the batch FIFO may be full.
     * Older devices may set this value to zero. Ignore this value in case it is negative
     * or zero.
     *
     * @return The max delay for this sensor in microseconds.
     */
    public int getMaxDelay() {
        return mMaxDelay;
    }

    /**
     * Returns whether this sensor is a wake-up sensor.
     * <p>
     * Wake up sensors wake the application processor up when they have events to deliver. When a
     * wake up sensor is registered to without batching enabled, each event will wake the
     * application processor up.
     * <p>
     * When a wake up sensor is registered to with batching enabled, it
     * wakes the application processor up when maxReportingLatency has elapsed or when the hardware
     * FIFO storing the events from wake up sensors is getting full.
     * <p>
     * Non-wake up sensors never wake the application processor up. Their events are only reported
     * when the application processor is awake, for example because the application holds a wake
     * lock, or another source woke the application processor up.
     * <p>
     * When a non-wake up sensor is registered to without batching enabled, the measurements made
     * while the application processor is asleep might be lost and never returned.
     * <p>
     * When a non-wake up sensor is registered to with batching enabled, the measurements made while
     * the application processor is asleep are stored in the hardware FIFO for non-wake up sensors.
     * When this FIFO gets full, new events start overwriting older events. When the application
     * then wakes up, the latest events are returned, and some old events might be lost. The number
     * of events actually returned depends on the hardware FIFO size, as well as on what other
     * sensors are activated. If losing sensor events is not acceptable during batching, you must
     * use the wake-up version of the sensor.
     * @return true if this is a wake up sensor, false otherwise.
     */
    public boolean isWakeUpSensor() {
        return mWakeUpSensor;
    }

    void setRange(float max, float res) {
        mMaxRange = max;
        mResolution = res;
+8 −1
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ struct SensorOffsets
    jfieldID    fifoMaxEventCount;
    jfieldID    stringType;
    jfieldID    requiredPermission;
    jfieldID    maxDelay;
    jfieldID    isWakeUpSensor;
} gSensorOffsets;


@@ -78,6 +80,8 @@ nativeClassInit (JNIEnv *_env, jclass _this)
    sensorOffsets.stringType = _env->GetFieldID(sensorClass, "mStringType", "Ljava/lang/String;");
    sensorOffsets.requiredPermission = _env->GetFieldID(sensorClass, "mRequiredPermission",
                                                        "Ljava/lang/String;");
    sensorOffsets.maxDelay    = _env->GetFieldID(sensorClass, "mMaxDelay",  "I");
    sensorOffsets.isWakeUpSensor = _env->GetFieldID(sensorClass, "mWakeUpSensor",  "Z");
}

static jint
@@ -112,6 +116,8 @@ nativeGetNextSensor(JNIEnv *env, jclass clazz, jobject sensor, jint next)
    env->SetObjectField(sensor, sensorOffsets.stringType, stringType);
    env->SetObjectField(sensor, sensorOffsets.requiredPermission,
                        requiredPermission);
    env->SetIntField(sensor, sensorOffsets.maxDelay, list->getMaxDelay());
    env->SetBooleanField(sensor, sensorOffsets.isWakeUpSensor, list->isWakeUpSensor());
    next++;
    return size_t(next) < count ? next : 0;
}
@@ -160,7 +166,8 @@ private:
        ASensorEvent buffer[16];
        while ((n = q->read(buffer, 16)) > 0) {
            for (int i=0 ; i<n ; i++) {
                if (buffer[i].type == SENSOR_TYPE_STEP_COUNTER) {
                if (buffer[i].type == SENSOR_TYPE_STEP_COUNTER ||
                    buffer[i].type == SENSOR_TYPE_WAKE_UP_STEP_COUNTER) {
                    // step-counter returns a uint64, but the java API only deals with floats
                    float value = float(buffer[i].u64.step_counter);
                    env->SetFloatArrayRegion(mScratch, 0, 1, &value);