Native: Sensor: For ndk sensor enable request, enable sensor with
SENSOR_DELAY_NORMAL delay instead of 0 delay, by default
In case of one or more sensor applications running in background
(say Auto Rotation, Auto Brightness, some sensor ndk daemon like
panning, etc), which are using the common sensor (say accelerometer)
running at UI delay(66 ms), and then some 3rd party sensor ndk daemon
starts(say Direct Call feature, GPS ndk daemon for correcting latitude
and longitude using sensor data while using navigation, etc), which
enables the same sensor (accelerometer) but does not set the delay,
then that sensor chip will start to generate data at minimum delay
possible because of passing 0 delay value during enable.
Ideally, this is wrong behaviour because none of the sensor-ndk daemon
or android application has requested for minimum delay yet and so sensor
should generate data still at 66ms only. This in turn will make
significant increment in current consumption because of fastest sampling
rate.
Also, as you know, ASensorEventQueue_enableSensor api and
ASensorEventQueue_setEventRate api are not deprecated and is still used
irrespective of HAL 1_3 or latest 1_4. In fact, these are the only two
api currently available for enabling and setting delay. Direct Call,
panning, Smart alert, gps daemon, etc are such examples which uses these
ndk api
Small Code Snippet:
AutoRotation starts:
mSensorManager.registerListener(
listener1, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
AutoBrightness start:
mSensorManager.registerListener(
listener2, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
mSensorManager.registerListener(
listener2, mLight, SensorManager.SENSOR_DELAY_NORMAL);
Panning:
ASensorEventQueue_enableSensor(mSensorEventQueue1, mAccelerometer);
ASensorEventQueue_setEventRate(
mSensorEventQueue1, mAccelerometer, SENSOR_DELAY_UI);
(Here, first 0 delay will be set, but UI delay will override it with
function call setEventRate)
... more possible android-apps/sensor-ndk daemon
So currently, accelerometer is running at 66 ms delay
because DELAY_UI (66ms) is less than DELAY_NORMAL (200ms)
Now, sensor gps ndk daemon starts, enables the sensor but does not set
delay:
ASensorEventQueue_enableSensor(mSensorEventQueue2, mAccelerometer);
--> This call will request for 0ms delay so minimum delay will be set
(say 10ms)
Therefore now, accelerometer will run at 10 ms delay which is wrong
behavior because delay should still be 66 ms ideally. Also, running
sensor at lowest delay unnecessarily increases current consumption.
(Unless requested for minimum delay like in games)
Change-Id: Ib18d0d77f80b2621a204d491c3f61eed9a8b7251
Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
Signed-off-by: Aniroop Mathur <aniroop.mathur@gmail.com>
diff --git a/libs/gui/SensorEventQueue.cpp b/libs/gui/SensorEventQueue.cpp
index 4b7986e..5983a6c 100644
--- a/libs/gui/SensorEventQueue.cpp
+++ b/libs/gui/SensorEventQueue.cpp
@@ -125,7 +125,7 @@
}
status_t SensorEventQueue::enableSensor(Sensor const* sensor) const {
- return mSensorEventConnection->enableDisable(sensor->getHandle(), true, 0, 0, false);
+ return mSensorEventConnection->enableDisable(sensor->getHandle(), true, us2ns(200000), 0, false);
}
status_t SensorEventQueue::disableSensor(Sensor const* sensor) const {