VehicleHal.java - fwk层对应VehicleService
- 1、VehicleHal.java初始化
- 1.1 hal服务区分
- 1.2 简要时序图
- 2、PowerHalService为例
- 2.1 PowerHalService初始化和订阅
- 2.2 简要时序图
android12-release
【IVI】VehicleService启动
【IVI】车载设备硬件抽象层VHAL
【IVI】CarService启动
1、VehicleHal.java初始化
- CarService: 位于
/platform/packages/services/Car/
。
- 流程主要有两个,一是创建
CarService.java#onCreate() -> ICarImpl.java#new -> VehicleHal.java#new
,而是初始化CarService.java#onCreate() -> ICarImpl.java#init -> VehicleHal.java#init
android.hardware.automotive.vehicle.V2_0.IVehicle.getService(instanceName)
获取底层服务VehicleService.cpp/IVehicle.hal
VehicleHal.java
创建初始化,此类处理与本机HAL的接口,并对接收的数据进行基本解析(类型检查)。然后将每个事件发送到相应的HalServiceBase
实现。HalServiceBase负责将数据转换为相应的Car*Service
和Car*Manager API
。
1.1 hal服务区分
hal服务区分 | 相关属性types.hal | 说明 | 对应API Manager和service |
---|---|---|---|
PowerHalService | AP_POWER_STATE_REQ 、AP_POWER_STATE_REPORT 、DISPLAY_BRIGHTNESS | 将 HAL 电源事件转换为更高级别的语义信息 | CarPowerManagementService - CarPowerManager |
PropertyHalService | 此车辆 HAL 支持的所有属性配置的列表。mAllProperties 即getAllPropConfigs() | HAL 服务的通用接口,通过 ICarProperty 来回发送车辆属性。通过 ICarProperty 来回传递车辆属性进行通信的服务应扩展此类。 | CarPropertyService - CarPropertyManager |
InputHalService | HW_KEY_INPUT 、HW_ROTARY_INPUT 、HW_CUSTOM_INPUT | 将 HAL 输入事件转换为更高级别的语义信息。 | CarInputService - CarInputManager |
VmsHalService | VEHICLE_MAP_SERVICE | VMS 客户端实现,它使用特定于 HAL 的消息编码代理 VmsPublisher/VmsSubscriber API 对车辆 HAL 的调用。 | |
UserHalService | CREATE_USER 、INITIAL_USER_INFO 、REMOVE_USER 、SWITCH_USER 、USER_IDENTIFICATION_ASSOCIATION | 用于将OEM的自定义用户管理与Android集成的服务。 | CarUserService - CarUserManager |
DiagnosticHalService | OBD2_LIVE_FRAME 、OBD2_FREEZE_FRAME 、OBD2_FREEZE_FRAME_INFO 、OBD2_FREEZE_FRAME_CLEAR | 诊断 HAL 服务支持从 VHAL 收集诊断信息并将其转换为更高级别的语义信息 | CarDiagnosticService - CarDiagnosticManager |
ClusterHalService | CLUSTER_SWITCH_UI 、CLUSTER_DISPLAY_STATE 、CLUSTER_REPORT_STATE 、CLUSTER_REQUEST_DISPLAY 、CLUSTER_NAVIGATION_STATE | 将 HAL 输入事件转换为更高级别的语义信息。 | ClusterHomeService - ClusterHomeManager |
EvsHalService | EVS_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()
,并注册监听回调IVehicleCallback
即VehicleHal 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;
}
}
}