CarPropertyManager

public class CarPropertyManager
extends Object

java.lang.Object
   ↳ android.car.hardware.property.CarPropertyManager


Provides an application interface for interacting with the Vehicle specific properties. For details about the individual properties, see the descriptions in VehiclePropertyIds

Summary

Nested classes

interface CarPropertyManager.CarPropertyEventCallback

Application registers CarPropertyEventCallback object to receive updates and changes to subscribed Vehicle specific properties. 

Constants

int CAR_SET_PROPERTY_ERROR_CODE_ACCESS_DENIED

Status to indicate that set operation failed because car denied access to the property.

int CAR_SET_PROPERTY_ERROR_CODE_INVALID_ARG

Status to indicate that set operation failed because of an invalid argument.

int CAR_SET_PROPERTY_ERROR_CODE_PROPERTY_NOT_AVAILABLE

Status to indicate that set operation failed because the property is not available.

int CAR_SET_PROPERTY_ERROR_CODE_TRY_AGAIN

Status to indicate that set operation failed.

int CAR_SET_PROPERTY_ERROR_CODE_UNKNOWN

Status to indicate that set operation failed because of an general error in cars.

float SENSOR_RATE_FAST

Read sensors at the rate of 10 hertz

float SENSOR_RATE_FASTEST

Read sensors at the rate of 100 hertz

float SENSOR_RATE_NORMAL

Read sensors at the rate of 1 hertz

float SENSOR_RATE_ONCHANGE

Read ONCHANGE sensors.

float SENSOR_RATE_UI

Read sensors at the rate of 5 hertz

Public methods

int getAreaId(int propId, int area)

Returns areaId contains the selected area for the property.

boolean getBooleanProperty(int prop, int area)

Returns value of a bool property

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

CarPropertyConfig<?> getCarPropertyConfig(int propId)

Get CarPropertyConfig by property ID.

float getFloatProperty(int prop, int area)

Returns value of a float property

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

int[] getIntArrayProperty(int prop, int area)

Returns value of an integer array property

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

int getIntProperty(int prop, int area)

Returns value of an integer property

This method may take couple seconds to complete, so it needs to be called form an non-main thread.

<E> CarPropertyValue<E> getProperty(Class<E> clazz, int propId, int areaId)

Return CarPropertyValue

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

<E> CarPropertyValue<E> getProperty(int propId, int areaId)

Query CarPropertyValue with property id and areaId.

List<CarPropertyConfig> getPropertyList(ArraySet<Integer> propertyIds)
List<CarPropertyConfig> getPropertyList()
boolean isPropertyAvailable(int propId, int area)

Check whether a given property is available or disabled based on the car's current state.

boolean registerCallback(CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback, int propertyId, float updateRateHz)

Register CarPropertyEventCallback to get property updates.

void setBooleanProperty(int prop, int areaId, boolean val)

Modifies a property.

void setFloatProperty(int prop, int areaId, float val)

Set float value of property

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

void setIntProperty(int prop, int areaId, int val)

Set int value of property

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

<E> void setProperty(Class<E> clazz, int propId, int areaId, E val)

Set value of car property by areaId.

