Android Automotive(四) Vehicle Property

在介绍CarService之前,先介绍一下Vehicle Property(车辆属性),车辆属性是Android Automotive 中最重要的内容之一,使用它来传递车辆上的一些重要信息。

车辆属性是硬件抽象层定义的汽车设备制造商可以实现的属性,并会包含属性元数据(例如,属性是否为 int 以及允许使用哪些更改模式)。Vehicle HAL 提供接口对车辆属性进行访问(读取、写入、订阅)。

车辆属性使用HIDL语言定义,代码位于hardware/interfaces/automotive/vehicle/2.0/types.hal中。

车辆属性可以是只读、只写、也可以是读写。每个车辆属性都由一个int32键唯一标识,且具有预定义的数据类型。区域属性可能具有多个值,具体取决于属性支持区域的数量

车辆属性的定义是由四个整型值做或运算取得的。它们描述了车辆属性的ID、分组、类型和区域。

INFO_VIN = (0x0100| VehiclePropertyGroup:SYSTEM| VehiclePropertyType:STRING| VehicleArea:GLOBAL)

除了定义所需的必须属性,车辆属性的额外信息以注释的形式标记在文件中。包括车辆属性的变化类型、读写性、单位、取值的数据结构等等。

/*** VIN of vehicle** @change_mode VehiclePropertyChangeMode:STATIC* @access VehiclePropertyAccess:READ*/
INFO_VIN =

具体如下

注释 描述 类型
@change_mode 变化模式 VehiclePropertyChangeMode
STATIC 静态
ON_CHANGE 变化
CONTINUOUS 持续
@access 读写性质 VehiclePropertyAccess
READ 只读
WRITE 只写
READ_WRITE 读写
@unit 单位 VehicleUnit
@data_enum 数据结构
@since 增加的版本

属性ID

是一个int数值,通常是4位16进制,占半个字节。在车辆属性中使用“4567”后四位表示属性ID,如0x0000****。通常省略高位0,写成0x****的形式。

属性分组

分组表示了车辆属性的来源,区分是原生属性还是扩展属性。原生属性是指AOSP定义的属性,扩展属性是指OEM厂商自己定义增加的属性。在车辆属性中使用第0位占位0x*000000。

//types.hal中定义
enum VehiclePropertyGroup : int32_t {/*** Properties declared in AOSP must have this flag.*/SYSTEM         = 0x10000000, //268435456/*** Properties declared by vendors must have this flag.*/VENDOR         = 0x20000000, //536870912MASK           = 0xf0000000, //-268435456
};
  • SYSTEM:Google原生属性定义使用
  • VENDOR:OME自定义属性使用
属性 十六进制 十进制
SYSTEM 0x10000000 268435456
VENDOR 0x20000000 536870912

扩展属性必须使用VENDOR声明

属性类型

表示车辆属性对应值的数据类型,占0x00**0000第“23”位。
目前支持的数据类型如下

  • STRING
  • BOOLEAN
  • INT32
  • INT32_VEC (INT32[])
  • INT64
  • INT64_VEC (INT64[])
  • FLOAT
  • FLOAT_VEC (FLOAT[])
  • BYTES
//types.hal中定义
/*** Enumerates supported data type for VehicleProperty.** Used to create property ID in VehicleProperty enum.*/
enum VehiclePropertyType : int32_t {STRING          = 0x00100000,BOOLEAN         = 0x00200000,INT32           = 0x00400000,INT32_VEC       = 0x00410000,INT64           = 0x00500000,INT64_VEC       = 0x00510000,FLOAT           = 0x00600000,FLOAT_VEC       = 0x00610000,BYTES           = 0x00700000,/*** Any combination of scalar or vector types. The exact format must be* provided in the description of the property.** For vendor MIXED type properties, configArray needs to be formatted in this* structure.* configArray[0], 1 indicates the property has a String value* configArray[1], 1 indicates the property has a Boolean value .* configArray[2], 1 indicates the property has an Integer value.* configArray[3], the number indicates the size of Integer[] in the property.* configArray[4], 1 indicates the property has a Long value.* configArray[5], the number indicates the size of Long[] in the property.* configArray[6], 1 indicates the property has a Float value.* configArray[7], the number indicates the size of Float[] in the property.* configArray[8], the number indicates the size of byte[] in the property.* For example:* {@code configArray = {1, 1, 1, 3, 0, 0, 0, 0, 0}} indicates the property has* a String value, a Boolean value, an Integer value and an array with 3 integers.*/MIXED           = 0x00e00000,MASK            = 0x00ff0000
};
属性 十六进制 十进制
STRING 0x00100000 1048576
BOOLEAN 0x00200000 2097152
INT32 0x00400000 4194304
INT32_VEC 0x00410000 4259840
INT64 0x00500000 5242880
INT64_VEC 0x00510000 5308416
FLOAT 0x00600000 6291456
FLOAT_VEC 0x00610000 6356992
BYTES 0x00700000 7340032
MIXED 0x00e00000 14680064

属性区域

属性区域定义了车辆属性归属车辆的哪一个模块,比如门或者窗。占位0x0*000000,第1位。

Android P 删除了ZONE区域,新增WHEEL区域。

每个区域属性都必须使用预定义的区域类型。每种区域类型都有一组在区域类型的枚举中定义的位标记。

