Merge "Add confidence to the heart rate monitor definition and clarify onAccuracyChange" into klp-modular-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d7439d8c59
@ -10992,6 +10992,7 @@ package android.hardware {
|
||||
field public static final int SENSOR_STATUS_ACCURACY_HIGH = 3; // 0x3
|
||||
field public static final int SENSOR_STATUS_ACCURACY_LOW = 1; // 0x1
|
||||
field public static final int SENSOR_STATUS_ACCURACY_MEDIUM = 2; // 0x2
|
||||
field public static final int SENSOR_STATUS_NO_CONTACT = -1; // 0xffffffff
|
||||
field public static final int SENSOR_STATUS_UNRELIABLE = 0; // 0x0
|
||||
field public static final deprecated int SENSOR_TEMPERATURE = 4; // 0x4
|
||||
field public static final deprecated int SENSOR_TRICORDER = 64; // 0x40
|
||||
|
@ -381,11 +381,17 @@ public final class Sensor {
|
||||
/**
|
||||
* A constant describing a heart rate monitor.
|
||||
* <p>
|
||||
* A sensor that measures the heart rate in beats per minute.
|
||||
* The reported value is the heart rate in beats per minute.
|
||||
* <p>
|
||||
* value[0] represents the beats per minute when the measurement was taken.
|
||||
* value[0] is 0 if the heart rate monitor could not measure the rate or the
|
||||
* rate is 0 beat per minute.
|
||||
* The reported accuracy represents the status of the monitor during the reading. See the
|
||||
* {@code SENSOR_STATUS_*} constants in {@link android.hardware.SensorManager SensorManager}
|
||||
* for more details on accuracy/status values. In particular, when the accuracy is
|
||||
* {@code SENSOR_STATUS_UNRELIABLE} or {@code SENSOR_STATUS_NO_CONTACT}, the heart rate
|
||||
* value should be discarded.
|
||||
* <p>
|
||||
* This sensor requires permission {@code android.permission.BODY_SENSORS}.
|
||||
* It will not be returned by {@code SensorManager.getSensorsList} nor
|
||||
* {@code SensorManager.getDefaultSensor} if the application doesn't have this permission.
|
||||
*/
|
||||
public static final int TYPE_HEART_RATE = 21;
|
||||
|
||||
|
@ -39,11 +39,13 @@ public interface SensorEventListener {
|
||||
public void onSensorChanged(SensorEvent event);
|
||||
|
||||
/**
|
||||
* Called when the accuracy of a sensor has changed.
|
||||
* <p>See {@link android.hardware.SensorManager SensorManager}
|
||||
* for details.
|
||||
* Called when the accuracy of the registered sensor has changed.
|
||||
*
|
||||
* @param accuracy The new accuracy of this sensor
|
||||
* <p>See the SENSOR_STATUS_* constants in
|
||||
* {@link android.hardware.SensorManager SensorManager} for details.
|
||||
*
|
||||
* @param accuracy The new accuracy of this sensor, one of
|
||||
* {@code SensorManager.SENSOR_STATUS_*}
|
||||
*/
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy);
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy);
|
||||
}
|
||||
|
@ -320,6 +320,13 @@ public abstract class SensorManager {
|
||||
public static final int SENSOR_DELAY_NORMAL = 3;
|
||||
|
||||
|
||||
/**
|
||||
* The values returned by this sensor cannot be trusted because the sensor
|
||||
* had no contact with what it was measuring (for example, the heart rate
|
||||
* monitor is not in contact with the user).
|
||||
*/
|
||||
public static final int SENSOR_STATUS_NO_CONTACT = -1;
|
||||
|
||||
/**
|
||||
* The values returned by this sensor cannot be trusted, calibration is
|
||||
* needed or the environment doesn't allow readings
|
||||
@ -421,9 +428,10 @@ public abstract class SensorManager {
|
||||
* {@link SensorManager#getSensorList(int) getSensorList}.
|
||||
*
|
||||
* @param type
|
||||
* of sensors requested
|
||||
* of sensors requested
|
||||
*
|
||||
* @return the default sensors matching the asked type.
|
||||
* @return the default sensor matching the requested type if one exists and the application
|
||||
* has the necessary permissions, or null otherwise.
|
||||
*
|
||||
* @see #getSensorList(int)
|
||||
* @see Sensor
|
||||
|
@ -395,25 +395,12 @@ public class SystemSensorManager extends SensorManager {
|
||||
t.timestamp = timestamp;
|
||||
t.accuracy = inAccuracy;
|
||||
t.sensor = sensor;
|
||||
switch (t.sensor.getType()) {
|
||||
// Only report accuracy for sensors that support it.
|
||||
case Sensor.TYPE_MAGNETIC_FIELD:
|
||||
case Sensor.TYPE_ORIENTATION:
|
||||
// call onAccuracyChanged() only if the value changes
|
||||
final int accuracy = mSensorAccuracies.get(handle);
|
||||
if ((t.accuracy >= 0) && (accuracy != t.accuracy)) {
|
||||
mSensorAccuracies.put(handle, t.accuracy);
|
||||
mListener.onAccuracyChanged(t.sensor, t.accuracy);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// For other sensors, just report the accuracy once
|
||||
if (mFirstEvent.get(handle) == false) {
|
||||
mFirstEvent.put(handle, true);
|
||||
mListener.onAccuracyChanged(
|
||||
t.sensor, SENSOR_STATUS_ACCURACY_HIGH);
|
||||
}
|
||||
break;
|
||||
|
||||
// call onAccuracyChanged() only if the value changes
|
||||
final int accuracy = mSensorAccuracies.get(handle);
|
||||
if ((t.accuracy >= 0) && (accuracy != t.accuracy)) {
|
||||
mSensorAccuracies.put(handle, t.accuracy);
|
||||
mListener.onAccuracyChanged(t.sensor, t.accuracy);
|
||||
}
|
||||
mListener.onSensorChanged(t);
|
||||
}
|
||||
|
@ -176,11 +176,26 @@ private:
|
||||
gBaseEventQueueClassInfo.dispatchFlushCompleteEvent,
|
||||
buffer[i].meta_data.sensor);
|
||||
} else {
|
||||
int8_t status;
|
||||
switch (buffer[i].type) {
|
||||
case SENSOR_TYPE_ORIENTATION:
|
||||
case SENSOR_TYPE_MAGNETIC_FIELD:
|
||||
case SENSOR_TYPE_ACCELEROMETER:
|
||||
case SENSOR_TYPE_GYROSCOPE:
|
||||
status = buffer[i].vector.status;
|
||||
break;
|
||||
case SENSOR_TYPE_HEART_RATE:
|
||||
status = buffer[i].heart_rate.status;
|
||||
break;
|
||||
default:
|
||||
status = SENSOR_STATUS_ACCURACY_HIGH;
|
||||
break;
|
||||
}
|
||||
env->CallVoidMethod(mReceiverObject,
|
||||
gBaseEventQueueClassInfo.dispatchSensorEvent,
|
||||
buffer[i].sensor,
|
||||
mScratch,
|
||||
buffer[i].vector.status,
|
||||
status,
|
||||
buffer[i].timestamp);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user