summaryrefslogtreecommitdiff
path: root/services/sensorservice
diff options
context:
space:
mode:
authorJim Kaye <jameskaye@google.com>2017-05-08 09:07:27 -0700
committerJim Kaye <jameskaye@google.com>2017-05-08 16:31:52 +0000
commit663720b29f412756b8599897df9f8e32eb930be2 (patch)
tree7b36230ffd8c01d058fa8c36c30b909c2225067e /services/sensorservice
parent584bc3cebf3f23d378fc7ed06e71c5d1722373dd (diff)
downloadnative-663720b29f412756b8599897df9f8e32eb930be2.tar.gz
Fix enforcement of sensor's slowest rate
This code calculates a sensor's maximum sample period in nanoseconds. This is stored as a 64-bit value, as required for periods greater than ~2.1 seconds. The calculation was done with 32-bit arithmetic, sometimes resulting in overflow. This caused the sensor to run at its maximum rate. (The requested period is first clipped to the maximum period. When the maximum period appears negative, it is always used. The now-negative period is then clipped to the minimum period, resulting in the sensor's maximum supported rate.) Bug: 37465457 Test: Verified correct operation with Goldfish accelerometer, which has a 60-second maximum period. Change-Id: Ic75a9dc7c4e7c9ca690eafbfa51ee50540ca5aaf
Diffstat (limited to 'services/sensorservice')
-rw-r--r--services/sensorservice/SensorService.cpp3
1 files changed, 1 insertions, 2 deletions
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index c5bbeee4d9..d60768c98d 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -1250,7 +1250,7 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection,
}
// Check maximum delay for the sensor.
- nsecs_t maxDelayNs = sensor->getSensor().getMaxDelay() * 1000;
+ nsecs_t maxDelayNs = sensor->getSensor().getMaxDelay() * 1000LL;
if (maxDelayNs > 0 && (samplingPeriodNs > maxDelayNs)) {
samplingPeriodNs = maxDelayNs;
}
@@ -1511,4 +1511,3 @@ bool SensorService::isOperationRestricted(const String16& opPackageName) {
}
}; // namespace android
-