Jelly Bean Sensor Framework

来源:互联网 发布:sql树结构 所以父节点 编辑:程序博客网 时间:2024/06/04 19:42

如果您要转载,请注明原创作者是蝈蝈

Frameworks

Below is a picture to show how sensor works in JB.

Each Application would create an EventListener to handle events from sensorHW. Below is a snap shot for EventListener, usually, onSensorChanged() and onAccuracyChanged() would be provided.

 

The Application registers the created EventListener to the SystemSensorManager which has a pooling thread and will invokes the callback functions in EventThread once read any event data from SensorEventQueue whose data is from SensorService.

SystemSensorManager enables the required sensor once registered with the EventListener. The control commands are sent to sensorService also through SensorEventQueue.

For the data flow, the sensorEventQueue holds a bitTube buffer; sensorSevice is responsible to write it with sensor event polled from sensorhal while systemSensorManager has a thread reads data from the bitTube buffer and invokes registered callbacks.

2.    Sensor Service

Sensor Service is an android service run in system_server.

Sensor Service has a fancy fusion instance which could generate virtual sensors event data. Once hardware not supplies such virtual sensors, Sensor Service uses its own virtual sensors. Those virtual sensors include Rotation vector, Gravity, Linear Acceleration, and Orientation. And to support those virtual sensors, hardware should at least provide Accelerator, Magnetic and Gyroscope sensors.

SensorDevice holds an internal class BatteryService. It is used to inform the BatteryService that how much time the sensor running. noteStartSensor() is called when enabling a sensor while noteStopSensor() is called when disabling a sensor.

3.    Control Flow sequence

Below is the control flow for register an event listener by applications.

原创粉丝点击