I am currently developing a driver for an ambient light sensor on a Qualcomm Snapdragon 888 platform.
When I try to interact with the device through the Android Sensor Framework I only get the Lux value (in the onSensorChanged
callback the size of the values
field in SensorEvent
object is 1
whereas multiple data are pushed along with the Lux measure).
When having a look at the proprietary vendor implementation of the HAL I can clearly see that multiple data are being pushed to the HAL event message queue, but only the Lux info is forwarded by the framework.
I guess that somewhere in the AOSP the additional information (raw data in my case) are being discarded / ignored and I can't really find where this operation is done in the codebase.
To summarize, I would like to know which location has to be patched in order to keep these information and be able to use them at application level.
While doing some research I came across this question where users were using some additional info forwarded by the sensor framework for the light sensor: Reading Android RGB light sensor - Galaxy S5
Thank you!
It took me some time but I managed to get it working applying the following patches:
frameworks/base/core/java/android/hardware/Sensor.java
, update the entry of your sensor in the sSensorReportingModes
array with the desired data length:private static final int[] sSensorReportingModes = {
...
2, // SENSOR_TYPE_LIGHT
...
}
hardware/interfaces/sensors/1.0/default/convert.cpp
, update the following methods accordingly:void convertFromSensorEvent(const sensors_event_t &src, Event *dst) {
...
case SensorType::LIGHT:
dst->u.data[0] = src.data[0];
dst->u.data[1] = src.data[1];
break;
...
}
void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
...
case SensorType::LIGHT:
dst->data[0] = src.u.data[0];
dst->data[1] = src.u.data[1];
break;
...
}