AndroidO前期预研之三:AndroidVehicleHAL

更新时间:2023-05-23 15:11:27 阅读: 评论:0

AndroidO前期预研之三:AndroidVehicleHAL
Android Automotive
Android Automotive 是Android Oreo中的⼀个新的特⾊功能,从AOSP的代码上来看,Android O中已经包含有了从Application到Framework 到HAL的整体框架,这⼀章节,我们简单的过以下Android Vehicle 的框架,以及重点看下 Vehicle HAL的东西。总体结构⼤约是以下这个样⼦:
上图的结构应该是Android Oreo当中⽐较通⽤的框架结构了,从Application 到Framework到HAL,跟之前的Android版本相⽐,之前Framework要不通过binder联系上⼀个Daemon,这个Daemon再去load 相关的HAL,要不就是这些Framework的rvice直接通过JNI去load 这些个HAL 库。⽽现在的Android Oreo则是Framework 与HAL之间直接采⽤HIDL来做联络沟通了。接下来我们从下往上的来把Android Vehicle的框架捋⼀下吧。⾸先来分析下Vehicle HAL,通过这个来复习并且实践下之前研究学习过的Android HIDL.
Android Vehicle HAL
types.hal 定义的是⼀些数据结构,IVehicle.hal定义的是从Framework往HAL调⽤的接⼝,⽽IVehicleCallback.hal则是HAL往Framework 上报回调的接⼝。看起来还是挺清晰的吧。
⽽IVehicle.hal的接⼝也不是很多,
package android.hardware.automotive.vehicle@2.0;
import IVehicleCallback;
interface IVehicle {
/**
* Returns a list of all property configurations supported by this vehicle
* HAL.
*/
getAllPropConfigs() generates (vec<VehiclePropConfig> propConfigs);
/**
* Returns a list of property configurations for given properties.
*
* If requested VehicleProperty wasn't found it must return
* StatusCode::INVALID_ARG, otherwi a list of vehicle property
* configurations with StatusCode::OK
*/
getPropConfigs(vec<int32_t> props)
捎怎么组词
generates (StatusCode status, vec<VehiclePropConfig> propConfigs);
/**
* Get a vehicle property value.
*
* For VehiclePropertyChangeMode::STATIC properties, this method must always
* return the same value always.
* For VehiclePropertyChangeMode::ON_CHANGE properties, it must return the
* latest available value.
* latest available value.
*
* Some properties like AUDIO_VOLUME requires to pass additional data in
* GET request in VehiclePropValue object.
*
* If there is no data available yet, which can happen during initial stage,
* this call must return immediately with an error code of
* StatusCode::TRY_AGAIN.
*/
get(VehiclePropValue requestedPropValue)
generates (StatusCode status, VehiclePropValue propValue);
/**
* Set a vehicle property value.
*
* Timestamp of data must be ignored for t operation.
*
* Setting some properties require having initial state available. If initial
* data is not available yet this call must return StatusCode::TRY_AGAIN.
* For a property with parate power control this call must return
* StatusCode::NOT_AVAILABLE error if property is not powered on.
*/
t(VehiclePropValue propValue) generates (StatusCode status);
/**
* Subscribes to property events.
*
* Clients must be able to subscribe to multiple properties at a time
艳照门主角* depending on data provided in options argument.
*
* @param listener This client must be called on appropriate event.
* @param options List of options to subscribe. SubscribeOption contains
*                information such as property Id, area Id, sample rate, etc.
*/
subscribe(IVehicleCallback callback, vec<SubscribeOptions> options)
generates (StatusCode status);
/
**
* Unsubscribes from property events.
*
* If this client wasn't subscribed to the given property, this method
情绪是什么* must return StatusCode::INVALID_ARG.
*/
unsubscribe(IVehicleCallback callback, int32_t propId)
generates (StatusCode status);
/**
* Print out debugging state for the vehicle hal.
*
* The text must be in ASCII encoding only.
*
* Performance requirements:
*
* The HAL must return from this call in less than 10ms. This call must avoid    * deadlocks, as it may be called at any point of operation. Any synchronization    * primitives ud (such as mutex locks or maphores) must be acquired
* with a timeout.
*
*/
debugDump() generates (string s);
};
⽽IVehicle.hal则就更少了:
package android.hardware.automotive.vehicle@2.0;
interface IVehicleCallback {
/**
* Event callback happens whenever a variable that the API ur has
* subscribed to needs to be reported. This may be bad purely on
* threshold and frequency (a regular subscription, e subscribe call's
* arguments) or when the IVehicle#t method was called and the actual
* change needs to be reported.
*
* The callbacks are chunked.
*
* @param values that has been updated.
*/
oneway onPropertyEvent(vec<VehiclePropValue> propValues);
/**
* This method gets called if the client was subscribed to a property using
* SubscribeFlags::SET_CALL flag and IVehicle#t(...) method was called.
*
* The events must be delivered to subscriber immediately without any
* batching.
*
* @param value Value that was t by a client.
*/
oneway onPropertySet(VehiclePropValue propValue);
/**
* Set property value is usually asynchronous operation. Thus even if
* client received StatusCode::OK from the IVehicle::t(...) this
* doesn't guarantee that the value was successfully propagated to the
* vehicle network. If such rare event occurs this method must be called.
*
* @param errorCode - any value from StatusCode enum.
* @param property - a property where error has happened.
* @param areaId - bitmask that specifies in which areas the problem has
*                occurred, must be 0 for global properties
*/
oneway onPropertySetError(StatusCode errorCode,
int32_t propId,
int32_t areaId);
};
⽐较好奇的是这么些接⼝就能实现Android 车机的这么些功能?先还是这么看看吧,后续仔细研究研究。
Android Vehicle HAL 的编译
按照我们之前的研究来看看这么些Android Vehicle HAL被怎么编译,编译成什么东西。先看.hal⽂件编译⽣成的头⽂件:
.hal ⽂件⽣成的CPP⽂件:
.h ⽂件我们之前也都做过分析,Bp/Bn/Bs 代表啥意思相信都没忘记吧,在这⾥就不多赘述了,⽽
VehicleAll.cpp/VehicleCallbackAll.cpp ⾥其实就是那些⽣成的.h⽂件中所定义的C++ Class ⽂件的实现,这些相关实现都是写在这些.cpp⽂件当中。
这些.cpp⽂件/.h⽂件最终会⽣成⼀个名叫android.hardware.automotive.vehicle@2.0.so的库,详情请参考
hardware/interfaces/automotive/vehicle/2.0/Android.bp。
另外参考hardware/interfaces/automotive/vehicle/2.0/default/Android.mk,
hardware/interfaces/automotive/vehicle/2.0/default/impl/⽬录下会被编译出名叫android.hardware.automotive.vehicle@2.0-default-impl-lib的静态库,⽽hardware/interfaces/automoti
ve/vehicle/2.0/default/common/⽬录会被编译出⼀个名叫android.hardware.automotive.vehicle@2.0-manager-lib-shared的静态库,⽽这两个静态库都会去链接上⾯⽣成的
android.hardware.automotive.vehicle@2.0.so动态库。
⽽最终会被编译成⼀个可执⾏程序:
include $(CLEAR_VARS)
LOCAL_MODULE := $(vhal_v2_0)-rvice
LOCAL_INIT_RC := $(vhal_v2_0)-
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
VehicleService.cpp
LOCAL_SHARED_LIBRARIES := \
libba \
libhidlba \
libhidltransport \
liblog \
libprotobuf-cpp-lite \
libutils \
$(vhal_v2_0) \
商旅不行
LOCAL_STATIC_LIBRARIES := \
$(vhal_v2_0)-manager-lib \
$(vhal_v2_0)-default-impl-lib \
$(vhal_v2_0)-libproto-native \
LOCAL_CFLAGS += -Wall -Wextra -Werror
include $(BUILD_EXECUTABLE)
⽽这个可执⾏程序会被Init 系统在开机的时候启动,成为⼀个Daemon:
日蚀号游艇rvice vehicle-hal-2.0 /vendor/bin/hw/android.hardware.automotive.vehicle@2.0-rvice
class hal
日霜ur vehicle_network
group system inet
Android Vehicle HAL 的使⽤
东西都编译出来后,我们看看Vehicle HAL怎么来使⽤。
1) Android Vehicle HAL Service 端使⽤:
我们来看下hardware/interfaces/automotive/vehicle/2.0/default/VehicleService.cpp⽂件:
int main(int /* argc */, char* /* argv */ []) {
auto store = std::make_unique<VehiclePropertyStore>();
auto hal = std::make_unique<impl::EmulatedVehicleHal>(());
auto emulator = std::make_unique<impl::VehicleEmulator>(());
auto rvice = std::make_unique<VehicleHalManager>(());
configureRpcThreadpool(4, true /* callerWillJoin */);
ALOGI("Registering ");
rvice->registerAsService();
ALOGI("Ready");
joinRpcThreadpool();
}
说实话,刚看到这段代码的我是⼀脸懵逼的,auto是个什么⿁, std::make_unique是个什么⿁,这⼏年弄的都是JAVA/Android,像这些
C++的新规范,新东西越来越层出不穷了,真的是⼀天不学习就得落伍了哈。
幸亏这个也很简单, std::make_unique就先等同与new吧,auto的意思就是变量类型在声明的时候先不确定,等变量被定义的时候根据实
际情况来确定变量类型。于丹现状
其中最关键的是这两句:
auto rvice = std::make_unique<VehicleHalManager>(());
ALOGI("Registering ");
小孩口臭怎么办rvice->registerAsService();
我们看下 VehicleHalManager的定义:
class VehicleHalManager : public IVehicle
VehicleHalManager类是由 IVehicle类派⽣出来,⽽IVehicle则是从我们上⾯介绍的.hal⽂件⾥编译出来的。
我们继续来看下下⾯这句:
rvice->registerAsService();
我们从.hal⽂件编译出来的.cpp⽂件来看下,这个中间⽣成的cpp⽂件所在⽬录为:
out/soong/.intermediates/hardware/interfaces/automotive/vehicle/2.0/android.hardware.automotive.vehicle@2.0_genc++/gen/and
该函数的具体实现为:

本文发布于:2023-05-23 15:11:27,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/925228.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:编译   实现   时候   研究   变量   东西   框架
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图