Only requantize sensor max range if significant
The previous computation that decided whether to adjust the sensor's
reported maximum range if not a multiple of the resolution was
susceptible to floating point error (e.g. considering 5.0 as not a
multiple of 0.1), so rework this to only update the maximum range and
print a warning log if the maximum range would be changed significantly
after requantization. We define significant here as resolution/8 (i.e.
the target quantization level).
Also, make the reported power clamping log more helpful.
Fixes: 182828004
Test: compare SensorService startup logs before & after change
Change-Id: I44e399a7aca6fe8ff02bd2840525c95798cda1f4
diff --git a/services/sensorservice/SensorDeviceUtils.h b/services/sensorservice/SensorDeviceUtils.h
index 1309971..255f7e1 100644
--- a/services/sensorservice/SensorDeviceUtils.h
+++ b/services/sensorservice/SensorDeviceUtils.h
@@ -32,16 +32,15 @@
namespace android {
namespace SensorDeviceUtils {
-// Quantizes a single value using a sensor's resolution.
-inline void quantizeValue(float *value, double resolution) {
+// Quantizes a single value to (a fractional factor of) a sensor's resolution. Typically we
+// increase the value of the sensor's nominal resolution to ensure that sensor accuracy
+// improvements, like runtime calibration, are not masked during requantization.
+inline void quantizeValue(float *value, double resolution, double factor = 0.125) {
if (resolution == 0) {
return;
}
- // Increase the value of the sensor's nominal resolution to ensure that
- // sensor accuracy improvements, like runtime calibration, are not masked
- // during requantization.
- double incRes = 0.125 * resolution;
+ double incRes = factor * resolution;
*value = round(static_cast<double>(*value) / incRes) * incRes;
}