//types.hal中定义
/*** Vehicle Areas* Used to construct property IDs in the VehicleProperty enum.** Some properties may be associated with particular vehicle areas. For* example, VehicleProperty:DOOR_LOCK property must be associated with* particular door, thus this property must be marked with* VehicleArea:DOOR flag.** Other properties may not be associated with particular vehicle area.* These kinds of properties must have VehicleArea:GLOBAL flag.** [Definition] Area: An area represents a unique element of an AreaType.*   For instance, if AreaType is WINDOW, then an area may be FRONT_WINDSHIELD.** [Definition] AreaID: An AreaID is a combination of one or more areas,*   and is represented using a bitmask of Area enums. Different AreaTypes may*   not be mixed in a single AreaID. For instance, a window area cannot be*   combined with a seat area in an AreaID.** Rules for mapping a zoned property to AreaIDs:*  - A property must be mapped to an array of AreaIDs that are impacted when*    the property value changes.*  - Each element in the array must represent an AreaID, in which the*    property value can only be changed together in all the areas within*    the AreaID and never independently. That is, when the property value*    changes in one of the areas in an AreaID in the array, then it must*    automatically change in all other areas in the AreaID.*  - The property value must be independently controllable in any two*    different AreaIDs in the array.*  - An area must only appear once in the array of AreaIDs. That is, an*    area must only be part of a single AreaID in the array.** [Definition] Global Property: A property that applies to the entire car*   and is not associated with a specific area. For example, FUEL_LEVEL,*   HVAC_STEERING_WHEEL_HEAT.** Rules for mapping a global property to AreaIDs:*  - A global property must not be mapped to AreaIDs.
*/
enum VehicleArea : int32_t {GLOBAL      = 0x01000000,/** WINDOW maps to enum VehicleAreaWindow *///ZONE         = 0x02000000, //android P开始删除WINDOW      = 0x03000000,/** MIRROR maps to enum VehicleAreaMirror */MIRROR      = 0x04000000,/** SEAT maps to enum VehicleAreaSeat */SEAT        = 0x05000000,/** DOOR maps to enum VehicleAreaDoor */DOOR        = 0x06000000,/** WHEEL maps to enum VehicleAreaWheel */WHEEL       = 0x07000000,MASK        = 0x0f000000,
};
属性 十六进制 十进制
GLOBAL 0x01000000 16777216
ZONE 0x02000000 33554432
WINDOW 0x03000000 50331648
MIRROR 0x04000000 67108864
SEAT 0x05000000 83886080
DOOR 0x06000000 100663296
WHEEL 0x07000000 117440512

GLOBAL

此属性是单一实例,不具备多个区域。

ZONE

用于空调并将汽车划分为物理区域。

在Android P版本删除。使用枚举类VehicleAreaZone。Android P 开始删除此属性

//types.hal中定义
/*** Various zones in the car.** Zones are used for Air Conditioning purposes and divide the car into physical* area zones.*/
enum VehicleAreaZone : int32_t {ROW_1_LEFT = 0x00000001,ROW_1_CENTER = 0x00000002,ROW_1_RIGHT = 0x00000004,ROW_1 = 0x00000008,ROW_2_LEFT = 0x00000010,ROW_2_CENTER = 0x00000020,ROW_2_RIGHT = 0x00000040,ROW_2 = 0x00000080,ROW_3_LEFT = 0x00000100,ROW_3_CENTER = 0x00000200,ROW_3_RIGHT = 0x00000400,ROW_3 = 0x00000800,ROW_4_LEFT = 0x00001000,ROW_4_CENTER = 0x00002000,ROW_4_RIGHT = 0x00004000,ROW_4 = 0x00008000,WHOLE_CABIN = 0x80000000,
};

WINDOW

基于车窗的区域。使用枚举类VehicleAreaWindow

  • FRONT_WINDSHIELD 前挡风玻璃
  • REAR_WINDSHIELD 后挡风玻璃
  • ROW_1_LEFT 第一排左侧车窗
  • ROW_1_RIGHT 第一排右侧车窗
  • ROW_2_LEFT 第二排左侧车窗
  • ROW_2_RIGHT 第二排右侧车窗
  • ROW_3_LEFT 第三排左侧车窗
  • ROW_3_RIGHT 第三排右侧车窗
  • ROOF_TOP_1 天窗1
  • ROOF_TOP_2 天窗2
// hardware/interfaces/automotive/vehicle/2.0/types.hal
/*** Various windshields/windows in the car.*/
enum VehicleAreaWindow : int32_t {FRONT_WINDSHIELD  = 0x00000001,REAR_WINDSHIELD   = 0x00000002,ROW_1_LEFT        = 0x00000010,ROW_1_RIGHT       = 0x00000040,ROW_2_LEFT        = 0x00000100,ROW_2_RIGHT       = 0x00000400,ROW_3_LEFT        = 0x00001000,ROW_3_RIGHT       = 0x00004000,ROOF_TOP_1        = 0x00010000,ROOF_TOP_2        = 0x00020000,};
属性 十六进制 十进制
FRONT_WINDSHIELD 0x00000001 1
REAR_WINDSHIELD 0x00000002 2
ROW_1_LEFT 0x00000010 16
ROW_1_RIGHT 0x00000040 64
ROW_2_LEFT 0x00000100 256
ROW_2_RIGHT 0x00000400 1024
ROW_3_LEFT 0x00001000 4096
ROW_3_RIGHT 0x00004000 16384
ROOF_TOP_1 0x00010000 65536
ROOF_TOP_2 0x00020000 131072

MIRROR

基于车镜的区域。使用枚举类VehicleAreaMirror

  • DRIVER_LEFT 左后视镜
  • DRIVER_RIGHT 右后视镜
  • DRIVER_CENTER 中央后视镜
// hardware/interfaces/automotive/vehicle/2.0/types.hal
enum VehicleAreaMirror : int32_t {DRIVER_LEFT = 0x00000001,DRIVER_RIGHT = 0x00000002,DRIVER_CENTER = 0x00000004,
};
属性 十六进制 十进制
DRIVER_LEFT 0x00000001 1
DRIVER_RIGHT 0x00000002 2
DRIVER_CENTER 0x00000004 4