void unregisterCallback(CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Stop getting property updates for the given CarPropertyEventCallback.

void unregisterCallback(CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback, int propertyId)

Stop getting update for propertyId to the given CarPropertyEventCallback.

Inherited methods

Constants

CAR_SET_PROPERTY_ERROR_CODE_ACCESS_DENIED

Added in API level 30
public static final int CAR_SET_PROPERTY_ERROR_CODE_ACCESS_DENIED

Status to indicate that set operation failed because car denied access to the property.

Constant Value: 4 (0x00000004)

CAR_SET_PROPERTY_ERROR_CODE_INVALID_ARG

Added in API level 30
public static final int CAR_SET_PROPERTY_ERROR_CODE_INVALID_ARG

Status to indicate that set operation failed because of an invalid argument.

Constant Value: 2 (0x00000002)

CAR_SET_PROPERTY_ERROR_CODE_PROPERTY_NOT_AVAILABLE

Added in API level 30
public static final int CAR_SET_PROPERTY_ERROR_CODE_PROPERTY_NOT_AVAILABLE

Status to indicate that set operation failed because the property is not available.

Constant Value: 3 (0x00000003)

CAR_SET_PROPERTY_ERROR_CODE_TRY_AGAIN

Added in API level 30
public static final int CAR_SET_PROPERTY_ERROR_CODE_TRY_AGAIN

Status to indicate that set operation failed. Try it again.

Constant Value: 1 (0x00000001)

CAR_SET_PROPERTY_ERROR_CODE_UNKNOWN

Added in API level 30
public static final int CAR_SET_PROPERTY_ERROR_CODE_UNKNOWN

Status to indicate that set operation failed because of an general error in cars.

Constant Value: 5 (0x00000005)

SENSOR_RATE_FAST

Added in API level 29
public static final float SENSOR_RATE_FAST

Read sensors at the rate of 10 hertz

Constant Value: 10.0

SENSOR_RATE_FASTEST

Added in API level 29
public static final float SENSOR_RATE_FASTEST

Read sensors at the rate of 100 hertz

Constant Value: 100.0

SENSOR_RATE_NORMAL

Added in API level 29
public static final float SENSOR_RATE_NORMAL

Read sensors at the rate of 1 hertz

Constant Value: 1.0

SENSOR_RATE_ONCHANGE

Added in API level 29
public static final float SENSOR_RATE_ONCHANGE

Read ONCHANGE sensors.

Constant Value: 0.0

SENSOR_RATE_UI

Added in API level 29
public static final float SENSOR_RATE_UI

Read sensors at the rate of 5 hertz

Constant Value: 5.0

Public methods

getAreaId

Added in API level 30
public int getAreaId (int propId, 
                int area)

Returns areaId contains the selected area for the property.

Parameters
propId int: Property ID

area int: Area enum such as Enums in VehicleAreaSeat.

Returns
int the AreaId containing the selected area for the property

Throws
IllegalArgumentException if the property is not available in the vehicle for the selected area.

getBooleanProperty

Added in API level 29
public boolean getBooleanProperty (int prop, 
                int area)

Returns value of a bool property

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

Clients that declare a ApplicationInfo.targetSdkVersion equal or later than Build.VERSION_CODES#R will receive the following exceptions when request is failed.

Clients that declare a ApplicationInfo.targetSdkVersion earlier than Build.VERSION_CODES#R will receive the following exceptions if the call fails.

Parameters
prop int: Property ID to get

area int: Area of the property to get

Returns
boolean value of a bool property, false if can not get value from cars.

Throws
android.car.hardware.property.CarInternalErrorException CarInternalErrorException} when there is an error detected in cars.
android.car.hardware.property.PropertyAccessDeniedSecurityException PropertyAccessDeniedSecurityException} when cars denied the access of the property.
android.car.hardware.property.PropertyNotAvailableAndRetryException PropertyNotAvailableAndRetryException} when the property is temporarily not available and likely that retrying will be successful.
android.car.hardware.property.PropertyNotAvailableException PropertyNotAvailableException} when the property is temporarily not available.
java.lang.IllegalArgumentException IllegalArgumentException} when the property in the areaId is not supplied.

getCarPropertyConfig

Added in API level 30
public CarPropertyConfig<?> getCarPropertyConfig (int propId)

Get CarPropertyConfig by property ID.

Parameters
propId int: Property ID

Returns
CarPropertyConfig<?> CarPropertyConfig for the selected property. Null if the property is not available.

getFloatProperty

Added in API level 29
public float getFloatProperty (int prop, 
                int area)

Returns value of a float property

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

This method has the same exception behavior as getBooleanProperty(int, int).

Parameters
prop int: Property ID to get

area int: Area of the property to get

Returns
float value of a float property, 0 if can not get value from the cars.

Throws
android.car.hardware.property.CarInternalErrorException CarInternalErrorException} when there is an error detected in cars.
android.car.hardware.property.PropertyAccessDeniedSecurityException PropertyAccessDeniedSecurityException} when cars denied the access of the property.
android.car.hardware.property.PropertyNotAvailableAndRetryException PropertyNotAvailableAndRetryException} when the property is temporarily not available and likely that retrying will be successful.
android.car.hardware.property.PropertyNotAvailableException PropertyNotAvailableException} when the property is temporarily not available.
java.lang.IllegalArgumentException IllegalArgumentException} when the property in the areaId is not supplied.

getIntArrayProperty

Added in API level 29
public int[] getIntArrayProperty (int prop, 
                int area)

Returns value of an integer array property

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

This method has the same exception behavior as getBooleanProperty(int, int).

Parameters
prop int: Property ID to get

area int: Zone of the property to get

Returns
int[] value of an integer array property, an empty integer array if can not get the value from cars.

