Merge "SensorManager API changes." into lmp-dev
diff --git a/api/current.txt b/api/current.txt
index d0d0e00..dba086c 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -12404,7 +12404,6 @@
field public static final int REPORTING_MODE_ONE_SHOT = 2; // 0x2
field public static final int REPORTING_MODE_ON_CHANGE = 1; // 0x1
field public static final int REPORTING_MODE_SPECIAL_TRIGGER = 3; // 0x3
- 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 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";
@@ -12426,24 +12425,6 @@
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
@@ -12457,7 +12438,6 @@
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
@@ -12467,24 +12447,6 @@
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
}
public class SensorEvent {
@@ -12514,6 +12476,7 @@
method public static float getAltitude(float, float);
method public static void getAngleChange(float[], float[], float[]);
method public android.hardware.Sensor getDefaultSensor(int);
+ method public android.hardware.Sensor getDefaultSensor(int, boolean);
method public static float getInclination(float[]);
method public static float[] getOrientation(float[], float[]);
method public static void getQuaternionFromVector(float[], float[]);
diff --git a/core/java/android/hardware/Sensor.java b/core/java/android/hardware/Sensor.java
index b6d2a13..d60a2c2 100644
--- a/core/java/android/hardware/Sensor.java
+++ b/core/java/android/hardware/Sensor.java
@@ -406,304 +406,6 @@
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.
@@ -711,7 +413,7 @@
* @hide
* @see #isWakeUpSensor()
*/
- public static final int TYPE_WAKE_UP_TILT_DETECTOR = 41;
+ public static final int TYPE_TILT_DETECTOR = 22;
/**
* A constant string describing a wake up tilt detector sensor type.
@@ -719,8 +421,8 @@
* @hide
* @see #TYPE_WAKE_UP_TILT_DETECTOR
*/
- public static final String SENSOR_STRING_TYPE_WAKE_UP_TILT_DETECTOR =
- "android.sensor.wake_up_tilt_detector";
+ public static final String SENSOR_STRING_TYPE_TILT_DETECTOR =
+ "android.sensor.tilt_detector";
/**
* A constant describing a wake gesture sensor.
@@ -739,7 +441,7 @@
* @see #isWakeUpSensor()
* @hide This sensor is expected to only be used by the system ui
*/
- public static final int TYPE_WAKE_GESTURE = 42;
+ public static final int TYPE_WAKE_GESTURE = 23;
/**
* A constant string describing a wake gesture sensor.
@@ -771,7 +473,7 @@
* @see #isWakeUpSensor()
* @hide This sensor is expected to only be used by the system ui
*/
- public static final int TYPE_GLANCE_GESTURE = 43;
+ public static final int TYPE_GLANCE_GESTURE = 24;
/**
* A constant string describing a wake gesture sensor.
@@ -790,7 +492,7 @@
*
* @hide Expected to be used internally for always on display.
*/
- public static final int TYPE_PICK_UP_GESTURE = 44;
+ public static final int TYPE_PICK_UP_GESTURE = 25;
/**
* A constant string describing a pick up sensor.
@@ -876,26 +578,6 @@
1, // SENSOR_TYPE_STEP_COUNTER
5, // SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
1, // SENSOR_TYPE_HEART_RATE_MONITOR
- 3, // SENSOR_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR
- // wake up variants of base sensors
- 3, // SENSOR_TYPE_WAKE_UP_ACCELEROMETER
- 3, // SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD
- 3, // SENSOR_TYPE_WAKE_UP_ORIENTATION
- 3, // SENSOR_TYPE_WAKE_UP_GYROSCOPE
- 3, // SENSOR_TYPE_WAKE_UP_LIGHT
- 3, // SENSOR_TYPE_WAKE_UP_PRESSURE
- 3, // SENSOR_TYPE_WAKE_UP_GRAVITY
- 3, // SENSOR_TYPE_WAKE_UP_LINEAR_ACCELERATION
- 5, // SENSOR_TYPE_WAKE_UP_ROTATION_VECTOR
- 3, // SENSOR_TYPE_WAKE_UP_RELATIVE_HUMIDITY
- 3, // SENSOR_TYPE_WAKE_UP_AMBIENT_TEMPERATURE
- 6, // SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED
- 4, // SENSOR_TYPE_WAKE_UP_GAME_ROTATION_VECTOR
- 6, // SENSOR_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED
- 1, // SENSOR_TYPE_WAKE_UP_STEP_DETECTOR
- 1, // SENSOR_TYPE_WAKE_UP_STEP_COUNTER
- 5, // SENSOR_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR
- 1, // SENSOR_TYPE_WAKE_UP_HEART_RATE_MONITOR
1, // SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
1, // SENSOR_TYPE_WAKE_GESTURE
1, // SENSOR_TYPE_GLANCE_GESTURE
diff --git a/core/java/android/hardware/SensorEventListener2.java b/core/java/android/hardware/SensorEventListener2.java
index 4c3b429..70eff08 100644
--- a/core/java/android/hardware/SensorEventListener2.java
+++ b/core/java/android/hardware/SensorEventListener2.java
@@ -21,9 +21,11 @@
*/
public interface SensorEventListener2 extends SensorEventListener {
/**
- * Called after flush() is completed. This flush() could have been initiated by this application
- * or some other application. All the events in the batch at the point when the flush was called
- * have been delivered to the applications registered for those sensor events.
+ * Called after flush() is completed. All the events in the batch at the point when
+ * the flush was called have been delivered to the applications registered for those
+ * sensor events. Flush Complete Events are sent ONLY to the application that has
+ * explicitly called flush(). If the hardware FIFO is flushed due to some other
+ * application calling flush(), flush complete event is not delivered to this application.
* <p>
*
* @param sensor The {@link android.hardware.Sensor Sensor} on which flush was called.
diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java
index 25c7630..cccd624 100644
--- a/core/java/android/hardware/SensorManager.java
+++ b/core/java/android/hardware/SensorManager.java
@@ -390,6 +390,12 @@
* {@link android.hardware.Sensor#TYPE_ALL Sensor.TYPE_ALL} to get all the
* sensors.
*
+ * <p class="note">
+ * NOTE: Both wake-up and non wake-up sensors matching the given type are
+ * returned. Check {@link Sensor#isWakeUpSensor()} to know the wake-up properties
+ * of the returned {@link Sensor}.
+ * </p>
+ *
* @param type
* of sensors requested
*
@@ -439,7 +445,55 @@
public Sensor getDefaultSensor(int type) {
// TODO: need to be smarter, for now, just return the 1st sensor
List<Sensor> l = getSensorList(type);
- return l.isEmpty() ? null : l.get(0);
+ boolean wakeUpSensor = false;
+ // For the following sensor types, return a wake-up sensor. These types are by default
+ // defined as wake-up sensors. For the rest of the SDK defined sensor types return a
+ // non_wake-up version.
+ if (type == Sensor.TYPE_PROXIMITY || type == Sensor.TYPE_SIGNIFICANT_MOTION ||
+ type == Sensor.TYPE_TILT_DETECTOR || type == Sensor.TYPE_WAKE_GESTURE ||
+ type == Sensor.TYPE_GLANCE_GESTURE || type == Sensor.TYPE_PICK_UP_GESTURE) {
+ wakeUpSensor = true;
+ }
+
+ for (Sensor sensor : l) {
+ if (sensor.isWakeUpSensor() == wakeUpSensor) return sensor;
+ }
+ return null;
+ }
+
+ /**
+ * Return a Sensor with the given type and wakeUp properties. If multiple sensors of this
+ * type exist, any one of them may be returned.
+ * <p>
+ * For example,
+ * <ul>
+ * <li>getDefaultSensor({@link Sensor#TYPE_ACCELEROMETER}, true) returns a wake-up accelerometer
+ * sensor if it exists. </li>
+ * <li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, false) returns a non wake-up proximity
+ * sensor if it exists. </li>
+ * <li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, true) returns a wake-up proximity sensor
+ * which is the same as the Sensor returned by {@link #getDefaultSensor(int)}. </li>
+ * </ul>
+ * </p>
+ * <p class="note">
+ * Note: Sensors like {@link Sensor#TYPE_PROXIMITY} and {@link Sensor#TYPE_SIGNIFICANT_MOTION}
+ * are declared as wake-up sensors by default.
+ * </p>
+ * @param type
+ * type of sensor requested
+ * @param wakeUp
+ * flag to indicate whether the Sensor is a wake-up or non wake-up sensor.
+ * @return the default sensor matching the requested type and wakeUp properties if one exists
+ * and the application has the necessary permissions, or null otherwise.
+ * @see Sensor#isWakeUpSensor()
+ */
+ public Sensor getDefaultSensor(int type, boolean wakeUp) {
+ List<Sensor> l = getSensorList(type);
+ for (Sensor sensor : l) {
+ if (sensor.isWakeUpSensor() == wakeUp)
+ return sensor;
+ }
+ return null;
}
/**
diff --git a/core/jni/android_hardware_SensorManager.cpp b/core/jni/android_hardware_SensorManager.cpp
index c588942..ec2bd84 100644
--- a/core/jni/android_hardware_SensorManager.cpp
+++ b/core/jni/android_hardware_SensorManager.cpp
@@ -166,8 +166,7 @@
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 ||
- buffer[i].type == SENSOR_TYPE_WAKE_UP_STEP_COUNTER) {
+ if (buffer[i].type == SENSOR_TYPE_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);