android car源码分析

编程入门 行业动态 更新时间:2024-10-28 13:14:03

android car<a href=https://www.elefans.com/category/jswz/34/1770099.html style=源码分析"/>

android car源码分析

一 android automative架构

属于com.android.car进程

car app:

packages/services/Car/car_product/build/car.mk 这个文件中列出了汽车系统中专有的模块:

BOARD_PLAT_PUBLIC_SEPOLICY_DIR += packages/services/Car/car_product/sepolicy/public   
BOARD_PLAT_PRIVATE_SEPOLICY_DIR += packages/services/Car/car_product/sepolicy/private# Automotive specific packages
PRODUCT_PACKAGES += \CarService \CarTrustAgentService \CarDialerApp \CarRadioApp \OverviewApp \CarLauncher \CarLensPickerApp \LocalMediaPlayer \CarMediaApp \CarMessengerApp \CarHvacApp \CarMapsPlaceholder \CarLatinIME \                                                                                                                                                                                           CarSettings \ CarUsbHandler \android.car \car-frameworks-service \com.android.car.procfsinspector \libcar-framework-service-jni \# System Server components 
PRODUCT_SYSTEM_SERVER_JARS += car-frameworks-service# should add to BOOT_JARS only once
ifeq (,$(INCLUDED_ANDROID_CAR_TO_PRODUCT_BOOT_JARS))                                                                                                                                                        
PRODUCT_BOOT_JARS += \android.car
INCLUDED_ANDROID_CAR_TO_PRODUCT_BOOT_JARS := yes
endif

car api:

packages/services/Car/car-lib/

android.car:包含了与车相关的基本API。例如:车辆后视镜,门,座位,窗口等。
annotation:包含了两个注解。
app
menu:车辆应用菜单相关API。
cluster:仪表盘相关API。
render:渲染相关API。
content
pm:应用包相关API。
diagnostic:包含与汽车诊断相关的API。
hardware:车辆硬件相关API。
cabin:座舱相关API。
hvac:通风空调相关API。(hvac是Heating, ventilation and air conditioning的缩写)
property:属性相关API。
radio:收音机相关API。
input:输入相关API。
media:多媒体相关API。
navigation:导航相关API。
settings:设置相关API。
vms:汽车监测相关API

car service:
Car Service并非一个服务,而是一系列的服务这些服务都在ICarImpl.java构造函数中列了出来。

public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface,CanBusErrorNotifier errorNotifier, String vehicleInterfaceName) {                                                                                                                               mContext = serviceContext;mSystemInterface = systemInterface;mHal = new VehicleHal(vehicle);mVehicleInterfaceName = vehicleInterfaceName;mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext);mCarPowerManagementService = new CarPowerManagementService(mContext, mHal.getPowerHal(),systemInterface);mCarPropertyService = new CarPropertyService(serviceContext, mHal.getPropertyHal());mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarPropertyService);mCarUXRestrictionsService = new CarUxRestrictionsManagerService(serviceContext,mCarDrivingStateService, mCarPropertyService);mCarPackageManagerService = new CarPackageManagerService(serviceContext,mCarUXRestrictionsService,mSystemActivityMonitoringService);mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());mCarProjectionService = new CarProjectionService(serviceContext, mCarInputService);mGarageModeService = new GarageModeService(mContext, mCarPowerManagementService);mCarLocationService = new CarLocationService(mContext, mCarPowerManagementService,mCarPropertyService);mAppFocusService = new AppFocusService(serviceContext, mSystemActivityMonitoringService);mCarAudioService = new CarAudioService(serviceContext);mCarNightService = new CarNightService(serviceContext, mCarPropertyService);mInstrumentClusterService = new InstrumentClusterService(serviceContext,mAppFocusService, mCarInputService);mSystemStateControllerService = new SystemStateControllerService(serviceContext,mCarPowerManagementService, mCarAudioService, this);mPerUserCarServiceHelper = new PerUserCarServiceHelper(serviceContext);mCarBluetoothService = new CarBluetoothService(serviceContext, mCarPropertyService,mPerUserCarServiceHelper, mCarUXRestrictionsService);mVmsSubscriberService = new VmsSubscriberService(serviceContext, mHal.getVmsHal());mVmsPublisherService = new VmsPublisherService(serviceContext, mHal.getVmsHal());mCarDiagnosticService = new CarDiagnosticService(serviceContext, mHal.getDiagnosticHal());mCarStorageMonitoringService = new CarStorageMonitoringService(serviceContext,systemInterface);mCarConfigurationService =new CarConfigurationService(serviceContext, new JsonReaderImpl());mUserManagerHelper = new CarUserManagerHelper(serviceContext);

二 callserive启动流程

1 frameworks/base/services/java/com/android/server/SystemServer.java启动CarServiceHelperService,如下:

            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {                traceBeginAndSlog("StartCarServiceHelperService");mSystemServiceManager.startService(CarServiceHelperService.class);traceEnd();}

而CarServiceHelperService.onStart()会bind到CarService,如下:

        Intent intent = new Intent();intent.setPackage("com.android.car");intent.setAction(CAR_SERVICE_INTERFACE);if (!getContext().bindServiceAsUser(intent, mCarServiceConnection, Context.BIND_AUTO_CREATE,UserHandle.SYSTEM)) { Slog.wtf(TAG, "cannot start car service");}

注意:这里用的是bindService方式,mCarServiceConnection是ServiceConnection类对象,它能监听目标Service的状态,当目标Service所在进程异常退出时,会导致其onServiceDisconnected()方法被调用

2 CarService启动其他service

CarService.onCreate()里会创建ICarImpl的实例,并调用ICarImpl.init()方法;

        Log.i(CarLog.TAG_SERVICE, "Service onCreate"); mCanBusErrorNotifier = new CanBusErrorNotifier(this /* context */);mVehicle = getVehicle();if (mVehicle == null) { throw new IllegalStateException("Vehicle HAL service is not available.");} try { mVehicleInterfaceName = mVehicle.interfaceDescriptor();} catch (RemoteException e) { throw new IllegalStateException("Unable to get Vehicle HAL interface descriptor", e);} Log.i(CarLog.TAG_SERVICE, "Connected to " + mVehicleInterfaceName);mICarImpl = new ICarImpl(this, mVehicle, SystemInterface.getDefault(this),mCanBusErrorNotifier);mICarImpl.init();SystemProperties.set("boot.car_service_created", "1");linkToDeath(mVehicle, mVehicleDeathRecipient);super.onCreate();

而ICarImpl.init()里会启动一大堆Service,其中就包括InstrumentClusterService,如下

        // Be careful with order. Service depending on other service should be inited later. List<CarServiceBase> allServices = new ArrayList<>(Arrays.asList(mSystemActivityMonitoringService,mCarPowerManagementService,mCarSensorService,mCarPackageManagerService,mCarInputService,mGarageModeService,mCarInfoService,mAppFocusService,mCarAudioService,mCarCabinService,mCarHvacService,mCarRadioService,mCarNightService,mInstrumentClusterService,mCarProjectionService,mSystemStateControllerService,mCarVendorExtensionService,mCarBluetoothService,mCarDiagnosticService,mPerUserCarServiceHelper));

注意服务启动顺序,依赖于其他服务的service靠后初始化。


三 架构图

参考文章:

Android Automotive(三)——CarAudioService(AndroidP)_tudouhuashengmi的博客-CSDN博客



Android CarService 源码分析 - 简书

更多推荐

android car源码分析

本文发布于:2024-03-14 20:58:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1737315.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:源码   android   car

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!