栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

android car源码分析

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

android car源码分析

一 android automative架构

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 );
        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 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 源码分析 - 简书

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/877529.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号