分享

Jelly Bean Sensor Framework

 写意人生 2014-06-28

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

原文地址:http://blog.csdn.net/guoguodaern/article/details/7984176

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.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多