SEAT

基于座椅的区域,使用枚举类VehicleAreaSeat

  • ROW_1_LEFT 第一排左侧
  • ROW_1_CENTER 第一排中间
  • ROW_1_RIGHT 第一排右侧
  • ROW_2_LEFT 第二排左侧
  • ROW_2_CENTER 第二排中间
  • ROW_2_RIGHT 第二排右侧
  • ROW_3_LEFT 第三排左侧
  • ROW_3_CENTER 第三排中间
  • ROW_3_RIGHT 第三排右侧
// hardware/interfaces/automotive/vehicle/2.0/types.hal
/*** Various Seats in the car.*/
enum VehicleAreaSeat : int32_t {ROW_1_LEFT   = 0x0001,ROW_1_CENTER = 0x0002,ROW_1_RIGHT  = 0x0004,ROW_2_LEFT   = 0x0010,ROW_2_CENTER = 0x0020,ROW_2_RIGHT  = 0x0040,ROW_3_LEFT   = 0x0100,ROW_3_CENTER = 0x0200,ROW_3_RIGHT  = 0x0400
};
属性 十六进制 十进制
ROW_1_LEFT 0x0001 1
ROW_1_CENTER 0x0002 2
ROW_1_RIGHT 0x0004 4
ROW_2_LEFT 0x0010 16
ROW_2_CENTER 0x0020 32
ROW_2_RIGHT 0x0040 64
ROW_3_LEFT 0x0100 256
ROW_3_CENTER 0x0200 512
ROW_3_RIGHT 0x0400 1024

DOOR

基于车门的区域。使用枚举类VehicleAreaDoor

  • ROW_1_LEFT 第一排左侧门
  • ROW_1_RIGHT 第一排右侧门
  • ROW_2_LEFT 第二排左侧门
  • ROW_2_RIGHT 第二排右侧门
  • ROW_3_LEFT 第三排左侧门
  • ROW_3_RIGHT 第三排右侧门
  • HOOD 前车厢门
  • REAR 后车厢门
// hardware/interfaces/automotive/vehicle/2.0/types.hal
enum VehicleAreaDoor : int32_t {ROW_1_LEFT = 0x00000001,ROW_1_RIGHT = 0x00000004,ROW_2_LEFT = 0x00000010,ROW_2_RIGHT = 0x00000040,ROW_3_LEFT = 0x00000100,ROW_3_RIGHT = 0x00000400,HOOD = 0x10000000,REAR = 0x20000000,
};
属性 十六进制 十进制
ROW_1_LEFT 0x00000001 1
ROW_1_RIGHT 0x00000004 4
ROW_2_LEFT 0x00000010 16
ROW_2_RIGHT 0x00000040 64
ROW_3_LEFT 0x00000100 256
ROW_3_RIGHT 0x00000400 1024
HOOD 0x10000000 268435456
REAR 0x20000000 536870912

WHEEL

基于车轮的区域。使用枚举类VehicleAreaWheel

  • UNKNOWN 未知
  • LEFT_FRONT 左前轮胎
  • RIGHT_FRONT 右前轮胎
  • LEFT_REAR 左后轮胎
  • RIGHT_REAR 右后轮胎
// hardware/interfaces/automotive/vehicle/2.0/types.hal
enum VehicleAreaWheel : int32_t {UNKNOWN = 0x0,LEFT_FRONT = 0x1,RIGHT_FRONT = 0x2,LEFT_REAR = 0x4,RIGHT_REAR = 0x8,
};
属性 十六进制 十进制
UNKNOWN 0x0 0
LEFT_FRONT 0x1 1
RIGHT_FRONT 0x2 2
LEFT_REAR 0x4 4
RIGHT_REAR 0x8 8

每个区域属性都必须使用预定义的区域类型。每种区域类型都有一组在区域类型的枚举中定义的位标记

区域 ID

区域属性通过区域 ID 进行处理。每个区域属性都可以支持一个或多个区域 ID。区域 ID 由其各自枚举中的一个或多个标记组成。例如,使用 VehicleAreaSeat 的属性可能会使用以下区域 ID:

  • ROW_1_LEFT | ROW_1_RIGHT
    区域 ID 适用于两个前排座椅。
  • ROW_2_LEFT
    仅适用于左后座椅。
  • ROW_2_RIGHT
    仅适用于右后座椅。

属性操作

车辆属性的可见性标识该属性是否只读,只写,读写。在types.hal中以注释@access的形式出现
如:@access VehiclePropertyAccess::READ_WRITE

  • NONE 不可读不可写
  • READ 只读
  • WRITE 只写
  • READ_WRITE 读写
// hardware/interfaces/automotive/vehicle/2.0/types.hal
/*** Property config defines the capabilities of it. User of the API* must first get the property config to understand the output from get()* commands and also to ensure that set() or events commands are in sync with* the expected output.*/
enum VehiclePropertyAccess : int32_t {NONE = 0x00,READ = 0x01,WRITE = 0x02,READ_WRITE = 0x03,
};
属性 说明 Android版本
NONE 不可读不可写
READ 只读 8.0~
WRITE 只写 8.0~
READ_WRITE 读写 8.0~
属性 十六进制 十进制
NONE 0x00 0
READ 0x01 1
WRITE 0x02 2
READ_WRITE 0x03 3

属性变化模式

属性的变化模式,在types.hal中以注释@change_mode的形式出现

如:@change_mode VehiclePropertyChangeMode::ON_CHANGE

