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 |
interface |
CarPropertyManager.GetPropertyCallback
A callback |
class |
CarPropertyManager.GetPropertyRequest
A request for |
class |
CarPropertyManager.GetPropertyResult<T>
A successful result for |
class |
CarPropertyManager.PropertyAsyncError
An error result for |
interface |
CarPropertyManager.SetPropertyCallback
A callback |
class |
CarPropertyManager.SetPropertyRequest<T>
A request for |
class |
CarPropertyManager.SetPropertyResult
A successful result for |
interface |
CarPropertyManager.SupportedValuesChangeCallback
A callback interface to deliver value range change callbacks. |
Constants | |
|---|---|
long |
ASYNC_GET_DEFAULT_TIMEOUT_MS
The default timeout in MS for |
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)
Gets |
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. |
<T>
MinMaxSupportedValue<T>
|
getMinMaxSupportedValue(int propertyId, int areaId)
Gets the currently supported min/max value for [propertyId, areaId]. |
void
|
getPropertiesAsync(List<CarPropertyManager.GetPropertyRequest> getPropertyRequests, CancellationSignal cancellationSignal, Executor callbackExecutor, CarPropertyManager.GetPropertyCallback getPropertyCallback)
Query a list of |
void
|
getPropertiesAsync(List<CarPropertyManager.GetPropertyRequest> getPropertyRequests, long timeoutInMs, CancellationSignal cancellationSignal, Executor callbackExecutor, CarPropertyManager.GetPropertyCallback getPropertyCallback)
Query a list of |
<E>
CarPropertyValue<E>
|
getProperty(int propertyId, int areaId)
Query |
<E>
CarPropertyValue<E>
|
getProperty(Class<E> clazz, int propertyId, int areaId)
Return This method may take couple seconds to complete, so it needs to be called from a non-main thread. |
List<CarPropertyConfig<T>>
|
getPropertyList()
Returns all the list of properties supported by this car that the application may access. |
List<CarPropertyConfig<T>>
|
getPropertyList(ArraySet<Integer> propertyIds)
Checks the given property IDs and returns a list of property configs supported by the car. |
<T>
List<T>
|
getSupportedValuesList(int propertyId, int areaId)
Gets the currently supported values list for [propertyId, areaId]. |
boolean
|
isPropertyAvailable(int propertyId, int areaId)
Checks 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
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, if for the
Note: If the client has 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 If
Note:Caller must check the value of
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.
If the registration failed, this will return
If the property is not supported, this will return
If the property is supported and the caller does not have read or write permission to it,
this will return
If the caller has write permission but does not have read permission, this will throw
Note that the callback will be executed on the event handler provided to the
If one |
boolean
|
registerSupportedValuesChangeCallback(int propertyId, Executor callbackExecutor, CarPropertyManager.SupportedValuesChangeCallback cb)
Registers a callback that will be called when min or max or supported value list for any areaIds for the propertyId changes. |
boolean
|
registerSupportedValuesChangeCallback(int propertyId, CarPropertyManager.SupportedValuesChangeCallback cb)
Registers a callback that will be called when min or max or supported value list for any areaIds for the propertyId changes. |
boolean
|
registerSupportedValuesChangeCallback(int propertyId, int areaId, Executor callbackExecutor, CarPropertyManager.SupportedValuesChangeCallback cb)
Registers a callback that will be called when min or max or supported value list for [propertyId, areaId] changes. |
boolean
|
registerSupportedValuesChangeCallback(int propertyId, int areaId, CarPropertyManager.SupportedValuesChangeCallback cb)
Registers a callback that will be called when min or max or supported value list for [propertyId, areaId] changes. |
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
|
void
|
unregisterCallback(CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback, int propertyId)
This method is deprecated.
Use
|
void
|
unregisterSupportedValuesChangeCallback(int propertyId, CarPropertyManager.SupportedValuesChangeCallback cb)
Unregisters the specific callback for the property ID. |
void
|
unregisterSupportedValuesChangeCallback(int propertyId, int areaId, CarPropertyManager.SupportedValuesChangeCallback cb)
Unregisters the specific callback for the [propertyId, areaId]. |
void
|
unregisterSupportedValuesChangeCallback(int propertyId)
Unregisters all value range change callbacks for the property ID Do nothing if no callbacks was registered before. |
void
|
unsubscribePropertyEvents(CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)
Stop getting property updates for the given |
void
|
unsubscribePropertyEvents(int propertyId, CarPropertyManager.CarPropertyEventCallback carPropertyEventCallback)
Stop getting update for |
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_INFOSWITCH_USERCREATE_USERREMOVE_USERUSER_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.
CarInternalErrorExceptionwhen there is an unexpected error detected in carsPropertyAccessDeniedSecurityExceptionwhen cars denied the access of the propertyPropertyNotAvailableAndRetryExceptionwhen the property is temporarily not available and likely that retrying will be successfulPropertyNotAvailableExceptionwhen the property is not available and might be unavailable for a while.IllegalArgumentExceptionwhen the [propertyId, areaId] is not supported or when the property is of wrong type.
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.
CarInternalErrorExceptionwhen there is an unexpected error detected in carsPropertyAccessDeniedSecurityExceptionwhen cars denied the access of the propertyPropertyNotAvailableAndRetryExceptionwhen the property is temporarily not available and likely that retrying will be successfulPropertyNotAvailableExceptionwhen the property is not available and might be unavailable for a while.IllegalArgumentExceptionwhen the property is of wrong type.falsewhen the [propertyId, areaId] is not supported
Clients that declare a ApplicationInfo.targetSdkVersion
earlier than Build.VERSION_CODES.R will receive the following exceptions or
false when request failed.
IllegalStateExceptionwhen 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.IllegalArgumentExceptionwhen the property is of wrong type.falsewhen the [propertyId, areaId] is not supported or when the property is temporarily not available.
For pre-R client, if the property is temporarily not available, this will return
false.
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 | |
|---|---|
IllegalStateException |
when there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens for pre-R clients. |
CarInternalErrorException |
when there is an unexpected error detected in cars for R and later clients. |
PropertyAccessDeniedSecurityException |
when cars denied the access of the property for R and later clients. |
PropertyNotAvailableAndRetryException |
when [propertyId, areaId] is temporarily not available and likely that retrying will be successful for R and later clients. |
PropertyNotAvailableException |
when [propertyId, areaId] is not available and might be unavailable for a while for R and later clients. |
IllegalArgumentException |
when the [propertyId, areaId] is not supported for U and later client, or when the specified class does not match the property type. |
SecurityException |
when the client does not have the required read permission to access the [propertyId, areaId]. |
getCarPropertyConfig
public CarPropertyConfig<?> getCarPropertyConfig (int propertyId)
Gets 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).
For pre-R client, if the property is temporarily not available, this will return
0.
For pre-U client, when the [propertyId, areaId] is not supported, this will return
0.
| 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 | |
|---|---|
IllegalStateException |
when there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens for pre-R clients. |
CarInternalErrorException |
when there is an unexpected error detected in cars for R and later clients. |
PropertyAccessDeniedSecurityException |
when cars denied the access of the property for R and later clients. |
PropertyNotAvailableAndRetryException |
when [propertyId, areaId] is temporarily not available and likely that retrying will be successful for R and later clients. |
PropertyNotAvailableException |
when [propertyId, areaId] is not available and might be unavailable for a while for R and later clients. |
IllegalArgumentException |
when the [propertyId, areaId] is not supported for U and later client, or when the specified class does not match the property type. |
SecurityException |
when the client does not have the required read permission to access the [propertyId, areaId]. |
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).
For pre-R client, if the property is temporarily not available, this will return an empty array.
For pre-U client, when the [propertyId, areaId] is not supported, this will return an empty array.
| 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).
For pre-R client, if the property is temporarily not available, this will return
0.
For pre-U client, when the [propertyId, areaId] is not supported, this will return
0.
| 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 | |
|---|---|
IllegalStateException |
when there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens for pre-R clients. |
CarInternalErrorException |
when there is an unexpected error detected in cars for R and later clients. |
PropertyAccessDeniedSecurityException |
when cars denied the access of the property for R and later clients. |
PropertyNotAvailableAndRetryException |
when [propertyId, areaId] is temporarily not available and likely that retrying will be successful for R and later clients. |
PropertyNotAvailableException |
when [propertyId, areaId] is not available and might be unavailable for a while for R and later clients. |
IllegalArgumentException |
when the [propertyId, areaId] is not supported for U and later client, or when the specified class does not match the property type. |
SecurityException |
when the client does not have the required read permission to access the [propertyId, areaId]. |
getMinMaxSupportedValue
public MinMaxSupportedValue<T> getMinMaxSupportedValue (int propertyId, int areaId)
Gets the currently supported min/max value for [propertyId, areaId].
This is only meaningful if AreaIdConfig.hasMinSupportedValue or
AreaIdConfig.hasMaxSupportedValue returns true.
Unless mentioned otherwise in property definition, this function is only meaningful for int32, int64, float property types.
For certain properties, AreaIdConfig.hasMinSupportedValue and
AreaIdConfig.hasMaxSupportedValue always returns
true and you could always use this function to get min/max value in normal cases,
e.g. EV_BRAKE_REGENERATION_LEVEL. Check VehiclePropertyIds documentation for
more detail.
Note that the returned value range is a super-set applies for both values
set to vehicle hardware and values read from vehicle hardware. The value
range may change dynamically so it is still possible to get
IllegalArgumentException for
CarPropertyManager.setProperty even though the value to set is
within the value range.
Caller should use CarPropertyManager.registerSupportedValuesChangeCallback to
register for supported value change.
| Parameters | |
|---|---|
propertyId |
int |
areaId |
int |
| Returns | |
|---|---|
MinMaxSupportedValue<T> |
The currently supported min/max value. |
| Throws | |
|---|---|
IllegalArgumentException |
if [propertyId, areaId] is not supported. |
SecurityException |
if the caller does not have either read or write access to the property. |
CarInternalErrorException |
if failed to get the information from the hardware. |
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_INFOSWITCH_USERCREATE_USERREMOVE_USERUSER_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.
CarInternalErrorExceptionwhen there is an unexpected error detected in carsPropertyAccessDeniedSecurityExceptionwhen cars denied the access of the [propertyId, areaId].PropertyNotAvailableAndRetryExceptionwhen the [propertyId, areaId] is temporarily not available and likely that retrying will be successfulPropertyNotAvailableExceptionwhen the [propertyId, areaId] is not available and might be unavailable for a while.IllegalArgumentExceptionwhen the [propertyId, areaId] is not supported or when the specified class does not match the property type.
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.
CarInternalErrorExceptionwhen there is an unexpected error detected in carsPropertyAccessDeniedSecurityExceptionwhen cars denied the access of the [propertyId, areaId].PropertyNotAvailableAndRetryExceptionwhen the [propertyId, areaId] is temporarily not available and likely that retrying will be successfulPropertyNotAvailableExceptionwhen the [propertyId, areaId] is not available and might be unavailable for a while.IllegalArgumentExceptionwhen the specified class does not match the property type.nullwhen the [propertyId, areaId] is not supported
Clients that declare a ApplicationInfo.targetSdkVersion
earlier than Build.VERSION_CODES.R will receive the following exceptions or
null when request failed.
IllegalStateExceptionwhen there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens.IllegalArgumentExceptionwhen the specified class does not match the property type.nullwhen 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 | |
|---|---|
IllegalStateException |
when there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens for pre-R clients. |
CarInternalErrorException |
when there is an unexpected error detected in cars for R and later clients. |
PropertyAccessDeniedSecurityException |
when cars denied the access of the property for R and later clients. |
PropertyNotAvailableAndRetryException |
when [propertyId, areaId] is temporarily not available and likely that retrying will be successful for R and later clients. |
PropertyNotAvailableException |
when [propertyId, areaId] is not available and might be unavailable for a while for R and later clients. |
IllegalArgumentException |
when the [propertyId, areaId] is not supported for U and later client, or when the specified class does not match the property type. |
SecurityException |
when the client does not have the required read permission to access the [propertyId, areaId]. |
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_INFOSWITCH_USERCREATE_USERREMOVE_USERUSER_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.
CarInternalErrorExceptionwhen there is an unexpected error detected in carsPropertyAccessDeniedSecurityExceptionwhen cars denied the access of the [propertyId, areaId].PropertyNotAvailableAndRetryExceptionwhen the [propertyId, areaId] is temporarily not available and likely that retrying will be successfulPropertyNotAvailableExceptionwhen the [propertyId, areaId] is not available and might be unavailable for a while.IllegalArgumentExceptionwhen the [propertyId, areaId] is not supported or when the specified class does not match the property type.
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.
CarInternalErrorExceptionwhen there is an unexpected error detected in carsPropertyAccessDeniedSecurityExceptionwhen cars denied the access of the [propertyId, areaId].PropertyNotAvailableAndRetryExceptionwhen the [propertyId, areaId] is temporarily not available and likely that retrying will be successfulPropertyNotAvailableExceptionwhen the [propertyId, areaId] is not available and might be unavailable for a while.IllegalArgumentExceptionwhen the specified class does not match the property type.nullwhen the [propertyId, areaId] is not supported
Clients that declare a ApplicationInfo.targetSdkVersion
earlier than Build.VERSION_CODES.R will receive the following exceptions or
null when request failed.
IllegalStateExceptionwhen there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens.IllegalArgumentExceptionwhen the specified class does not match the property type.nullwhen 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 | |
|---|---|
IllegalStateException |
when there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens for pre-R clients. |
CarInternalErrorException |
when there is an unexpected error detected in cars for R and later clients. |
PropertyAccessDeniedSecurityException |
when cars denied the access of the property for R and later clients. |
PropertyNotAvailableAndRetryException |
when [propertyId, areaId] is temporarily not available and likely that retrying will be successful for R and later clients. |
PropertyNotAvailableException |
when [propertyId, areaId] is not available and might be unavailable for a while for R and later clients. |
IllegalArgumentException |
when the [propertyId, areaId] is not supported for U and later client, or when the specified class does not match the property type. |
SecurityException |
when the client does not have the required read permission to access the [propertyId, areaId]. |
getPropertyList
public List<CarPropertyConfig<T>> getPropertyList ()
Returns all the list of properties supported by this car that the application may access. If the caller does not have read/write access to some of the properties, then they will not be returned as part of the list, even if the properties are supported by the vehicle.
| Returns | |
|---|---|
List<CarPropertyConfig<T>> |
the property config list. |
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 or if the caller does not own the read/write permission to access them, they will not be returned.
| Parameters | |
|---|---|
propertyIds |
ArraySet: the list of property IDs |
| Returns | |
|---|---|
List<CarPropertyConfig<T>> |
the list of property configs |
getSupportedValuesList
public List<T> getSupportedValuesList (int propertyId,
int areaId)Gets the currently supported values list for [propertyId, areaId].
This is only meaningful if AreaIdConfig.hasSupportedValuesList returns
true.
For certain properties, AreaIdConfig.hasSupportedValuesList always returns
true and you could always use this function to get supported values in normal cases,
e.g. GEAR_SELECTION. Check VehiclePropertyIds documentation for
more detail.
Note that the returned value range is a super-set applies for both values
set to vehicle hardware and values read from vehicle hardware. The value
range may change dynamically so it is still possible to get
IllegalArgumentException for
CarPropertyManager.setProperty even though the value to set is
within the value range.
Caller should use CarPropertyManager.registerSupportedValuesChangeCallback to
register for supported value list change.
The returned supported value list is in sorted ascending order if the property is of type int32, int64 or float.
| Parameters | |
|---|---|
propertyId |
int |
areaId |
int |
| Returns | |
|---|---|
List<T> |
The immutable supported values. null if no supported values are currently
specified. If this returns an empty set, it means no values are supported now
(the property is probably in an error state). |
| Throws | |
|---|---|
IllegalArgumentException |
if [propertyId, areaId] is not supported. |
SecurityException |
if the caller does not have either read or write access to the property. |
CarInternalErrorException |
if failed to get the information from the hardware. |
isPropertyAvailable
public boolean isPropertyAvailable (int propertyId,
int areaId)Checks 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) |
| Throws | |
|---|---|
SecurityException |
if the client does not have the required read permission to access the [propertyId, areaId]. |
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:
CarPropertyManager.SENSOR_RATE_ONCHANGECarPropertyManager.SENSOR_RATE_NORMALCarPropertyManager.SENSOR_RATE_UICarPropertyManager.SENSOR_RATE_FASTCarPropertyManager.SENSOR_RATE_FASTEST
Note:Rate has no effect if the property has one of the following change modes:
CarPropertyConfig.VEHICLE_PROPERTY_CHANGE_MODE_STATICCarPropertyConfig.VEHICLE_PROPERTY_CHANGE_MODE_ONCHANGE
Note: When this function is called, if for the CarPropertyManager instance,
this is the first callback registered for the property, it 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.
Note: If the client has ApplicationInfo.targetSdkVersion <
16, if the client calls this function after the property is already registered
(aka, this is not the first callback registered for the property),
it is not guaranteed that the initial current-value event will be generated. If the client
has ApplicationInfo.targetSdkVersion > 16, it is guaranteed that
the initial current-value event will always be generated for every call.
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. |
registerSupportedValuesChangeCallback
public boolean registerSupportedValuesChangeCallback (int propertyId,
Executor callbackExecutor,
CarPropertyManager.SupportedValuesChangeCallback cb)Registers a callback that will be called when min or max or supported value list for any areaIds for the propertyId changes.
One callback must only be associated with one executor.
If a different callback was previously registered for this property, this adds a new callback.
| Parameters | |
|---|---|
propertyId |
int: The property ID. |
callbackExecutor |
Executor: The executor in which the callback is done on. One callback is only
allowed to be associated with one executor. |
cb |
CarPropertyManager.SupportedValuesChangeCallback: The callback to deliver value range change events. |
| Returns | |
|---|---|
boolean |
true if registered successfully. |
| Throws | |
|---|---|
IllegalArgumentException |
if the property ID is not supported. |
IllegalArgumentException |
if the callback was previously associated with a different executor. |
registerSupportedValuesChangeCallback
public boolean registerSupportedValuesChangeCallback (int propertyId,
CarPropertyManager.SupportedValuesChangeCallback cb)Registers a callback that will be called when min or max or supported value list for any areaIds for the propertyId changes.
If a different callback was previously registered for this property, this adds a new callback.
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 property ID. |
cb |
CarPropertyManager.SupportedValuesChangeCallback: The callback to deliver value range change events. |
| Returns | |
|---|---|
boolean |
true if registered successfully. |
| Throws | |
|---|---|
IllegalArgumentException |
if the property ID is not supported. |
registerSupportedValuesChangeCallback
public boolean registerSupportedValuesChangeCallback (int propertyId,
int areaId,
Executor callbackExecutor,
CarPropertyManager.SupportedValuesChangeCallback cb)Registers a callback that will be called when min or max or supported value list for [propertyId, areaId] changes.
One callback must only be associated with one executor.
If a different callback was previously registered for [propertyId, areaId], this adds a new callback.
| Parameters | |
|---|---|
propertyId |
int: The property ID. |
areaId |
int: The area ID. |
callbackExecutor |
Executor: The executor in which the callback is done on. |
cb |
CarPropertyManager.SupportedValuesChangeCallback: The callback to deliver value range change events. |
| Returns | |
|---|---|
boolean |
true if registers successfully. |
| Throws | |
|---|---|
IllegalArgumentException |
if [propertyId, areaId] is not supported. |
IllegalArgumentException |
if the callback was previously associated with a different executor. |
registerSupportedValuesChangeCallback
public boolean registerSupportedValuesChangeCallback (int propertyId,
int areaId,
CarPropertyManager.SupportedValuesChangeCallback cb)Registers a callback that will be called when min or max or supported value list for [propertyId, areaId] changes.
If a different callback was previously registered for [propertyId, areaId], this adds a new callback.
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 property ID. |
areaId |
int: The area ID. |
cb |
CarPropertyManager.SupportedValuesChangeCallback: The callback to deliver value range change events. |
| Returns | |
|---|---|
boolean |
true if registers successfully. |
| Throws | |
|---|---|
IllegalArgumentException |
if [propertyId, areaId] is not supported. |
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 |
| Throws | |
|---|---|
RuntimeException |
when the [propertyId, areaId] is temporarily not available for pre-R clients. |
IllegalStateException |
when there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens for pre-R clients. |
CarInternalErrorException |
when there is an unexpected error detected in cars for R and later clients. |
PropertyAccessDeniedSecurityException |
when cars denied the access of the property for R and later clients. |
PropertyNotAvailableException |
when [propertyId, areaId] is not available and might be unavailable for a while for R and later clients. |
PropertyNotAvailableAndRetryException |
when [propertyId, areaId] is temporarily not available and likely that retrying will be successful for R and later clients. |
IllegalArgumentException |
when the [propertyId, areaId] or value is not supported. |
SecurityException |
when the client does not have the required write permission to access the [propertyId, areaId]. |
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 |
| Throws | |
|---|---|
RuntimeException |
when the [propertyId, areaId] is temporarily not available for pre-R clients. |
IllegalStateException |
when there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens for pre-R clients. |
CarInternalErrorException |
when there is an unexpected error detected in cars for R and later clients. |
PropertyAccessDeniedSecurityException |
when cars denied the access of the property for R and later clients. |
PropertyNotAvailableException |
when [propertyId, areaId] is not available and might be unavailable for a while for R and later clients. |
PropertyNotAvailableAndRetryException |
when [propertyId, areaId] is temporarily not available and likely that retrying will be successful for R and later clients. |
IllegalArgumentException |
when the [propertyId, areaId] or value is not supported. |
SecurityException |
when the client does not have the required write permission to access the [propertyId, areaId]. |
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 |
| Throws | |
|---|---|
RuntimeException |
when the [propertyId, areaId] is temporarily not available for pre-R clients. |
IllegalStateException |
when there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens for pre-R clients. |
CarInternalErrorException |
when there is an unexpected error detected in cars for R and later clients. |
PropertyAccessDeniedSecurityException |
when cars denied the access of the property for R and later clients. |
PropertyNotAvailableException |
when [propertyId, areaId] is not available and might be unavailable for a while for R and later clients. |
PropertyNotAvailableAndRetryException |
when [propertyId, areaId] is temporarily not available and likely that retrying will be successful for R and later clients. |
IllegalArgumentException |
when the [propertyId, areaId] or value is not supported. |
SecurityException |
when the client does not have the required write permission to access the [propertyId, areaId]. |
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.
CarInternalErrorExceptionPropertyAccessDeniedSecurityExceptionPropertyNotAvailableAndRetryExceptionPropertyNotAvailableExceptionIllegalArgumentException
Clients that declare a ApplicationInfo.targetSdkVersion
earlier than Build.VERSION_CODES.R will receive the following exceptions when request
failed.
RuntimeExceptionwhen the [propertyId, areaId] is temporarily not available.IllegalStateExceptionwhen there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [property, areaId} is not available and might be unavailable for a while, or when unexpected error happens.IllegalArgumentExceptionwhen 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 | |
|---|---|
RuntimeException |
when the [propertyId, areaId] is temporarily not available for pre-R clients. |
IllegalStateException |
when there is an error detected in cars, or when cars denied the access of the [propertyId, areaId], or when the [propertyId, areaId] is not available and might be unavailable for a while, or when unexpected error happens for pre-R clients. |
CarInternalErrorException |
when there is an unexpected error detected in cars for R and later clients. |
PropertyAccessDeniedSecurityException |
when cars denied the access of the property for R and later clients. |
PropertyNotAvailableException |
when [propertyId, areaId] is not available and might be unavailable for a while for R and later clients. |
PropertyNotAvailableAndRetryException |
when [propertyId, areaId] is temporarily not available and likely that retrying will be successful for R and later clients. |
IllegalArgumentException |
when the [propertyId, areaId] or value is not supported. |
SecurityException |
when the client does not have the required write permission to access the [propertyId, areaId]. |
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, if for the CarPropertyManager instance,
this is the first callback registered for the [propertyId, areaId], it 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: If the client has ApplicationInfo.targetSdkVersion <
16, if the client calls this function after the [propertyId, areaId] is already registered
(aka, this is not the first callback registered for the [propertyId, areaId]),
it is not guaranteed that the initial current-value event will be generated. If the client
has ApplicationInfo.targetSdkVersion > 16, it is guaranteed that
the initial current-value event will always be generated for every call.
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. (E.G. A callback cannot have multiple executors)
Note:Rate has no effect if the property has one of the following change modes:
CarPropertyConfig.VEHICLE_PROPERTY_CHANGE_MODE_STATICCarPropertyConfig.VEHICLE_PROPERTY_CHANGE_MODE_ONCHANGE
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. |
unregisterSupportedValuesChangeCallback
public void unregisterSupportedValuesChangeCallback (int propertyId,
CarPropertyManager.SupportedValuesChangeCallback cb)Unregisters the specific callback for the property ID.
Do nothing if the callback was not registered before.
| Parameters | |
|---|---|
propertyId |
int: The property ID. |
cb |
CarPropertyManager.SupportedValuesChangeCallback: The callback to unregister. |
| Throws | |
|---|---|
IllegalArgumentException |
if the propertyId is not supported. |
unregisterSupportedValuesChangeCallback
public void unregisterSupportedValuesChangeCallback (int propertyId,
int areaId,
CarPropertyManager.SupportedValuesChangeCallback cb)Unregisters the specific callback for the [propertyId, areaId].
Do nothing if the callback was not registered before.
| Parameters | |
|---|---|
propertyId |
int: The property ID. |
areaId |
int: The area ID. |
cb |
CarPropertyManager.SupportedValuesChangeCallback: The callback to unregister. |
| Throws | |
|---|---|
IllegalArgumentException |
if the [propertyId, areaId] is not supported. |
unregisterSupportedValuesChangeCallback
public void unregisterSupportedValuesChangeCallback (int propertyId)
Unregisters all value range change callbacks for the property ID
Do nothing if no callbacks was registered before.
| Parameters | |
|---|---|
propertyId |
int: The property ID. |
| Throws | |
|---|---|
IllegalArgumentException |
if the propertyId is not supported. |
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. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-10-09 UTC.