Throws
android.car.hardware.property.CarInternalErrorException CarInternalErrorException} when there is an error detected in cars.
android.car.hardware.property.PropertyAccessDeniedSecurityException PropertyAccessDeniedSecurityException} when cars denied the access of the property.
android.car.hardware.property.PropertyNotAvailableAndRetryException PropertyNotAvailableAndRetryException} when the property is temporarily not available and likely that retrying will be successful.
android.car.hardware.property.PropertyNotAvailableException PropertyNotAvailableException} when the property is temporarily not available.
java.lang.IllegalArgumentException IllegalArgumentException} when the property in the areaId is not supplied.

getIntProperty

Added in API level 29
public int getIntProperty (int prop, 
                int area)

Returns value of an integer property

This method may take couple seconds to complete, so it needs to be called form an non-main thread.

This method has the same exception behavior as getBooleanProperty(int, int).

Parameters
prop int: Property ID to get

area int: Zone of the property to get

Returns
int value of an integer property, 0 if can not get the value from cars.

Throws
android.car.hardware.property.CarInternalErrorException CarInternalErrorException} when there is an error detected in cars.
android.car.hardware.property.PropertyAccessDeniedSecurityException PropertyAccessDeniedSecurityException} when cars denied the access of the property.
android.car.hardware.property.PropertyNotAvailableAndRetryException PropertyNotAvailableAndRetryException} when the property is temporarily not available and likely that retrying will be successful.
android.car.hardware.property.PropertyNotAvailableException PropertyNotAvailableException} when the property is temporarily not available.
java.lang.IllegalArgumentException IllegalArgumentException} when the property in the areaId is not supplied.

getProperty

Added in API level 29
public CarPropertyValue<E> getProperty (Class<E> clazz, 
                int propId, 
                int areaId)

Return CarPropertyValue

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

Clients that declare a ApplicationInfo.targetSdkVersion equal or later than Build.VERSION_CODES#R will receive the following exceptions when request is failed.

Clients that declare a ApplicationInfo.targetSdkVersion earlier than Build.VERSION_CODES#R will receive the following exceptions when request is failed.

Parameters
clazz Class: The class object for the CarPropertyValue

propId int: Property ID to get

areaId int: Zone of the property to get

Returns
CarPropertyValue<E> CarPropertyValue. Null if property's id is invalid.

Throws
android.car.hardware.property.CarInternalErrorException CarInternalErrorException} when there is an error detected in cars.
android.car.hardware.property.PropertyAccessDeniedSecurityException PropertyAccessDeniedSecurityException} when cars denied the access of the property.
android.car.hardware.property.PropertyNotAvailableAndRetryException PropertyNotAvailableAndRetryException} when the property is temporarily not available and likely that retrying will be successful.
android.car.hardware.property.PropertyNotAvailableException PropertyNotAvailableException} when the property is temporarily not available.
java.lang.IllegalArgumentException IllegalArgumentException} when the property in the areaId is not supplied.

getProperty

Added in API level 29
public CarPropertyValue<E> getProperty (int propId, 
                int areaId)

Query CarPropertyValue with property id and areaId.

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

Clients that declare a ApplicationInfo.targetSdkVersion equal or later than Build.VERSION_CODES#R will receive the following exceptions when request is failed.

Clients that declare a ApplicationInfo.targetSdkVersion earlier than Build.VERSION_CODES#R will receive the following exceptions when request is failed.

Parameters
propId int: Property Id

areaId int: areaId

Returns
CarPropertyValue<E> CarPropertyValue. Null if property's id is invalid.

Throws
android.car.hardware.property.CarInternalErrorException CarInternalErrorException} when there is an error detected in cars.
android.car.hardware.property.PropertyAccessDeniedSecurityException PropertyAccessDeniedSecurityException} when cars denied the access of the property.
android.car.hardware.property.PropertyNotAvailableAndRetryException PropertyNotAvailableAndRetryException} when the property is temporarily not available and likely that retrying will be successful.
android.car.hardware.property.PropertyNotAvailableException PropertyNotAvailableException} when the property is temporarily not available.
java.lang.IllegalArgumentException IllegalArgumentException} when the property in the areaId is not supplied.

getPropertyList

Added in API level 29
public List<CarPropertyConfig> getPropertyList (ArraySet<Integer> propertyIds)

Parameters
propertyIds ArraySet: property ID list

Returns
List<CarPropertyConfig> List of properties implemented by this car in given property ID list that application may access.

getPropertyList

Added in API level 29
public List<CarPropertyConfig> getPropertyList ()

Returns
List<CarPropertyConfig> List of properties implemented by this car that the application may access.

isPropertyAvailable

Added in API level 29
public boolean isPropertyAvailable (int propId, 
                int area)

Check whether a given property is available or disabled based on the car's current state.

Parameters
propId int: Property ID

area int: AreaId of property

