淘宝网站建设基本流程图,沈阳网站建设服务电话,谷歌seo知识,wordpress登陆评论Android Automotive平台
Android Automotive是通过Android的通用框架#xff0c;语言和API来实现的一个全栈#xff0c;开源#xff0c;高度可定制的平台。
Android Automotive与整个Android生态系统的关系
Android Automotive是Android的一部分。 Android Automotive不是…Android Automotive平台
Android Automotive是通过Android的通用框架语言和API来实现的一个全栈开源高度可定制的平台。
Android Automotive与整个Android生态系统的关系
Android Automotive是Android的一部分。 Android Automotive不是Android的分支或并行开发它与手机平板电脑等安卓设备上的Android具有相同的代码库并且位于相同的存储库中。它基于经过10多年开发的强大平台和功能集可利用现有的安全模型兼容性程序开发人员工具和基础架构同时继续具有高度可定制性和可移植性完全免费和开源的特点。Android Automotive扩展了Android 。在将Android打造为功能齐全的信息娱乐平台的过程中我们添加了对汽车特定要求功能和技术的支持。就像今天用于移动设备的Android一样Android Automotive将是一个完整的汽车信息娱乐平台。
Android Automotive架构 Automotive
Android Automative是在原先Android的系统架构上增加了一些与车相关的图中虚线框中绿色背景的模块。
Car App 包括OEM和第三方开发的AppCar API 提供给汽车App特有的接口Car Service 系统中与车相关的服务主要是基于CarProperty实现Vechile相关的一些策略Vehicle Network Service 汽车的网络服务Vehicle HAL 汽车的硬件抽象层描述定义 OEM 可以实现的车辆属性的接口
Android CarAPI CarAPI
· annotation包含了两个注解。 · app · menu车辆应用菜单相关API。 · cluster仪表盘相关API。 · render渲染相关API。 · content · pm应用包相关API。 · diagnostic包含与汽车诊断相关的API。 · hardware车辆硬件相关API。 · cabin座舱相关API。 · hvac通风空调相关API。 · property属性相关API(实现定制的property)。 · radio收音机相关API。 · input输入相关API。 · media多媒体相关API。 · navigation导航相关API。 · settings设置相关API。 · vms汽车监测相关API
这些api集合中我们可以通过CarpropertyManager去实现定制的property功能简要类图 CarpropertyManager内部方法
通过registerListener注册自定义的propertyId以及property变更通知的callback 解注册CarpropertyEventListener 获取所有property, 返回一个元素类型是CarpropertyConfig的list 获取property状态 获取property value 设置property value CarpropertyManager与service层交互的AIDL接口 需要注意的是ICarProperty是同步接口ICarPropertyEventListener是异步接口。
onEvent传上来的是参数是CarPropertyEvent的listCarPropertyEvent中包含event type与CarPropertyValue; eventType包含PROPERTY_EVENT_PROPERTY_CHANGE与PROPERTY_EVENT_ERROR分别对应listener中的onPropertyChanged和PROPERTY_EVENT_ERROR CarPropertyValue则包含具体的propId、propValue等具体属性信息。
Android CarService
代码目录 packages/services/Car/serviceCarService并非一个服务而是一系列的服务。这些服务都在ICarImpl.java构造函数中列了出来 CarService启动流程 启动CarServiceHelperService
SystemServer启动过程中在ActivityManagerService systemReady时启动CarServiceHelperService。 代码
android/frameworks/base/services/java/com/android/server/SystemServer.java
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {t.traceBegin(StartCarServiceHelperService);final SystemService cshs mSystemServiceManager.startService(CAR_SERVICE_HELPER_SERVICE_CLASS);if (cshs instanceof Dumpable) {mDumper.addDumpable((Dumpable) cshs);}if (cshs instanceof DevicePolicySafetyChecker) {dpms.setDevicePolicySafetyChecker((DevicePolicySafetyChecker) cshs);}t.traceEnd();
}
private static final String CAR_SERVICE_HELPER_SERVICE_CLASS com.android.internal.car.CarServiceHelperService;启动CarService
CarServiceHelperService在onStart时拉起CarServcie加载Native库car-framework-service-jni。
代码
android/frameworks/opt/car/services/src/com/android/internal/car/CarServiceHelperService.java
public void onStart() {EventLog.writeEvent(EventLogTags.CAR_HELPER_START);
IntentFilter filter new IntentFilter(Intent.ACTION_REBOOT);filter.addAction(Intent.ACTION_SHUTDOWN);mContext.registerReceiverForAllUsers(mShutdownEventReceiver, filter, null, null);mCarWatchdogDaemonHelper.addOnConnectionChangeListener(mConnectionListener);mCarWatchdogDaemonHelper.connect();Intent intent new Intent();intent.setPackage(com.android.car);intent.setAction(CAR_SERVICE_INTERFACE);if (!mContext.bindServiceAsUser(intent, mCarServiceConnection, Context.BIND_AUTO_CREATE,mHandler, UserHandle.SYSTEM)) {Slogf.wtf(TAG, cannot start car service);}loadNativeLibrary();
}
void loadNativeLibrary() {System.loadLibrary(car-framework-service-jni);
}
代码
android/packages/services/Car/car-lib/src/com/android/car/internal/common/CommonConstants.java
public static final String CAR_SERVICE_INTERFACE android.car.ICar;代码
android/packages/services/Car/service/AndroidManifest.xml
manifest xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:androidprvhttp://schemas.android.com/apk/prv/res/androidpackagecom.android.carcoreApptrueandroid:sharedUserIdandroid.uid.system
application android:labelstring/app_titleandroid:directBootAwaretrueandroid:allowBackupfalseandroid:persistenttrueservice android:name.CarServiceandroid:singleUsertrueandroid:exportedtrueintent-filteraction android:nameandroid.car.ICar//intent-filter/service初始化ICarImpl
CarService在onCreate时先判断Vehicle HAL起来了然后再初始化ICarImpl。 代码
android/packages/services/Car/service/src/com/android/car/CarService.java
public void onCreate() {LimitedTimingsTraceLog initTiming new LimitedTimingsTraceLog(CAR_SERVICE_INIT_TIMING_TAG,Trace.TRACE_TAG_SYSTEM_SERVER, CAR_SERVICE_INIT_TIMING_MIN_DURATION_MS);initTiming.traceBegin(CarService.onCreate);
initTiming.traceBegin(getVehicle);mVehicle getVehicle();initTiming.traceEnd();EventLog.writeEvent(EventLogTags.CAR_SERVICE_CREATE, mVehicle null ? 0 : 1);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);}Slog.i(CarLog.TAG_SERVICE, Connected to mVehicleInterfaceName);EventLog.writeEvent(EventLogTags.CAR_SERVICE_CONNECTED, mVehicleInterfaceName);mICarImpl new ICarImpl(this,mVehicle,SystemInterface.Builder.defaultSystemInterface(this).build(),mVehicleInterfaceName);mICarImpl.init();linkToDeath(mVehicle, mVehicleDeathRecipient);ServiceManager.addService(car_service, mICarImpl);SystemProperties.set(boot.car_service_created, 1);super.onCreate();initTiming.traceEnd(); // CarService.onCreate
}
private static IVehicle getVehicle() {final String instanceName SystemProperties.get(ro.vehicle.hal, default);
try {return android.hardware.automotive.vehicle.V2_0.IVehicle.getService(instanceName);} catch (RemoteException e) {Slog.e(CarLog.TAG_SERVICE, Failed to get IVehicle/ instanceName service, e);} catch (NoSuchElementException e) {Slog.e(CarLog.TAG_SERVICE, IVehicle/ instanceName service not registered yet);}return null;
}
代码
android/packages/services/Car/car-lib/src/android/car/ICar.aidl
android/packages/services/Car/service/src/com/android/car/ICarImpl.java初始化各个Car Services组件
ICarImpl构造函数中构造了下面几个实现了CarServiceBase接口的Car Services组件以及VehicleHal和CarStatsService然后通过init函数进行初始化。
CarFeatureController
CarPropertyService
CarDrivingStateService
CarUxRestrictionsManagerService
CarUserService
CarOccupantZoneService
SystemActivityMonitoringService
CarPowerManagementService
CarUserNoticeService
CarPackageManagerService
PerUserCarServiceHelper
CarBluetoothService
CarInputService
CarProjectionService
GarageModeService
AppFocusService
CarAudioService
CarNightService
FixedActivityService
ClusterNavigationService
InstrumentClusterService
VmsBrokerService
CarDiagnosticService
CarStorageMonitoringService
CarLocationService
CarMediaService
CarBugreportManagerService
CarExperimentalFeatureServiceController
CarWatchdogService
CarDevicePolicyService
ClusterHomeService
CarEvsService
CarTelemetryService
CarActivityService初始化各个Hal Services组件
VehicleHal构造函数中构造了下面几个继承自HalServiceBase基类的Hal Services组件以及HalClient然后通过init函数进行初始化。
PowerHalService
PropertyHalService
InputHalService
VmsHalService
UserHalService
DiagnosticHalService
ClusterHalService
EvsHalService
TimeHalService代码
android/packages/services/Car/service/src/com/android/car/hal/VehicleHal.javaVehicleHAL目录结构
下面是vehicle 2.0参考实现的目录结构。
android/hardware/interfaces/automotive/vehicle/2.0/
|-- default // 默认实现|-- common|-- include|-- vhal_v2_0 // .h|-- src // .cpp|-- impl|-- vhal_v2_0 // impl代码|-- proto // proto协议|-- tests|-- tests|-- Android.bp // 编译文件|-- VehicleService.cpp // main函数|-- android.hardware.automotive.vehicle2.0-service.rc // init rc|-- android.hardware.automotive.vehicle2.0-service.xml // matrix xml
|-- utils
|-- vts
|-- Android.bp // 编译文件
|-- IVehicle.hal // interface
|-- IVehicleCallback.hal // callback
|-- types.hal // typesHidl代码有个明显的namespace规则如下。
namespace android {
namespace hardware {
namespace automotive {
namespace vehicle {
namespace V2_0 {
// ...
} // namespace V2_0
} // namespace vehicle
} // namespace automotive
} // namespace hardware
} // namespace androidVehicleHAL启动流程
rc
VehicleHAL由init rc启动。 代码
android/hardware/interfaces/automotive/vehicle/2.0/default/android.hardware.automotive.vehicle2.0-service.rc
service vendor.vehicle-hal-2.0 /vendor/bin/hw/android.hardware.automotive.vehicle2.0-serviceclass early_haluser vehicle_networkgroup system inetmain
下面是VehicleHAL的main函数。 代码
android/hardware/interfaces/automotive/vehicle/2.0/default/VehicleService.cpp
int main(int /* argc */, char* /* argv */ []) {auto store std::make_uniqueVehiclePropertyStore();auto connector std::make_uniqueimpl::EmulatedVehicleConnector();auto userHal connector-getEmulatedUserHal();auto hal std::make_uniqueimpl::EmulatedVehicleHal(store.get(), connector.get(), userHal);auto emulator std::make_uniqueimpl::VehicleEmulator(hal.get());auto service std::make_uniqueVehicleHalManager(hal.get());connector-setValuePool(hal-getValuePool());
configureRpcThreadpool(4, true /* callerWillJoin */);ALOGI(Registering as service...);status_t status service-registerAsService();if (status ! OK) {ALOGE(Unable to register vehicle service (%d), status);return 1;}ALOGI(Ready);joinRpcThreadpool();return 1;
}VehiclePropertyStore存储、访问和修改vehicle相关的配置及属性VehiclePropertyValues存储在有序map中。使用了同步锁线程安全。EmulatedVehicleConnectorVehicleHalClient与VehicleHalServer通信的连接器。EmulatedUserHalUser Hal。EmulatedVehicleHalVehicle Hal。VehicleEmulatorVehicle Emulator。VehicleHalManagerThis class is a thick proxy between IVehicle HIDL interface and vendor’s implementation. 以上为车机开发技术中的CarFrameWork学习启动流程及原理介绍更多的车载技术可以前往《车机开发技术手册》查看更多车载技术。
交互
CarService向上与App通过CarLibaidl交互向下与VehicleHAL通过hidl交互其中包括了一个很重要的概念Property。 Property可以是静态的也可以是变化后向上通报的还可以是以一定的频率实时上报的。 下面以HVAC为例说明HVAC的控制过程。
【App】调用CarLib中【CarHvacManager】的setBooleanProperty设置Property。【CarHvacManager】调用CarLib中【CarPropertyManager】的setBooleanProperty。【CarPropertyManager】将Property封装成CarPropertyValue后调用CarServcie中【ICarProperty-CarPropertyService】的setProperty。aidl 【CarPropertyService】调用CarServcie中【PropertyHalService】的setProperty。【PropertyHalService】将CarPropertyValue封装成VehiclePropValue后调用CarServcie中【VehicleHal】的set。【VehicleHal】调用CarServcie中【HalClient】的setValue。【HalClient】调用VehicleHAL中【IVehicle-VehicleHalManager】的set。hidl【VehicleHalManager】首先通过订阅这个Property的【Native HalClient】的callback即【IVehicleCallback-HalClient$VehicleCallback】的onPropertySet通知Property变更。hidl callback【VehicleHalManager】然后调用【EmulatedVehicleHal】的set。【EmulatedVehicleHal】检查Property后调用【VehicleHalClient】的setProperty。【VehicleHalClient】与EmulatedVehicleConnector有关调用【EmulatedVehicleConnector】的onSetProperty。【EmulatedVehicleConnector】与VehicleHalServer有关调用【VehicleHalServer】的onSetProperty。
最终将Property或转换后的信号发到【Car ECU】。vehicle 2.0模拟实现是将Property存储到VehiclePropertyStore