From 663720b29f412756b8599897df9f8e32eb930be2 Mon Sep 17 00:00:00 2001 From: Jim Kaye Date: Mon, 8 May 2017 09:07:27 -0700 Subject: [PATCH] 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 --- services/sensorservice/SensorService.cpp | 3 +-- 1 file changed, 1 insertion(+), 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& 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 - -- 2.11.0