当前位置:   article > 正文

VehicleHal.java - fwk层对应VehicleService

vehiclehal

android12-release
【IVI】VehicleService启动
【IVI】车载设备硬件抽象层VHAL
【IVI】CarService启动


在这里插入图片描述

1、VehicleHal.java初始化

  • CarService: 位于 /platform/packages/services/Car/
  1. 流程主要有两个,一是创建CarService.java#onCreate() -> ICarImpl.java#new -> VehicleHal.java#new,而是初始化CarService.java#onCreate() -> ICarImpl.java#init -> VehicleHal.java#init
  2. android.hardware.automotive.vehicle.V2_0.IVehicle.getService(instanceName)获取底层服务VehicleService.cpp/IVehicle.hal
    在这里插入图片描述
  3. VehicleHal.java创建初始化,此类处理与本机HAL的接口,并对接收的数据进行基本解析(类型检查)。然后将每个事件发送到相应的HalServiceBase实现。HalServiceBase负责将数据转换为相应的Car*ServiceCar*Manager API
    在这里插入图片描述

1.1 hal服务区分

hal服务区分相关属性types.hal说明对应API Manager和service
PowerHalServiceAP_POWER_STATE_REQAP_POWER_STATE_REPORTDISPLAY_BRIGHTNESS将 HAL 电源事件转换为更高级别的语义信息CarPowerManagementService - CarPowerManager
PropertyHalService此车辆 HAL 支持的所有属性配置的列表。mAllPropertiesgetAllPropConfigs()HAL 服务的通用接口,通过 ICarProperty 来回发送车辆属性。通过 ICarProperty 来回传递车辆属性进行通信的服务应扩展此类。CarPropertyService - CarPropertyManager
InputHalServiceHW_KEY_INPUTHW_ROTARY_INPUTHW_CUSTOM_INPUT将 HAL 输入事件转换为更高级别的语义信息。CarInputService - CarInputManager
VmsHalServiceVEHICLE_MAP_SERVICEVMS 客户端实现,它使用特定于 HAL 的消息编码代理 VmsPublisher/VmsSubscriber API 对车辆 HAL 的调用。
UserHalServiceCREATE_USERINITIAL_USER_INFOREMOVE_USERSWITCH_USERUSER_IDENTIFICATION_ASSOCIATION用于将OEM的自定义用户管理与Android集成的服务。CarUserService - CarUserManager
DiagnosticHalServiceOBD2_LIVE_FRAMEOBD2_FREEZE_FRAMEOBD2_FREEZE_FRAME_INFOOBD2_FREEZE_FRAME_CLEAR诊断 HAL 服务支持从 VHAL 收集诊断信息并将其转换为更高级别的语义信息CarDiagnosticService - CarDiagnosticManager
ClusterHalServiceCLUSTER_SWITCH_UICLUSTER_DISPLAY_STATECLUSTER_REPORT_STATECLUSTER_REQUEST_DISPLAYCLUSTER_NAVIGATION_STATE将 HAL 输入事件转换为更高级别的语义信息。ClusterHomeService - ClusterHomeManager
EvsHalServiceEVS_SERVICE_REQUEST将CarEvsService感兴趣的HAL事件转换为更高级别的语义信息。CarEvsService - CarEvsManager
HalClient区别以上hal服务,VehicleHal.java通过HalClient底层IVehicle.hal交互车辆 HAL 客户端。直接与车辆 HAL 接口 IVehicle 交互。包含一些可重试属性的逻辑,将车辆通知重定向到给定的活套线程。

1.2 简要时序图

在这里插入图片描述

2、PowerHalService为例

2.1 PowerHalService初始化和订阅

  • VehicleHal.java#init -> PowerHalService#init订阅最终调用到mVehicle.subscribe(),并注册监听回调IVehicleCallbackVehicleHal extends IVehicleCallback.Stub
    在这里插入图片描述
  • IVehicleCallback.hal#onPropertyEvent -> VehicleHal.java#onPropertyEvent -> PowerHalService.java#onHalEvents -> PowerEventListener 属性监听最终传递给APP等注册的监听PowerEventListener
    在这里插入图片描述
private void dispatchEvents(List<VehiclePropValue> values, PowerEventListener listener) {
    for (VehiclePropValue v : values) {
        switch (v.prop) {
            case AP_POWER_STATE_REPORT:
                // Ignore this property event. It was generated inside of CarService.
                break;
            case AP_POWER_STATE_REQ:
                int state = v.value.int32Values.get(VehicleApPowerStateReqIndex.STATE);
                int param = v.value.int32Values.get(VehicleApPowerStateReqIndex.ADDITIONAL);
                Slog.i(CarLog.TAG_POWER, "Received AP_POWER_STATE_REQ="
                        + powerStateReqName(state) + " param=" + param);
                listener.onApPowerStateChange(new PowerState(state, param));
                break;
            case DISPLAY_BRIGHTNESS:
            {
                int maxBrightness;
                synchronized (mLock) {
                    maxBrightness = mMaxDisplayBrightness;
                }
                int brightness = v.value.int32Values.get(0) * MAX_BRIGHTNESS / maxBrightness;
                if (brightness < 0) {
                    Slog.e(CarLog.TAG_POWER, "invalid brightness: " + brightness
                            + ", set to 0");
                    brightness = 0;
                } else if (brightness > MAX_BRIGHTNESS) {
                    Slog.e(CarLog.TAG_POWER, "invalid brightness: " + brightness + ", set to "
                            + MAX_BRIGHTNESS);
                    brightness = MAX_BRIGHTNESS;
                }
                Slog.i(CarLog.TAG_POWER, "Received DISPLAY_BRIGHTNESS=" + brightness);
                listener.onDisplayBrightnessChange(brightness);
            }
                break;
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

2.2 简要时序图

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/636449
推荐阅读
相关标签
  

闽ICP备14008679号