// hardware/interfaces/automotive/vehicle/2.0/types.hal
/*** This describes how value of property can change.*/
enum VehiclePropertyChangeMode : int32_t {/*** Property of this type must never be changed. Subscription is not supported* for these properties.*/STATIC = 0x00,/*** Property of this type must be reported when there is a change.* IVehicle#get call must return the current value.* Set operation for this property is assumed to be asynchronous. When the* property is read (using IVehicle#get) after IVehicle#set, it may still* return old value until underlying H/W backing this property has actually* changed the state. Once state is changed, the property must dispatch* changed value as event.*/ON_CHANGE = 0x01,/*** Property of this type change continuously and requires fixed rate of* sampling to retrieve the data.*/CONTINUOUS = 0x02,/*** Property of this type may be polled to get the current value.*/POLL = 0x03,/*** This is for property where change event must be sent only when the* value is set from external component. Normal value change must not trigger* event. For example, clock property can send change event only when it is* set, outside android, for case like user setting time or time getting* update. There is no need to send it per every value change.*/ON_SET = 0x04,
};
属性 说明 Android版本
STATIC 决不能更改此类型的属性。不支持订阅这些属性 8.0~
ON_CHANGE 发生改变时,必须报告此类型的属性。 IVehicle#get调用必须返回当前值。假如设置是异步的,当在IVehicle#set之后读取属性时,它可能返回旧值,直到此属性的底层H/W实际更改了状态。状态更改后,属性必须将更改的值作为事件分派。 8.0~
CONTINUOUS 此种类型的属性不断变化,需要固定的采样率来检索数据。实现者可以选择在重大值更改时发送额外的通知。如车速 8.0~
POLL 可以轮询此类型的属性以获取当前值 8.0
ON_SET 变化时不需要一直上报,只有上层主动获取才上报,比如时间更新 8.0

POLL 和 ON_SET在Android P上被删除,不再使用

属性单位

某些属性的值需要配合国际单位来表示,比如车速的单位是米每秒(MILLIMETER)。

属性值的单位, 在types.hal中以注释@unit的形式出现,表示车辆属性表示含义的单位。

如:@unit VehicleUnit:YEAR表示单位是年

// hardware/interfaces/automotive/vehicle/2.0/types.hal
/*** Units used for int or float type with no attached enum types.*/
enum VehicleUnit : int32_t {SHOULD_NOT_USE      = 0x000,METER_PER_SEC       = 0x01,RPM                 = 0x02,HERTZ               = 0x03,PERCENTILE          = 0x10,MILLIMETER          = 0x20,METER               = 0x21,KILOMETER           = 0x23,MILE                = 0x24,CELSIUS             = 0x30,FAHRENHEIT          = 0x31,KELVIN              = 0x32,MILLILITER          = 0x40,LITER               = 0x41,/** deprecated. Use US_GALLON instead. */GALLON              = 0x42,US_GALLON           = 0x42,IMPERIAL_GALLON     = 0x43,NANO_SECS           = 0x50,SECS                = 0x53,YEAR                = 0x59,// Electrical UnitsWATT_HOUR           = 0x60,MILLIAMPERE         = 0x61,MILLIVOLT           = 0x62,MILLIWATTS          = 0x63,AMPERE_HOURS        = 0x64,KILOWATT_HOUR       = 0x65,KILOPASCAL          = 0x70,PSI                 = 0x71,BAR                 = 0x72,DEGREES             = 0x80,MILES_PER_HOUR      = 0x90,KILOMETERS_PER_HOUR = 0x91,
};
  • SHOULD_NOT_USE, 不使用
  • METER_PER_SEC, 米每秒
  • RPM, 转速
  • HERTZ, 赫兹
  • PERCENTILE, 百分比
  • MILLIMETER, 毫米
  • METER, 米
  • KILOMETER, 千米,公里
  • MILE, 英里
  • CELSIUS, 摄氏度
  • FAHRENHEIT, 华氏度
  • KELVIN, 开尔文
  • MILLILITER, 毫升
  • LITER, 升
  • US_GALLON, 美国加仑
  • IMPERIAL_GALLON, 英制加仑
  • NANO_SECS, 纳秒
  • SECS, 秒
  • YEAR, 年
  • KILOPASCAL, 千帕
  • WATT_HOUR, 瓦时
  • MILLIAMPERE, 毫安
  • MILLIVOLT, 毫伏
  • MILLIWATTS, 毫瓦
  • AMPERE_HOURS, 安倍小时
  • KILOWATT_HOUR, 千瓦时
  • PSI, 磅/平方英寸
  • BAR, 巴 压强的单位
  • DEGREES, 度
  • MILES_PER_HOUR, 英里每小时
  • KILOMETERS_PER_HOUR 公里每小时

属性数据结构

某些属性,将属性的可取值封装成一个对象,这样可以方便调用,比如VehicleGear表示档位。

// hardware/interfaces/automotive/vehicle/2.0/types.hal
/*** Various gears which can be selected by user and chosen in system.*/
enum VehicleGear: int32_t {GEAR_NEUTRAL = 0x0001,GEAR_REVERSE = 0x0002,GEAR_PARK = 0x0004,GEAR_DRIVE = 0x0008,GEAR_LOW = 0x0010,GEAR_1 = 0x0010,GEAR_2 = 0x0020,GEAR_3 = 0x0040,GEAR_4 = 0x0080,GEAR_5 = 0x0100,GEAR_6 = 0x0200,GEAR_7 = 0x0400,GEAR_8 = 0x0800,GEAR_9 = 0x1000,
};

属性权限

属性的权限是Android在系统框架层增加的,只有声明权限的应用才可以访问相关的车辆属性。

属性的权限检测在CarService中,配置在PropertyHalServiceIds.java中使用,关联到各个车辆属性。