Returns
boolean true if CarPropertyValue#STATUS_AVAILABLE, false otherwise (eg CarPropertyValue#STATUS_UNAVAILABLE)

registerCallback

Added in API level 29
public boolean registerCallback (CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback, 
                int propertyId, 
                float updateRateHz)

Register CarPropertyEventCallback to get property updates. Multiple callbacks can be registered for a single property or the same callback can be used for different properties. If the same callback is registered again for the same property, it will be updated to new updateRateHz.

Rate could be one of the following:

Note:Rate has no effect if the property has one of the following change modes:

Note:If listener registers for updates for a CarPropertyConfig#VEHICLE_PROPERTY_CHANGE_MODE_ONCHANGE property, it will receive the property's current value upon registration. See CarPropertyConfig#getChangeMode() for details. If updateRateHz is higher than CarPropertyConfig#getMaxSampleRate(), it will be registered with max sample updateRateHz. If updateRateHz is lower than CarPropertyConfig#getMinSampleRate(), it will be registered with min sample updateRateHz.

Parameters
carPropertyEventCallback CarPropertyManager.CarPropertyEventCallback: CarPropertyEventCallback to be registered.

propertyId int: PropertyId to subscribe

updateRateHz float: how fast the property events are delivered in Hz. Value is between 0.0 and 100.0 inclusive

Returns
boolean true if the listener is successfully registered.

Throws
SecurityException if missing the appropriate permission.

setBooleanProperty

Added in API level 29
public void setBooleanProperty (int prop, 
                int areaId, 
                boolean val)

Modifies a property. If the property modification doesn't occur, an error event shall be generated and propagated back to the application.

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

Parameters
prop int: Property ID to modify

areaId int: AreaId to apply the modification.

val boolean: Value to set

setFloatProperty

Added in API level 29
public void setFloatProperty (int prop, 
                int areaId, 
                float val)

Set float value of property

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

Parameters
prop int: Property ID to modify

areaId int: AreaId to apply the modification

val float: Value to set

setIntProperty

Added in API level 29
public void setIntProperty (int prop, 
                int areaId, 
                int val)

Set int value of property

This method may take couple seconds to complete, so it needs to be called from an non-main thread.

Parameters
prop int: Property ID to modify

areaId int: AreaId to apply the modification

val int: Value to set

setProperty

Added in API level 29
public void setProperty (Class<E> clazz, 
                int propId, 
                int areaId, 
                E val)

Set value of car property by areaId.

If multiple clients set a property for the same area id simultaneously, which one takes precedence is undefined. Typically, the last set operation (in the order that they are issued to the car's ECU) overrides the previous set operations.

This method may take couple seconds to complete, so it needs to be called form an non-main thread.

Clients that declare a ApplicationInfo.targetSdkVersion equal or later than Build.VERSION_CODES#R will receive the following exceptions when request is failed.

Clients that declare a ApplicationInfo.targetSdkVersion earlier than Build.VERSION_CODES#R will receive the following exceptions when request is failed.

Parameters
clazz Class: The class object for the CarPropertyValue

propId int: Property ID

areaId int: areaId

val E: Value of CarPropertyValue

Throws
android.car.hardware.property.CarInternalErrorException CarInternalErrorException} when there is an error detected in cars.
android.car.hardware.property.PropertyAccessDeniedSecurityException PropertyAccessDeniedSecurityException} when cars denied the access of the property.
android.car.hardware.property.PropertyNotAvailableException PropertyNotAvailableException} when the property is temporarily not available.
android.car.hardware.property.PropertyNotAvailableAndRetryException PropertyNotAvailableAndRetryException} when the property is temporarily not available and likely that retrying will be successful.
java.lang.IllegalStateException IllegalStateException} when get an unexpected error code.
java.lang.IllegalArgumentException IllegalArgumentException} when the property in the areaId is not supplied.

unregisterCallback

Added in API level 29
public void unregisterCallback (CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Stop getting property updates for the given CarPropertyEventCallback. If there are multiple registrations for this CarPropertyEventCallback, all listening will be stopped.

Parameters
carPropertyEventCallback CarPropertyManager.CarPropertyEventCallback

Throws
SecurityException if missing the appropriate permission.

unregisterCallback

Added in API level 29
public void unregisterCallback (CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback, 
                int propertyId)

Stop getting update for propertyId to the given CarPropertyEventCallback. If the same CarPropertyEventCallback is used for other properties, those subscriptions will not be affected.

Parameters
carPropertyEventCallback CarPropertyManager.CarPropertyEventCallback

propertyId int

Throws
SecurityException if missing the appropriate permission.