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

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

Query CarPropertyValue with property id and areaId.

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

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

List<CarPropertyConfig<T>> getPropertyList()
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)

Register CarPropertyEventCallback to get property updates.

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, long timeoutInMs, CancellationSignal cancellationSignal, Executor callbackExecutor, CarPropertyManager.SetPropertyCallback setPropertyCallback)

Sets a list of car property values asynchronously.

void setPropertiesAsync(List<SetPropertyRequest<?>> setPropertyRequests, 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.

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

ASYNC_GET_DEFAULT_TIMEOUT_MS

Added in API level 34
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

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

STATUS_ERROR_INTERNAL_ERROR

Added in API level 34
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

Added in API level 34
public static final int STATUS_ERROR_NOT_AVAILABLE

Error indicating that the property is temporarily not available.

Constant Value: 2 (0x00000002)

STATUS_ERROR_TIMEOUT

Added in API level 34
public static final int STATUS_ERROR_TIMEOUT

Error indicating the operation has timed-out.

Constant Value: 3 (0x00000003)

Public methods

generateGetPropertyRequest

Added in API level 34
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

Added in API level 34
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

Added in API level 30
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 available in the vehicle for the selected area

getBooleanProperty

Added in API level 29
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 the property is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when the property 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

Added in API level 30
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 the property is not available

getFloatProperty

Added in API level 29
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 the property is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when the property 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

Added in API level 29
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 the property is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when the property 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

Added in API level 29
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 the property is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when the property 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

Added in API level 34
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

Added in API level 34
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

Added in API level 29
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 the property is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when the property 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.

getProperty

Added in API level 29
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 the property is temporarily not available and likely that retrying will be successful
PropertyNotAvailableException when the property is not available and might be unavailable for a while.
IllegalArgumentException when the [propertyId, areaId] is not supported for U and later client.

getPropertyList

Added in API level 29
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

getPropertyList

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

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

isPropertyAvailable

Added in API level 29
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

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 a callback for updates for a property for the first time, it will receive the property's current value via a change event upon registration if the property's value is currently available for reading. If the property is currently not available for reading or in error state, a property change event 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.

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 missing the appropriate permission.

setBooleanProperty

Added in API level 29
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

Added in API level 29
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

Added in API level 29
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

Added in API level 34
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 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.

setPropertiesAsync

Added in API level 34
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

setProperty

Added in API level 29
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.

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 the property is not available and might be unavailable for a while.
PropertyNotAvailableAndRetryException when the property is temporarily not available and likely that retrying will be successful.
IllegalArgumentException when the [propertyId, areaId] is not supported.

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.