// packages/services/Car/service/src/com/android/car/hal/PropertyHalServiceIds.java
// default vendor permission
private static final int PERMISSION_CAR_VENDOR_DEFAULT = 0x00000000;// permissions for the property related with window
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_WINDOW = 0X00000001;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_WINDOW = 0x00000002;
// permissions for the property related with door
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_DOOR = 0x00000003;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_DOOR = 0x00000004;
// permissions for the property related with seat
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_SEAT = 0x00000005;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_SEAT = 0x00000006;
// permissions for the property related with mirror
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_MIRROR = 0x00000007;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_MIRROR = 0x00000008;// permissions for the property related with car's information
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_INFO = 0x00000009;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_INFO = 0x0000000A;
// permissions for the property related with car's engine
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_ENGINE = 0x0000000B;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_ENGINE = 0x0000000C;
// permissions for the property related with car's HVAC
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_HVAC = 0x0000000D;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_HVAC = 0x0000000E;
// permissions for the property related with car's light
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_LIGHT = 0x0000000F;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_LIGHT = 0x00000010;// permissions reserved for other vendor permission
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_1 = 0x00010000;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_1 = 0x00011000;
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_2 = 0x00020000;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_2 = 0x00021000;
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_3 = 0x00030000;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_3 = 0x00031000;
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_4 = 0x00040000;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_4 = 0x00041000;
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_5 = 0x00050000;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_5 = 0x00051000;
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_6 = 0x00060000;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_6 = 0x00061000;
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_7 = 0x00070000;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_7 = 0x00071000;
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_8 = 0x00080000;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_8 = 0x00081000;
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_9 = 0x00090000;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_9 = 0x00091000;
private static final int PERMISSION_SET_CAR_VENDOR_CATEGORY_10 = 0x000A0000;
private static final int PERMISSION_GET_CAR_VENDOR_CATEGORY_10 = 0x000A1000;
// Not available for android
private static final int PERMISSION_CAR_VENDOR_NOT_ACCESSIBLE = 0xF0000000;

在HAL层定义

// hardware/interfaces/automotive/vehicle/2.0/types.hal
/*** Used by SUPPORT_CUSTOMIZE_VENDOR_PERMISSION to indicate the permission of vendor properties.*/
enum VehicleVendorPermission : int32_t {PERMISSION_DEFAULT = 0x00000000,// permissions for the property related with windowPERMISSION_SET_VENDOR_CATEGORY_WINDOW= 0X00000001,PERMISSION_GET_VENDOR_CATEGORY_WINDOW = 0x00000002,// permissions for the property related with doorPERMISSION_SET_VENDOR_CATEGORY_DOOR  = 0x00000003,PERMISSION_GET_VENDOR_CATEGORY_DOOR   = 0x00000004,// permissions for the property related with seatPERMISSION_SET_VENDOR_CATEGORY_SEAT  = 0x00000005,PERMISSION_GET_VENDOR_CATEGORY_SEAT   = 0x00000006,// permissions for the property related with mirrorPERMISSION_SET_VENDOR_CATEGORY_MIRROR= 0x00000007,PERMISSION_GET_VENDOR_CATEGORY_MIRROR = 0x00000008,// permissions for the property related with car's informationPERMISSION_SET_VENDOR_CATEGORY_INFO  = 0x00000009,PERMISSION_GET_VENDOR_CATEGORY_INFO   = 0x0000000A,// permissions for the property related with car's enginePERMISSION_SET_VENDOR_CATEGORY_ENGINE= 0x0000000B,PERMISSION_GET_VENDOR_CATEGORY_ENGINE = 0x0000000C,// permissions for the property related with car's HVACPERMISSION_SET_VENDOR_CATEGORY_HVAC  = 0x0000000D,PERMISSION_GET_VENDOR_CATEGORY_HVAC   = 0x0000000E,// permissions for the property related with car's lightPERMISSION_SET_VENDOR_CATEGORY_LIGHT = 0x0000000F,PERMISSION_GET_VENDOR_CATEGORY_LIGHT  = 0x00000010,// permissions reserved for other vendor permissionPERMISSION_SET_VENDOR_CATEGORY_1  = 0x00010000,PERMISSION_GET_VENDOR_CATEGORY_1   = 0x00011000,PERMISSION_SET_VENDOR_CATEGORY_2  = 0x00020000,PERMISSION_GET_VENDOR_CATEGORY_2   = 0x00021000,PERMISSION_SET_VENDOR_CATEGORY_3  = 0x00030000,PERMISSION_GET_VENDOR_CATEGORY_3   = 0x00031000,PERMISSION_SET_VENDOR_CATEGORY_4  = 0x00040000,PERMISSION_GET_VENDOR_CATEGORY_4   = 0x00041000,PERMISSION_SET_VENDOR_CATEGORY_5  = 0x00050000,PERMISSION_GET_VENDOR_CATEGORY_5   = 0x00051000,PERMISSION_SET_VENDOR_CATEGORY_6  = 0x00060000,PERMISSION_GET_VENDOR_CATEGORY_6   = 0x00061000,PERMISSION_SET_VENDOR_CATEGORY_7  = 0x00070000,PERMISSION_GET_VENDOR_CATEGORY_7   = 0x00071000,PERMISSION_SET_VENDOR_CATEGORY_8  = 0x00080000,PERMISSION_GET_VENDOR_CATEGORY_8   = 0x00081000,PERMISSION_SET_VENDOR_CATEGORY_9  = 0x00090000,PERMISSION_GET_VENDOR_CATEGORY_9   = 0x00091000,PERMISSION_SET_VENDOR_CATEGORY_10 = 0x000A0000,PERMISSION_GET_VENDOR_CATEGORY_10  = 0x000A1000,// Indicate not available for android to access.PERMISSION_NOT_ACCESSIBLE = 0xF0000000
};

