1.概览
这部分是SensorHal部分的二阶段初始化,不放在SensorDevice中一起,主要是想强调下这俩所在进程的不同。所以在程序调用流程上也不应该柔和在一起。看起来无缝调用,只不过Android中的binder在默默耕耘罢了。
2.SensorHal的初始化–HalProxyV2_0::initialize
2.1 SensorHal 中 initialize 接口定义
initialize 接口是在 ISensors.hal 中定义的,意味着本次从SensorDevice调用到 HalProxyV2_0::initialize是跨进程的。
//hardware/interfaces/sensors/2.0/ISensors.hal
interface ISensors {
...
@entry
@callflow(next = {
"getSensorsList"})
initialize(fmq_sync<Event> eventQueueDescriptor,
fmq_sync<uint32_t> wakeLockDescriptor,
ISensorsCallback sensorsCallback)
generates
(Result result);
...
};
eventQueueDescriptor Fast Message Queue descriptor that is used to create the Event FMQ which is where sensor events are written. The descriptor is obtained from the framework’s FMQ that is used to read sensor events.
wakeLockDescriptor Fast Message Queue descriptor that is used to create the Wake Lock FMQ which is where wake_lock events are read from. The descriptor is obtained from the framework’s FMQ that is used to write wake_lock events.
sensorsCallback sensors callback that receives asynchronous data from the Sensors HAL.
所以入参都是从SensorDevice所在进程传递而来的。
2.2 HalProxyV2_0::initialize 接口的实现
在第四章节中描述过ISensor HIDL接口的实现,它的实现类就是 HalProxyV2_0 ,类图如下

它的接口实现位于 IHalProxy 类中
//hardware\interfaces\sensors\common\default\2.x\multihal\include\HalProxy.h
template <class ISensorsVersion>
class IHalProxy : public HalProxy, public ISensorsVersion {
public:
Return<Result> initialize(
const ::android::hardware::MQDescriptorSync<V1_0::Event>& eventQueueDescriptor,
const

本文详细解析了SensorHAL的二阶段初始化过程,包括HalProxyV2_0::initialize接口的定义与实现,以及初始化过程中涉及的主要组件如EventFMQ和WakeLockFMQ的工作原理。
最低0.47元/天 解锁文章
1651





