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.AsyncPropertyRequest

An async get/set property request. 

interface CarPropertyManager.CarPropertyEventCallback

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

interface CarPropertyManager.GetPropertyCallback

A callback CarPropertyManager#getPropertiesAsync when succeeded or failed. 

class CarPropertyManager.GetPropertyRequest

A request for CarPropertyManager#getPropertiesAsync(List, long, CancellationSignal, Executor, GetPropertyCallback)

class CarPropertyManager.GetPropertyResult<T>

A successful result for GetPropertyCallback

class CarPropertyManager.PropertyAsyncError

An error result for GetPropertyCallback or SetPropertyCallback

interface CarPropertyManager.SetPropertyCallback

A callback CarPropertyManager#setPropertiesAsync when succeeded or failed. 

class CarPropertyManager.SetPropertyRequest<T>

A request for CarPropertyManager#setPropertiesAsync(List, long, CancellationSignal, Executor, SetPropertyCallback)

class CarPropertyManager.SetPropertyResult

A successful result for SetPropertyCallback

Constants

long ASYNC_GET_DEFAULT_TIMEOUT_MS

The default timeout in MS for CarPropertyManager#getPropertiesAsync.

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 a 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

int STATUS_ERROR_INTERNAL_ERROR

Error indicating that there is an error detected in cars.

int STATUS_ERROR_NOT_AVAILABLE

Error indicating that the property is temporarily not available.

int STATUS_ERROR_TIMEOUT

Error indicating the operation has timed-out.

Public methods

CarPropertyManager.GetPropertyRequest generateGetPropertyRequest(int propertyId, int areaId)

Generate unique get request ID and return to the client.

<T> SetPropertyRequest<T> generateSetPropertyRequest(int propertyId, int areaId, T value)

Generate unique set request ID and return to the client.

int getAreaId(int propertyId, int area)

Returns areaId contains the selected area for the property.

boolean getBooleanProperty(int propertyId, int areaId)

Returns value of a bool property

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

CarPropertyConfig<?> getCarPropertyConfig(int propertyId)

Get CarPropertyConfig by property ID.

float getFloatProperty(int propertyId, int areaId)

Returns value of a float property

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

int[] getIntArrayProperty(int propertyId, int areaId)

Returns value of an integer array property

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

int getIntProperty(int propertyId, int areaId)

Returns value of an integer property

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

void getPropertiesAsync(List<CarPropertyManager.GetPropertyRequest> getPropertyRequests, CancellationSignal cancellationSignal, Executor callbackExecutor, CarPropertyManager.GetPropertyCallback getPropertyCallback)

Query a list of CarPropertyValue with property Id and area Id asynchronously.

void getPropertiesAsync(List<CarPropertyManager.GetPropertyRequest> getPropertyRequests, long timeoutInMs, CancellationSignal cancellationSignal, Executor callbackExecutor, CarPropertyManager.GetPropertyCallback getPropertyCallback)

Query a list of CarPropertyValue with property ID and area ID asynchronously.

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

Query CarPropertyValue with property id and areaId.

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

Return CarPropertyValue

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

List<CarPropertyConfig<T>> getPropertyList()
List<CarPropertyConfig<T>> getPropertyList(ArraySet<Integer> propertyIds)

Checks the given property IDs and returns a list of property configs supported by the car.

boolean isPropertyAvailable(int propertyId, int areaId)

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)

This method is deprecated. Use CarPropertyManager#subscribePropertyEvents(int, float, CarPropertyEventCallback) instead. Note that subscribePropertyEvents by default has variable update rate on for continuous properties, but registerCallback by default has variable update rate off. If you want to keep the current behavior of receiving property events for duplicate values (which hurts performance), please specify the variable update rate option via Subscription.Builder#setVariableUpdateRateEnabled. Registers 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: When this function is called, the callback will receive the current values for all the areaIds for the property through property change events if they are currently okay for reading. If they are not available for reading or in error state, property change events with a unavailable or error status will be generated.

For properties that might be unavailable for reading because their power state is off, property change events containing the property's initial value will be generated once their power state is on.

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.

Note:Caller must check the value of CarPropertyValue#getStatus() for property change events and only use CarPropertyValue#getValue() when CarPropertyValue#getStatus() is CarPropertyValue#STATUS_AVAILABLE. If not, the CarPropertyValue#getValue() is meaningless.