在Framework中VehicleVendorPermission定义了应用使用的权限字符串。

// packages/services/Car/car-lib/src/android/car/hardware/property/VehicleVendorPermission.java
// permissions for the property related with window
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_WINDOW ="android.car.permission.GET_CAR_VENDOR_CATEGORY_WINDOW";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_WINDOW ="android.car.permission.SET_CAR_VENDOR_CATEGORY_WINDOW";// permissions for the property related with door
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_DOOR ="android.car.permission.GET_CAR_VENDOR_CATEGORY_DOOR";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_DOOR ="android.car.permission.SET_CAR_VENDOR_CATEGORY_DOOR";// permissions for the property related with seat
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_SEAT ="android.car.permission.GET_CAR_VENDOR_CATEGORY_SEAT";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_SEAT ="android.car.permission.SET_CAR_VENDOR_CATEGORY_SEAT";// permissions for the property related with mirror
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_MIRROR ="android.car.permission.GET_CAR_VENDOR_CATEGORY_MIRROR";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_MIRROR ="android.car.permission.SET_CAR_VENDOR_CATEGORY_MIRROR";// permissions for the property related with car's information
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_INFO ="android.car.permission.GET_CAR_VENDOR_CATEGORY_INFO";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_INFO ="android.car.permission.SET_CAR_VENDOR_CATEGORY_INFO";// permissions for the property related with car's engine
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_ENGINE ="android.car.permission.GET_CAR_VENDOR_CATEGORY_ENGINE";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_ENGINE ="android.car.permission.SET_CAR_VENDOR_CATEGORY_ENGINE";// permissions for the property related with car's HVAC
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_HVAC ="android.car.permission.GET_CAR_VENDOR_CATEGORY_HVAC";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_HVAC ="android.car.permission.SET_CAR_VENDOR_CATEGORY_HVAC";// permissions for the property related with car's light
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_LIGHT ="android.car.permission.GET_CAR_VENDOR_CATEGORY_LIGHT";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_LIGHT ="android.car.permission.SET_CAR_VENDOR_CATEGORY_LIGHT";// permissions reserved for other vendor permission
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_1 ="android.car.permission.GET_CAR_VENDOR_CATEGORY_1";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_1 ="android.car.permission.SET_CAR_VENDOR_CATEGORY_1";
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_2 ="android.car.permission.GET_CAR_VENDOR_CATEGORY_2";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_2 ="android.car.permission.SET_CAR_VENDOR_CATEGORY_2";
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_3 ="android.car.permission.GET_CAR_VENDOR_CATEGORY_3";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_3 ="android.car.permission.SET_CAR_VENDOR_CATEGORY_3";
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_4 ="android.car.permission.GET_CAR_VENDOR_CATEGORY_4";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_4 ="android.car.permission.SET_CAR_VENDOR_CATEGORY_4";
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_5 ="android.car.permission.GET_CAR_VENDOR_CATEGORY_5";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_5 ="android.car.permission.SET_CAR_VENDOR_CATEGORY_5";
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_6 ="android.car.permission.GET_CAR_VENDOR_CATEGORY_6";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_6 ="android.car.permission.SET_CAR_VENDOR_CATEGORY_6";
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_7 ="android.car.permission.GET_CAR_VENDOR_CATEGORY_7";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_7 ="android.car.permission.SET_CAR_VENDOR_CATEGORY_7";
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_8 ="android.car.permission.GET_CAR_VENDOR_CATEGORY_8";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_8 ="android.car.permission.SET_CAR_VENDOR_CATEGORY_8";
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_9 ="android.car.permission.GET_CAR_VENDOR_CATEGORY_9";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_9 ="android.car.permission.SET_CAR_VENDOR_CATEGORY_9";
public static final String PERMISSION_GET_CAR_VENDOR_CATEGORY_10 ="android.car.permission.GET_CAR_VENDOR_CATEGORY_10";
public static final String PERMISSION_SET_CAR_VENDOR_CATEGORY_10 ="android.car.permission.SET_CAR_VENDOR_CATEGORY_10";

属性状态

每个属性值都随附一个 VehiclePropertyStatus 值。该值指示相应属性的当前状态:

  • AVAILABLE
    属性可用,且值有效。
  • UNAVAILABLE
    属性值目前不可用。该值用于受支持属性的暂时停用的功能。
  • ERROR
    该属性有问题。

如果车辆不支持某个属性,则不应将其包含在 VHAL 中。您不得将属性状态永久性设置为 UNAVAILABLE 来表示不受支持的属性。

配置属性

在硬件抽象层会用一个VehiclePropConfig结构体来维护车辆属性的配置。

// hardware/interfaces/automotive/vehicle/2.0/types.hal
struct VehiclePropConfig {/** Property identifier */int32_t prop;/*** Defines if the property is read or write or both.*/VehiclePropertyAccess access;/*** Defines the change mode of the property.*/VehiclePropertyChangeMode changeMode;/*** Contains per-area configuration.*/vec<VehicleAreaConfig> areaConfigs;/** Contains additional configuration parameters */vec<int32_t> configArray;/*** Some properties may require additional information passed over this* string. Most properties do not need to set this.*/string configString;/*** Min sample rate in Hz.* Must be defined for VehiclePropertyChangeMode::CONTINUOUS*/float minSampleRate;/*** Must be defined for VehiclePropertyChangeMode::CONTINUOUS* Max sample rate in Hz.*/float maxSampleRate;
};
  • prop 属性ID
  • access 属性读写权限
  • changeMode 属性变化模式
  • areaConfigs 属性每个区域的配置
  • configArray 配置相关的数组
  • configString 配置的描述
  • minSampleRate 最小的变化频率,通知频率,变化模式必须定义为CONTINUOUS
  • maxSampleRate 最大的变化频率,通知频率,变化模式必须定义为CONTINUOUS