Note:A property change event may/may not happen when the property's status changes. Caller should not depend on the change event to check property's status. For properties that might be unavailable because they depend on certain power state, caller should subscribe to the power state property (e.g. VehiclePropertyIds#HVAC_POWER_ON for hvac power dependent properties) to decide this property's availability.

If the registration failed, this will return false. Caller must check the return value to make sure the registration succeeded.

If the property is not supported, this will return false.

If the property is supported and the caller does not have read or write permission to it, this will return false.

If the caller has write permission but does not have read permission, this will throw SecurityException.

Note that the callback will be executed on the event handler provided to the Car or the main thread if none was provided.

If one CarPropertyEventCallback is already registered using CarPropertyManager#subscribePropertyEvents, caller must make sure the executor was null (using the default executor) when calling subscribePropertyEvents.

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

Modifies a property.

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

Set float value of property

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

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

Set int value of property

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

void setPropertiesAsync(List<SetPropertyRequest<?>> setPropertyRequests, CancellationSignal cancellationSignal, Executor callbackExecutor, CarPropertyManager.SetPropertyCallback setPropertyCallback)

Sets a list of car property values asynchronously.

void setPropertiesAsync(List<SetPropertyRequest<?>> setPropertyRequests, long timeoutInMs, CancellationSignal cancellationSignal, Executor callbackExecutor, CarPropertyManager.SetPropertyCallback setPropertyCallback)

Sets a list of car property values asynchronously.

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

Set value of car property by areaId.

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

Subscribes to property events for the specific area ID for the property.

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

Subscribes to property events for all areaIds for the property.

boolean subscribePropertyEvents(int propertyId, CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Subscribes to property events for all areaIds for the property.

boolean subscribePropertyEvents(int propertyId, int areaId, CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Subscribes to property events for the specific area ID for the property.

boolean subscribePropertyEvents(List<Subscription> subscriptions, Executor callbackExecutor, CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Subscribes to multiple [propertyId, areaId]s for property events.

void unregisterCallback(CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

This method is deprecated. Use CarPropertyManager#unsubscribePropertyEvents(CarPropertyEventCallback) instead. Stop getting property updates for the given CarPropertyEventCallback. If there are multiple registrations for this CarPropertyEventCallback, all listening will be stopped.

void unregisterCallback(CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback, int propertyId)

This method is deprecated. Use CarPropertyManager#unsubscribePropertyEvents(int, CarPropertyEventCallback) instead. Stop getting update for propertyId to the given CarPropertyEventCallback. If the same CarPropertyEventCallback is used for other properties, those subscriptions will not be affected.

void unsubscribePropertyEvents(CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Stop getting property updates for the given CarPropertyEventCallback.

void unsubscribePropertyEvents(int propertyId, CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Stop getting update for propertyId to the given CarPropertyEventCallback.

Inherited methods

Constants

ASYNC_GET_DEFAULT_TIMEOUT_MS

public static final long ASYNC_GET_DEFAULT_TIMEOUT_MS

The default timeout in MS for CarPropertyManager#getPropertiesAsync.

Constant Value: 10000 (0x0000000000002710)

CAR_SET_PROPERTY_ERROR_CODE_ACCESS_DENIED

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

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

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

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

public static final int CAR_SET_PROPERTY_ERROR_CODE_UNKNOWN

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

Constant Value: 5 (0x00000005)

SENSOR_RATE_FAST

public static final float SENSOR_RATE_FAST

Read sensors at the rate of 10 hertz

Constant Value: 10.0

SENSOR_RATE_FASTEST

public static final float SENSOR_RATE_FASTEST

Read sensors at the rate of 100 hertz

Constant Value: 100.0

SENSOR_RATE_NORMAL

public static final float SENSOR_RATE_NORMAL

Read sensors at the rate of 1 hertz

Constant Value: 1.0

SENSOR_RATE_ONCHANGE

public static final float SENSOR_RATE_ONCHANGE

Read ONCHANGE sensors.

Constant Value: 0.0

SENSOR_RATE_UI

public static final float SENSOR_RATE_UI

Read sensors at the rate of 5 hertz

Constant Value: 5.0

STATUS_ERROR_INTERNAL_ERROR

public static final int STATUS_ERROR_INTERNAL_ERROR

Error indicating that there is an error detected in cars.

Constant Value: 1 (0x00000001)

STATUS_ERROR_NOT_AVAILABLE

public static final int STATUS_ERROR_NOT_AVAILABLE

Error indicating that the property is temporarily not available.

Constant Value: 2 (0x00000002)

STATUS_ERROR_TIMEOUT

public static final int STATUS_ERROR_TIMEOUT

Error indicating the operation has timed-out.

Constant Value: 3 (0x00000003)

Public methods

generateGetPropertyRequest

public CarPropertyManager.GetPropertyRequest generateGetPropertyRequest (int propertyId, 
                int areaId)

Generate unique get request ID and return to the client.

Parameters
propertyId int: the property ID

areaId int: the area ID

Returns
CarPropertyManager.GetPropertyRequest the GetPropertyRequest object

generateSetPropertyRequest

public SetPropertyRequest<T> generateSetPropertyRequest (int propertyId, 
                int areaId, 
                T value)

Generate unique set request ID and return to the client.

Parameters
propertyId int: the property ID

areaId int: the area ID

value T: the value to set

Returns
SetPropertyRequest<T> the SetPropertyRequest object

getAreaId

public int getAreaId (int propertyId, 
                int area)

Returns areaId contains the selected area for the property.

Parameters
propertyId int: the property ID

area int: the 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 supported in the vehicle for the selected area or the caller does not have read or write permission to the property.

getBooleanProperty

public boolean getBooleanProperty (int propertyId, 
                int areaId)

Returns value of a bool property

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

Note: Client MUST NOT use one of the following as propertyId, otherwise the behavior is undefined:

  • INITIAL_USER_INFO
  • SWITCH_USER
  • CREATE_USER
  • REMOVE_USER
  • USER_IDENTIFICATION_ASSOCIATION

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

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

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

  • IllegalStateException when there is an error detected in cars, or when cars denied the access of the property, or when the property is not available and might be unavailable for a while, or when unexpected error happens.
  • IllegalArgumentException when the property is of wrong type.
  • false when the [propertyId, areaId] is not supported or when the property is temporarily not available.

For pre-R client, the returned value might be false if the property is temporarily not available. The client should try again in this case.

For pre-U client, when the [propertyId, areaId] is not supported, this will return false.

For U and later client, when the [propertyId, areaId] is not supported, this is guaranteed to throw IllegalArgumentException.

Parameters
propertyId int: the property ID to get

areaId int: the area ID of the property to get

Returns
boolean the value of a bool property or false.

Throws
CarInternalErrorException when there is an unexpected error detected in cars
PropertyAccessDeniedSecurityException when cars denied the access of the property
PropertyNotAvailableAndRetryException when [propertyId, areaId] is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when [propertyId, areaId] is not available and might be unavailable for a while.
IllegalArgumentException when the [propertyId, areaId] is not supported for U and later client, or when the property is of wrong type.

getCarPropertyConfig

public CarPropertyConfig<?> getCarPropertyConfig (int propertyId)

Get CarPropertyConfig by property ID.

Parameters
propertyId int: the property ID

Returns
CarPropertyConfig<?> the CarPropertyConfig for the selected property, null if missing the required permission to read/write the property or the property is not supported.

getFloatProperty

public float getFloatProperty (int propertyId, 
                int areaId)

Returns value of a float property

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

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

Parameters
propertyId int: the property ID to get

areaId int: the area ID of the property to get

Returns
float the value of a float property or 0.

Throws
CarInternalErrorException when there is an unexpected error detected in cars
PropertyAccessDeniedSecurityException when cars denied the access of the property
PropertyNotAvailableAndRetryException when [propertyId, areaId] is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when [propertyId, areaId] is not available and might be unavailable for a while.
IllegalArgumentException when the [propertyId, areaId] is not supported for U and later client, or when the property is of wrong type.

getIntArrayProperty

public int[] getIntArrayProperty (int propertyId, 
                int areaId)

Returns value of an integer array property

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

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

Parameters
propertyId int: the property ID to get

areaId int: the area ID of the property to get

Returns
int[] the value of an integer array property or an empty array.

Throws
CarInternalErrorException when there is an unexpected error detected in cars
PropertyAccessDeniedSecurityException when cars denied the access of the property
PropertyNotAvailableAndRetryException when [propertyId, areaId] is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when [propertyId, areaId] is not available and might be unavailable for a while.
IllegalArgumentException when the [propertyId, areaId] is not supported for U and later client, or when the property is of wrong type.

getIntProperty

public int getIntProperty (int propertyId, 
                int areaId)

Returns value of an integer property

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

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

Parameters
propertyId int: the property ID to get

areaId int: the area ID of the property to get

Returns
int the value of aa integer property or 0.

Throws
CarInternalErrorException when there is an unexpected error detected in cars
PropertyAccessDeniedSecurityException when cars denied the access of the property
PropertyNotAvailableAndRetryException when [propertyId, areaId] is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when [propertyId, areaId] is not available and might be unavailable for a while.
IllegalArgumentException when the [propertyId, areaId] is not supported for U and later client, or when the property is of wrong type.

getPropertiesAsync

public void getPropertiesAsync (List<CarPropertyManager.GetPropertyRequest> getPropertyRequests, 
                CancellationSignal cancellationSignal, 
                Executor callbackExecutor, 
                CarPropertyManager.GetPropertyCallback getPropertyCallback)

Query a list of CarPropertyValue with property Id and area Id asynchronously. Same as CarPropertyManager#getPropertiesAsync(List, long, CancellationSignal, Executor, GetPropertyCallback) with default timeout 10s.

Parameters
getPropertyRequests List

cancellationSignal CancellationSignal

callbackExecutor Executor

getPropertyCallback CarPropertyManager.GetPropertyCallback

getPropertiesAsync

public void getPropertiesAsync (List<CarPropertyManager.GetPropertyRequest> getPropertyRequests, 
                long timeoutInMs, 
                CancellationSignal cancellationSignal, 
                Executor callbackExecutor, 
                CarPropertyManager.GetPropertyCallback getPropertyCallback)

Query a list of CarPropertyValue with property ID and area ID asynchronously.

This function would return immediately before the results are ready. For each request, the corresponding result would either be delivered through one resultCallback.onSuccess call if the request succeeded or through one errorCallback.onFailure call if failed. It is guaranteed that the total times the callback functions are called is equal to the number of requests if this function does not throw an exception. It is guaranteed that none of the callback functions are called if an exception is thrown. If the callbackExecutor is null, the callback will be executed on the default event handler thread. If the callback is doing heavy work, it is recommended that the callbackExecutor is provided.

If the operation is cancelled, it is guaranteed that no more callbacks will be called.

For one request, if the property's status is not available, errorCallback.onFailure will be called once with STATUS_ERROR_NOT_AVAILABLE.

For one request, if the property's status is error, errorCallback.onFailure will be called once with STATUS_ERROR_INTERNAL_ERROR.

Parameters
getPropertyRequests List: a list of properties to get

timeoutInMs long: the timeout for the operation, in milliseconds

cancellationSignal CancellationSignal: a signal that could be used to cancel the on-going operation

callbackExecutor Executor: the executor to execute the callback with

getPropertyCallback CarPropertyManager.GetPropertyCallback: the callback function to deliver the result

Throws
SecurityException if missing permission to read one of the specific properties.
IllegalArgumentException if one of the properties to read is not supported.

getProperty

public CarPropertyValue<E> getProperty (int propertyId, 
                int areaId)

Query CarPropertyValue with property id and areaId.

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

Note: Client MUST NOT use one of the following as propertyId, otherwise the behavior is undefined (might throw exception or might return null):

  • INITIAL_USER_INFO
  • SWITCH_USER
  • CREATE_USER
  • REMOVE_USER
  • USER_IDENTIFICATION_ASSOCIATION

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

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

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

  • IllegalStateException when there is an error detected in cars, or when cars denied the access of the property, or when the property is not available and might be unavailable for a while, or when unexpected error happens.
  • null when the [propertyId, areaId] is not supported or when the property is temporarily not available.

For pre-R client, the returned value might be null if the property is temporarily not available. The client should try again in this case.

For pre-U client, when the [propertyId, areaId] is not supported, this will return null.

For pre-U client, the returned CarPropertyValue might contain unavailable or error status. Client must use CarPropertyValue#getStatus to check. If the returned status is not CarPropertyValue#STATUS_AVAILABLE, then the value returned via CarPropertyValue#getValue is undefined.

For U and later client, when the [propertyId, areaId] is not supported, this is guaranteed to throw IllegalArgumentException. This method will never return null.

For U and later client, if the property's status is CarPropertyValue#STATUS_UNAVAILABLE, then PropertyNotAvailableException will be thrown. If the property's status is CarPropertyValue#STATUS_ERROR, then CarInternalErrorException will be thrown. If no exception is thrown, the returned CarPropertyValue#getStatus is guaranteed to be CarPropertyValue#STATUS_AVAILABLE so client do not need to check.

Parameters
propertyId int: the property ID to get

areaId int: the area ID of the property to get

Returns
CarPropertyValue<E> the value of a property

Throws
CarInternalErrorException when there is an unexpected error detected in cars
PropertyAccessDeniedSecurityException when cars denied the access of the property
PropertyNotAvailableAndRetryException when [propertyId, areaId] is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when [propertyId, areaId] is not available and might be unavailable for a while.
IllegalArgumentException when the [propertyId, areaId] is not supported for U and later client.

getProperty

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

Return CarPropertyValue

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

Note: Client MUST NOT use one of the following as propertyId, otherwise the behavior is undefined (might throw exception or might return null):

  • INITIAL_USER_INFO
  • SWITCH_USER
  • CREATE_USER
  • REMOVE_USER
  • USER_IDENTIFICATION_ASSOCIATION

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

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

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

  • IllegalStateException when there is an error detected in cars, or when cars denied the access of the property, or when the property is not available and might be unavailable for a while, or when unexpected error happens.
  • IllegalArgumentException when the specified class does not match the property type.
  • null when the [propertyId, areaId] is not supported or when the property is temporarily not available.

For pre-R client, the returned value might be null if the property is temporarily not available. The client should try again in this case.

For pre-U client, when the [propertyId, areaId] is not supported, this will return null.

For pre-U client, the returned CarPropertyValue might contain unavailable or error status. Client must use CarPropertyValue#getStatus to check. If the returned status is not CarPropertyValue#STATUS_AVAILABLE, then the value returned via CarPropertyValue#getValue is undefined.

For U and later client, when the [propertyId, areaId] is not supported, this is guaranteed to throw IllegalArgumentException. This method will never return null.

For U and later client, if the property's status is CarPropertyValue#STATUS_UNAVAILABLE, then PropertyNotAvailableException will be thrown. If the property's status is CarPropertyValue#STATUS_ERROR, then CarInternalErrorException will be thrown. If no exception is thrown, the returned CarPropertyValue#getStatus is guaranteed to be CarPropertyValue#STATUS_AVAILABLE so client do not need to check.

Parameters
clazz Class: the class object for the CarPropertyValue

propertyId int: the property ID to get

areaId int: the area ID of the property to get

Returns
CarPropertyValue<E> the value of a property or null.

Throws
CarInternalErrorException when there is an unexpected error detected in cars
PropertyAccessDeniedSecurityException when cars denied the access of the property
PropertyNotAvailableAndRetryException when [propertyId, areaId] is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when [propertyId, areaId] is not available and might be unavailable for a while.
IllegalArgumentException when the [propertyId, areaId] is not supported for U and later client, or when the specified class does not match the property type.

getPropertyList

public List<CarPropertyConfig<T>> getPropertyList ()

Returns
List<CarPropertyConfig<T>> the list of properties supported by this car that the application may access

getPropertyList

public List<CarPropertyConfig<T>> getPropertyList (ArraySet<Integer> propertyIds)

Checks the given property IDs and returns a list of property configs supported by the car. If some of the properties in the given ID list are not supported, they will not be returned.

Parameters
propertyIds ArraySet: the list of property IDs

Returns
List<CarPropertyConfig<T>> the list of property configs

isPropertyAvailable

public boolean isPropertyAvailable (int propertyId, 
                int areaId)

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

Parameters
propertyId int: the property ID

areaId int: the area ID

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

registerCallback

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

This method is deprecated.
Use CarPropertyManager#subscribePropertyEvents(int, float, CarPropertyEventCallback) instead. Note that subscribePropertyEvents by default has variable update rate on for continuous properties, but registerCallback by default has variable update rate off. If you want to keep the current behavior of receiving property events for duplicate values (which hurts performance), please specify the variable update rate option via Subscription.Builder#setVariableUpdateRateEnabled. Registers 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: When this function is called, the callback will receive the current values for all the areaIds for the property through property change events if they are currently okay for reading. If they are not available for reading or in error state, property change events with a unavailable or error status will be generated.

For properties that might be unavailable for reading because their power state is off, property change events containing the property's initial value will be generated once their power state is on.

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.

Note:Caller must check the value of CarPropertyValue#getStatus() for property change events and only use CarPropertyValue#getValue() when CarPropertyValue#getStatus() is CarPropertyValue#STATUS_AVAILABLE. If not, the CarPropertyValue#getValue() is meaningless.

Note:A property change event may/may not happen when the property's status changes. Caller should not depend on the change event to check property's status. For properties that might be unavailable because they depend on certain power state, caller should subscribe to the power state property (e.g. VehiclePropertyIds#HVAC_POWER_ON for hvac power dependent properties) to decide this property's availability.

If the registration failed, this will return false. Caller must check the return value to make sure the registration succeeded.

If the property is not supported, this will return false.

If the property is supported and the caller does not have read or write permission to it, this will return false.

If the caller has write permission but does not have read permission, this will throw SecurityException.

Note that the callback will be executed on the event handler provided to the Car or the main thread if none was provided.

If one CarPropertyEventCallback is already registered using CarPropertyManager#subscribePropertyEvents, caller must make sure the executor was null (using the default executor) when calling subscribePropertyEvents.

Parameters
carPropertyEventCallback CarPropertyManager.CarPropertyEventCallback: the CarPropertyEventCallback to be registered

propertyId int: the property ID 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 the property is supported and the caller has write permission, but does not have read permission.

setBooleanProperty

public void setBooleanProperty (int propertyId, 
                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 a non-main thread.

Parameters
propertyId int: the property ID to modify

areaId int: the area ID to apply the modification

val boolean: the value to set

setFloatProperty

public void setFloatProperty (int propertyId, 
                int areaId, 
                float val)

Set float value of property

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

Parameters
propertyId int: the property ID to modify

areaId int: the area ID to apply the modification

val float: the value to set

setIntProperty

public void setIntProperty (int propertyId, 
                int areaId, 
                int val)

Set int value of property

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

Parameters
propertyId int: the property ID to modify

areaId int: the area ID to apply the modification

val int: the value to set

setPropertiesAsync

public void setPropertiesAsync (List<SetPropertyRequest<?>> setPropertyRequests, 
                CancellationSignal cancellationSignal, 
                Executor callbackExecutor, 
                CarPropertyManager.SetPropertyCallback setPropertyCallback)

Sets a list of car property values asynchronously. Same as CarPropertyManager#setPropertiesAsync(List, long, CancellationSignal, Executor, SetPropertyCallback) with default timeout 10s.

Parameters
setPropertyRequests List

cancellationSignal CancellationSignal

callbackExecutor Executor

setPropertyCallback CarPropertyManager.SetPropertyCallback

setPropertiesAsync

public void setPropertiesAsync (List<SetPropertyRequest<?>> setPropertyRequests, 
                long timeoutInMs, 
                CancellationSignal cancellationSignal, 
                Executor callbackExecutor, 
                CarPropertyManager.SetPropertyCallback setPropertyCallback)

Sets a list of car property values asynchronously.

This function would return immediately before the results are ready. For each request, the corresponding result would either be delivered through one resultCallback.onSuccess call if the request succeeded or through one errorCallback.onFailure call if failed. It is guaranteed that the total times the callback functions are called is equal to the number of requests if this function does not throw an exception. It is guaranteed that none of the callback functions are called if an exception is thrown. If the callbackExecutor is null, the callback will be executed on the default event handler thread. If the callback is doing heavy work, it is recommended that the callbackExecutor is provided.

If the operation is cancelled, it is guaranteed that no more callbacks will be called.

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.

When the success callback will be called depends on whether waitForPropertyUpdate for each request is set. If this is set to true (by default), the success callback will be called when the set operation is successfully delivered to vehicle bus AND either target value is the same as the current or when the property is updated to the target value.

When waitForPropertyUpdate is set to false, the success callback will be called as long as the set operation is successfully delivered to vehicle bus.

Under most cases, client should wait for the property update to verify that the set operation actually succeeded.

For cases when the property is write-only (no way to get property update event) or when the property represents some action, instead of an actual state, e.g. key stroke where the property's current value is not meaningful, caller must set waitForPropertyUpdate to false.

For HVAC_TEMPERATURE_VALUE_SUGGESTION, this must be set to false because the updated property value will not be the same as the value to be set.

Parameters
setPropertyRequests List: a list of properties to set

timeoutInMs long: the timeout for the operation, in milliseconds

cancellationSignal CancellationSignal: a signal that could be used to cancel the on-going operation

callbackExecutor Executor: the executor to execute the callback with

setPropertyCallback CarPropertyManager.SetPropertyCallback: the callback function to deliver the result

Throws
SecurityException if missing permission to write one of the specific properties.
IllegalArgumentException if one of the properties to set is not supported.
IllegalArgumentException if one of the values to set is not supported by the property.
IllegalArgumentException if one of the properties is not readable and does not set waitForPropertyUpdate to false.
IllegalArgumentException if one of the properties is HVAC_TEMPERATURE_VALUE_SUGGESTION and does not set waitForPropertyUpdate to false.

setProperty

public void setProperty (Class<E> clazz, 
                int propertyId, 
                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 a non-main thread.

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

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

  • RuntimeException when the property is temporarily not available.
  • IllegalStateException when there is an error detected in cars, or when cars denied the access of the property, or when the property is not available and might be unavailable for a while, or when unexpected error happens.
  • IllegalArgumentException when the [propertyId, areaId] is not supported.

Returning from this method does not necessary mean the set operation succeeded. In order to determine whether the operation succeeded/failed, Client should use CarPropertyManager#registerCallback to register for property updates for this [propertyId, areaId] before the set operation. The operation succeeded when CarPropertyEventCallback#onChangeEvent is called with the value to be set. The operation failed when CarPropertyEventCallback#onErrorEvent is called for this [propertyId, areaId]. Note that the registration must happen before the set operation otherwise the callback might be invoked after the set operation, but before the registration.

Note that if the value to set is the same as the current value, the set request will still be sent to vehicle hardware, however, a new property change event will not be generated for the set operation. If client want to prevent the set request to be sent, client must use ERROR(/getProperty) to check the current value before calling this.

Parameters
clazz Class: the class object for the CarPropertyValue

propertyId int: the property ID to modify

areaId int: the area ID to apply the modification

val E: the value to set

Throws
CarInternalErrorException when there is an unexpected error detected in cars.
PropertyAccessDeniedSecurityException when cars denied the access of the property.
PropertyNotAvailableException when [propertyId, areaId] is not available and might be unavailable for a while.
PropertyNotAvailableAndRetryException when [propertyId, areaId] is temporarily not available and likely that retrying will be successful.
IllegalArgumentException when the [propertyId, areaId] or value is not supported.

subscribePropertyEvents

public boolean subscribePropertyEvents (int propertyId, 
                int areaId, 
                float updateRateHz, 
                CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Subscribes to property events for the specific area ID for the property.

For continuous property, variable update rate is enabled.

A property event is used to indicate a property's value/status changes (a.k.a property update event) or used to indicate a previous setProperty(Class, int, int, E) operation failed (a.k.a property error event).

It is allowed to register multiple carPropertyEventCallback for a single [PropertyId, areaId]. All the registered callbacks will be invoked.

It is only allowed to have one updateRateHz for a single [propertyId, areaId, carPropertyEventCallback] combination. A new updateRateHz for such combination will update the updateRateHz.

It is only allowed to have one setVariableUpdateRateEnabled setting for a single [propertyId, areaId, carPropertyEventCallback] combination. A new setting will overwrite the current setting for the combination.

The carPropertyEventCallback is executed on a single default event handler thread.

Note: When this function is called, the callback will receive the current values of the subscribed [propertyId, areaId]s through property change events if they are currently okay for reading. If they are not available for reading or in error state, property change events with a unavailable or error status will be generated.

Note that the callback will be executed on the event handler provided to the Car or the main thread if none was provided.

Parameters
propertyId int: The ID for the property to subscribe to.

areaId int: The ID for the area to subscribe to.

updateRateHz float: Only meaningful for continuous property. The update rate in Hz. A common value is 1Hz. See Subscription.Builder#setUpdateRateHz for detail. Value is between 0.0 and 100.0 inclusive

carPropertyEventCallback CarPropertyManager.CarPropertyEventCallback: The callback to deliver property update/error events.

Returns
boolean true if the listener is successfully registered

Throws
SecurityException if the caller does not have read permission to one of the supported properties.
IllegalArgumentException if there are over-lapping areaIds or the executor is registered to another callback or one of the properties are not supported.

subscribePropertyEvents

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

Subscribes to property events for all areaIds for the property.

For continuous property, variable update rate is enabled.

Note that the callback will be executed on the event handler provided to the Car or the main thread if none was provided.

Parameters
propertyId int: The ID for the property to subscribe to.

updateRateHz float: Only meaningful for continuous property. The update rate in Hz. A common value is 1Hz. See Subscription.Builder#setUpdateRateHz for detail. Value is between 0.0 and 100.0 inclusive

carPropertyEventCallback CarPropertyManager.CarPropertyEventCallback: The callback to deliver property update/error events.

Returns
boolean true if the listener is successfully registered

Throws
SecurityException if the caller does not have read permission to one of the supported properties.
IllegalArgumentException if there are over-lapping areaIds or the executor is registered to another callback or one of the properties are not supported.

subscribePropertyEvents

public boolean subscribePropertyEvents (int propertyId, 
                CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Subscribes to property events for all areaIds for the property.

For continuous property, variable update rate is enabled. The update rate is 1Hz or the max supported rate (if lower than 1hz).

Note that the callback will be executed on the event handler provided to the Car or the main thread if none was provided.

Parameters
propertyId int: The ID for the property to subscribe to.

carPropertyEventCallback CarPropertyManager.CarPropertyEventCallback: The callback to deliver property update/error events.

Returns
boolean true if the listener is successfully registered

Throws
SecurityException if the caller does not have read permission to one of the supported properties.
IllegalArgumentException if there are over-lapping areaIds or the executor is registered to another callback or one of the properties are not supported.

subscribePropertyEvents

public boolean subscribePropertyEvents (int propertyId, 
                int areaId, 
                CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Subscribes to property events for the specific area ID for the property.

For continuous property, variable update rate is enabled. The update rate is 1Hz or the max supported rate (if lower than 1hz).

Note that the callback will be executed on the event handler provided to the Car or the main thread if none was provided.

Parameters
propertyId int: The ID for the property to subscribe to.

areaId int: The ID for the area to subscribe to.

carPropertyEventCallback CarPropertyManager.CarPropertyEventCallback: The callback to deliver property update/error events.

Returns
boolean true if the listener is successfully registered

Throws
SecurityException if the caller does not have read permission to one of the supported properties.
IllegalArgumentException if there are over-lapping areaIds or the executor is registered to another callback or one of the properties are not supported.

subscribePropertyEvents

public boolean subscribePropertyEvents (List<Subscription> subscriptions, 
                Executor callbackExecutor, 
                CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

Subscribes to multiple [propertyId, areaId]s for property events.

If caller don't need use different subscription options among different areaIds for one property (e.g. 1 Hz update rate for front-left and 5 Hz update rate for front-right), it is recommended to use one Subscription per property ID.

It is allowed to register multiple carPropertyEventCallback for a single [PropertyId, areaId]. All the registered callbacks will be invoked.

It is only allowed to have one updateRateHz for a single [propertyId, areaId, carPropertyEventCallback] combination. A new updateRateHz for such combination will update the updateRateHz.

It is only allowed to have one setVariableUpdateRateEnabled setting for a single [propertyId, areaId, carPropertyEventCallback] combination. A new setting will overwrite the current setting for the combination.

It is allowed to have the same PropertyId in different Subscriptions provided in one call. However, they must have non-overlapping AreaIds. A.k.a., one [PropertyId, AreaId] must only be associated with one Subscription within one call. Otherwise, IllegalArgumentException will be thrown.

If the callbackExecutor is null, the callback will be executed on the default event handler thread. If no AreaIds are specified, then it will subscribe to all AreaIds for that PropertyId.

Only one executor can be registered to a callback. The callback must be unregistered before trying to register another executor for the same callback. (A callback cannot have multiple executors)

Only one executor can be registered to a callback. The callback must be unregistered before trying to register another executor for the same callback. (E.G. A callback cannot have multiple executors)

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

If the property has the change mode: CarPropertyConfig#VEHICLE_PROPERTY_CHANGE_MODE_CONTINUOUS, updateRateHz in Subscription specifies how frequent the property value has to be polled. If setVariableUpdateRateEnabled is not called with false and variable update rate is supported based on AreaIdConfig.isVariableUpdateRateSupported(), then the client will receive property update event only when the property's value changes (a.k.a behaves the same as CarPropertyConfig#VEHICLE_PROPERTY_CHANGE_MODE_ONCHANGE). If setVariableUpdateRateEnabled is called with false or variable update rate is not supported, then the client will receive all the property update events based on the update rate even if the events contain the same property value.

See Subscription.Builder#setVariableUpdateRateEnabled for more detail.

Note: When this function is called, the callback will receive the current values of the subscribed [propertyId, areaId]s through property change events if they are currently okay for reading. If they are not available for reading or in error state, property change events with a unavailable or error status will be generated.

For properties that might be unavailable for reading because their power state is off, PropertyId change events containing the PropertyId's initial value will be generated once their power state is on.

If the update rate specified in the subscriptions for a given PropertyId is higher than the PropertyId's maximum sample rate, the subscription will be registered at the PropertyId's maximum sample rate specified by CarPropertyConfig#getMaxSampleRate().

If the update rate specified in the subscriptions for a given PropertyId is lower than the PropertyId's minimum sample rate, the subscription will be registered at the PropertyId's minimum sample rate specified by CarPropertyConfig#getMinSampleRate().

Note:Caller must check the value of CarPropertyValue#getStatus() for PropertyId change events and only use CarPropertyValue#getValue() when CarPropertyValue#getStatus() is CarPropertyValue#STATUS_AVAILABLE. If not, the CarPropertyValue#getValue() is meaningless.

Note:A PropertyId change event may/may not happen when the PropertyId's status changes. Caller should not depend on the change event to check PropertyId's status. For properties that might be unavailable because they depend on certain power state, caller should subscribe to the power state PropertyId (e.g. VehiclePropertyIds#HVAC_POWER_ON for hvac power dependent properties) to decide this PropertyId's availability.

If one CarPropertyEventCallback is already registered using CarPropertyManager#registerCallback, caller must make sure the executor is null (using the default executor) for subscribePropertyEvents.

Parameters
subscriptions List: A list of subscriptions to add, which specifies PropertyId, AreaId, and updateRateHz. Caller should typically use one Subscription for one property ID.

callbackExecutor Executor: The executor in which the callback is done on. If this is null, the callback will be executed on the event handler provided to the Car or the main thread if none was provided.

carPropertyEventCallback CarPropertyManager.CarPropertyEventCallback: The callback to deliver property update/error events.

Returns
boolean true if the listener is successfully registered

Throws
SecurityException if the caller does not have read permission to one of the supported properties.
IllegalArgumentException if there are over-lapping areaIds or the executor is registered to another callback or one of the properties are not supported.

unregisterCallback

public void unregisterCallback (CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

This method is deprecated.
Use CarPropertyManager#unsubscribePropertyEvents(CarPropertyEventCallback) instead. 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: A previously subscribed callback to unsubscribe.

Throws
SecurityException if the caller does not have read permission to the properties registered for this callback.

unregisterCallback

public void unregisterCallback (CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback, 
                int propertyId)

This method is deprecated.
Use CarPropertyManager#unsubscribePropertyEvents(int, CarPropertyEventCallback) instead. 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: A previously subscribed callback to unsubscribe.

propertyId int: The property ID to unsubscribe.

Throws
SecurityException if the caller does not have read permission to the property.

unsubscribePropertyEvents

public void unsubscribePropertyEvents (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: A previously subscribed callback to unsubscribe.

Throws
SecurityException if the caller does not have read permission to the properties registered for this callback.

unsubscribePropertyEvents

public void unsubscribePropertyEvents (int propertyId, 
                CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)

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
propertyId int: The property ID to unsubscribe.

carPropertyEventCallback CarPropertyManager.CarPropertyEventCallback: A previously subscribed callback to unsubscribe.

Throws
SecurityException if the caller does not have read permission to the property.