字段 描述
prop 属性ID
access 属性读写权限
changeMode 属性变化模式
areaConfigs 属性每个区域的配置
configArray 配置相关的数组
configString 配置的描述
minSampleRate 最小的变化频率,通知频率,变化模式必须定义为CONTINUOUS
maxSampleRate 最大的变化频率,通知频率,变化模式必须定义为CONTINUOUS

在Android N上使用 vehicle_prop_config_t 进行配置

使用 vehicle_prop_config_t 为每个属性提供配置信息。具体信息包括:

  • access(r、w、rw)
  • changeMode(表示监视属性的方式:变化模式还是连续模式)
  • areaConfigs(areaId、最小值和最大值)
  • configArray(其他配置参数)
  • configString(以字符串的形式传递的其他信息)
  • minSampleRatemax_sample_rate
  • prop(属性 ID、int)

属性取值

属性的取值,也就是属性所带的数据使用VehiclePropValue来维护。在types.hal中定义。

// hardware/interfaces/automotive/vehicle/2.0/types.hal
/*** Encapsulates the property name and the associated value. It* is used across various API calls to set values, get values or to register for* events.*/
struct VehiclePropValue {/** Time is elapsed nanoseconds since boot */int64_t timestamp;/*** Area type(s) for non-global property it must be one of the value from* VehicleArea* enums or 0 for global properties.*/int32_t areaId;/** Property identifier */int32_t prop;/** Status of the property */VehiclePropertyStatus status;/*** Contains value for a single property. Depending on property data type of* this property (VehiclePropetyType) one field of this structure must be filled in.*/struct RawValue {/*** This is used for properties of types VehiclePropertyType#INT* and VehiclePropertyType#INT_VEC*/vec<int32_t> int32Values;/*** This is used for properties of types VehiclePropertyType#FLOAT* and VehiclePropertyType#FLOAT_VEC*/vec<float> floatValues;/** This is used for properties of type VehiclePropertyType#INT64 */vec<int64_t> int64Values;/** This is used for properties of type VehiclePropertyType#BYTES */vec<uint8_t> bytes;/** This is used for properties of type VehiclePropertyType#STRING */string stringValue;};RawValue value;
};
字段` 描述
timestamp 时间戳,标记属性更新的时间
areaId 表示的区域
prop 属性ID
status 属性的状态
value 用RawValue来维护具体的属性值
int32Values 维护整型数据的数组,布尔类型也是用此维护
int64Values 维护长整型数据的数组
floatValues 维护浮点型数据的数组
bytes 维护字节型数据的数组
stringValue 维护字符串类型

常量接口

前面我们知道HAL文件是使用HIDL语言定义,它在编译时,会生成C++和JAVA接口。

typs.hal也是一样,里面定义的车辆属性会编译出系统框架层和硬件抽象层使用的接口。

编译产物

源码下automotive生成的文件如下:

代码路径:out/soong/.intermediates/hardware/interfaces/automotive/vehicle/2.0

out/soong/.intermediates/hardware/interfaces/automotive/vehicle/2.0
├── android.hardware.automotive.vehicle@2.0
│   ├── android_arm64_armv8-a_core_shared
│   │   └── android.hardware.automotive.vehicle@2.0.so
│   ├── android_arm64_armv8-a_core_static
│   │   ├── android.hardware.automotive.vehicle@2.0.a
│   │   └── obj
│   ├── android_arm_armv7-a-neon_cortex-a9_core_shared
│   │   └── android.hardware.automotive.vehicle@2.0.so
│   └── android_arm_armv7-a-neon_cortex-a9_core_static
│       ├── android.hardware.automotive.vehicle@2.0.a
│       └── obj
├── android.hardware.automotive.vehicle@2.0_genc++
│   └── gen
│       └── android
├── android.hardware.automotive.vehicle@2.0_genc++_headers
│   └── gen
│       └── android
├── android.hardware.automotive.vehicle-V2.0-java
│   └── android_common
│       ├── combined
│       ├── javac
│       ├── turbine
│       └── turbine-combined
└── android.hardware.automotive.vehicle-V2.0-java_gen_java└── gen└── android

hidl-gen

hidl-gen时编译HIDL文件的一个工具

工具路径 out/host/linux-x86/bin/hidl-gen,源代码路径 system/tools/hidl

使用说明

usage: hidl-gen [-p <root path>] -o <output path> -L <language> [-O <owner>] (-r <interface root>)+ [-v] [-d <depfile>] FQNAME...Process FQNAME, PACKAGE(.SUBPACKAGE)*@[0-9]+.[0-9]+(::TYPE)?, to create output.-h: Prints this menu.-L <language>: The following options are available:check           : Parses the interface to see if valid but doesn't write any files.c++             : (internal) (deprecated) Generates C++ interface files for talking to HIDL interfaces.c++-headers     : (internal) Generates C++ headers for interface files for talking to HIDL interfaces.c++-sources     : (internal) Generates C++ sources for interface files for talking to HIDL interfaces.export-header   : Generates a header file from @export enumerations to help maintain legacy code.c++-impl        : Generates boilerplate implementation of a hidl interface in C++ (for convenience).c++-impl-headers: c++-impl but headers onlyc++-impl-sources: c++-impl but sources onlyc++-adapter     : Takes a x.(y+n) interface and mocks an x.y interface.c++-adapter-headers: c++-adapter but helper headers onlyc++-adapter-sources: c++-adapter but helper sources onlyc++-adapter-main: c++-adapter but the adapter binary source onlyjava            : (internal) Generates Java library for talking to HIDL interfaces in Java.java-constants  : (internal) Like export-header but for Java (always created by -Lmakefile if @export exists).vts             : (internal) Generates vts proto files for use in vtsd.makefile        : (removed) Used to generate makefiles for -Ljava and -Ljava-constants.androidbp       : (internal) Generates Soong bp files for -Lc++-headers, -Lc++-sources, -Ljava, -Ljava-constants, and -Lc++-adapter.androidbp-impl  : Generates boilerplate bp files for implementation created with -Lc++-impl.hash            : Prints hashes of interface in `current.txt` format to standard out.-O <owner>: The owner of the module for -Landroidbp(-impl)?.-o <output path>: Location to output files.-p <root path>: Android build root, defaults to $ANDROID_BUILD_TOP or pwd.-r <package:path root>: E.g., android.hardware:hardware/interfaces.-v: verbose output.-d <depfile>: location of depfile to write to.

hidl-gen 工具会将hal文件转换为相应的类文件, 例:

启动环境

. build/envsetup.sh
lunch

命令

./out/host/linux-x86/bin/hidl-gen -o ./demo -Ljava -randroid.hardware:hardware/interfaces  -randroid.hidl:system/libhidl/transport android.hardware.automotive.vehicle@2.0

说明

-o: 生成文件的目录
-Lc+±headers: 生成c++ 头文件
-Ljava : 生成java文件
-r:指定包号和root路径

Android Automotive(四) Vehicle Property相关推荐

  1. Android车载嵌入式操作系统(Android Automotive)

    摘要: 大家最熟悉的Android系统应该是手机和平板设备上的,大部分人可能没想过Android系统和汽车有什么关系.但实际上,Android系统在四年前就在布局汽车这个平台.我最近对相关内容做了一些 ...

  2. Android Automotive车载嵌入式系统

    一.Android Auto Android Auto是一个Android端的App,是专门为驾驶环境而设计的,把手机的部分功能通过数据线连接,影射到汽车屏幕上.目前,支持Android Auto的应 ...

  3. 车载应用技术——Android Automotive系统

    黄金赛道 在智能手机行业初兴起时,包括BAT在内许多传统互联网企业都曾布局手机产业,但是随着手机市场的基本定型,造车似乎又成了各大资本下一个追逐的方向.百度.小米先后宣布造车,阿里巴巴则与上汽集团共同 ...

  4. Android Automotive(五) CarService

    Android Automotive(五) CarService CarService是Android Automotive在系统框架层的核心服务.它类似SystemServer在服务内部管理着数十个 ...

  5. Android Automotive (二)系统架构

    Android Automotive (二)系统架构 前面简单介绍了一下Android Automotive 的架构,具体Android Automotive 在系统的每个层,都做了哪些东西,这里总结 ...

  6. [原创] Android Automotive 车载应用对驾驶模式(Safe Drive Mode)适配的几种方法

    目录 前言 开发环境 1. Android Automotive 和 Android Auto的区别 Android Auto: 2. Android Automotive 的驾驶模式介绍 3. An ...

  7. 【Android Camera开发】Android Automotive介绍

    什么是Android Automotive Android Automotive 是一个基本 Android 平台车载信息娱乐系统,简称IVI(In-Vehicle Infotainment). An ...

  8. 【车载开发】Android Automotive车载操作系统开发解密篇

    提到Android车载,我们应该都不陌生.传统的车载功能单一,无太多娱乐性,而随着智能化时代的发展,车载系统也被赋予了在系统中预装 Android 应用的能力,基于Android平台的车载信息娱乐系统 ...

  9. Android Automotive OS在国内车载系统市场能分到多大一杯羹?

    前言: 随着汽车智能化趋势的进一步发展,车载系统越来越得到各大汽车厂商的重视,同时也涌入了一批互联网企业加入,甚至很多汽车厂商直接使用Android车载系统来打造自己的车机系统,比如宝马在今年宣布将在 ...

最新文章

  1. 云计算和云存储IBM教程
  2. java拉姆达表达式事例,Java Lambda表达式详解和实例
  3. TOJ 4095: love168yk的选美大赛
  4. 字符串的方法、注释及示例1.
  5. rowspan和colspan用法详解
  6. 系统实施基础:系统实施的相关知识介绍
  7. jbod ugood 磁盘驱动状态_如何检查Mac磁盘空间,mac磁盘空间其他怎么清理
  8. linux 进程通信 pipe
  9. 解决PhoneGap在Android手机上的全屏问题
  10. java异常处理机制_Java的异常处理机制
  11. 重装操作系统时遇到的一些问题的解决方法总结
  12. pygame系列文章
  13. 台式计算机如何上无线网络,台式电脑如何实现无线上网
  14. 【203】SSL证书常见格式转换
  15. 数据库的数据文件和日志文件
  16. excel中如何将内容分成几列?speedoffice告诉你
  17. 世唐科技:秒懂什么是区块链
  18. Davinci DM6446开发攻略——DSP开发工程建立
  19. 20230407 定时闹钟
  20. proxifier 出现错误代码10060处理

热门文章

  1. 闲聊linux中的input设备(转)
  2. 【100天精通python】Day1:python入门_初识python,搭建python环境,运行第一个python小程序
  3. Python 基础(一):初识 Python
  4. 软件工程原理及方法学习随笔——第一次阅读作业
  5. 安装NVIDIA驱动的一些新问题
  6. open-falcon监控系统组件学习之——judge组件
  7. Stem教育课程模式是有机地整合
  8. 电脑系统错误怎么办?您可以看看这5个方法!
  9. 计算机网络基础实验三—DHCP服务器的配置和管理
  10. 分享一组制作游戏用的人物立绘/角色形象素材图片,共21张图片