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 hardware/interfaces/automotive/vehicle/types.hal
Summary
Nested classes | |
---|---|
interface |
CarPropertyManager.CarPropertyEventCallback
Application registers |
Constants | |
---|---|
int |
CAR_SET_PROPERTY_ERROR_CODE_ACCESS_DENIED
Status to indicate that set operation failed because car denied access to the property. |
int |
CAR_SET_PROPERTY_ERROR_CODE_INVALID_ARG
Status to indicate that set operation failed because of an invalid argument. |
int |
CAR_SET_PROPERTY_ERROR_CODE_PROPERTY_NOT_AVAILABLE
Status to indicate that set operation failed because the property is not available. |
int |
CAR_SET_PROPERTY_ERROR_CODE_TRY_AGAIN
Status to indicate that set operation failed. |
int |
CAR_SET_PROPERTY_ERROR_CODE_UNKNOWN
Status to indicate that set operation failed because of an general error in cars. |
float |
SENSOR_RATE_FAST
Read sensors at the rate of 10 hertz |
float |
SENSOR_RATE_FASTEST
Read sensors at the rate of 100 hertz |
float |
SENSOR_RATE_NORMAL
Read sensors at the rate of 1 hertz |
float |
SENSOR_RATE_ONCHANGE
Read ON_CHANGE sensors |
float |
SENSOR_RATE_UI
Read sensors at the rate of 5 hertz |
Public methods | |
---|---|
int
|
getAreaId(int propId, int area)
Returns areaId contains the seletcted area for the property. |
boolean
|
getBooleanProperty(int prop, int area)
Returns value of a bool property This method may take couple seconds to complete, so it needs to be called from an non-main thread. |
CarPropertyConfig<?>
|
getCarPropertyConfig(int propId)
Get CarPropertyConfig by property Id. |
float
|
getFloatProperty(int prop, int area)
Returns value of a float property This method may take couple seconds to complete, so it needs to be called from an non-main thread. |
int[]
|
getIntArrayProperty(int prop, int area)
Returns value of a integer array property This method may take couple seconds to complete, so it needs to be called from an non-main thread. |
int
|
getIntProperty(int prop, int area)
Returns value of a integer property This method may take couple seconds to complete, so it needs to be called form an non-main thread. |
<E>
CarPropertyValue<E>
|
getProperty(Class<E> clazz, int propId, int areaId)
Return CarPropertyValue This method may take couple seconds to complete, so it needs to be called from an non-main thread. |
<E>
CarPropertyValue<E>
|
getProperty(int propId, int areaId)
Query CarPropertyValue with property id and areaId. |
List<CarPropertyConfig>
|
getPropertyList(ArraySet<Integer> propertyIds)
|
List<CarPropertyConfig>
|
getPropertyList()
|
boolean
|
isPropertyAvailable(int propId, int area)
Check whether a given property is available or disabled based on the car's current state. |
boolean
|
registerCallback(CarPropertyManager.CarPropertyEventCallback callback, int propertyId, float rate)
Register |
void
|
setBooleanProperty(int prop, int areaId, boolean val)
Modifies a property. |
void
|
setFloatProperty(int prop, int areaId, float val)
Set float value of property This method may take couple seconds to complete, so it needs to be called from an non-main thread. |
void
|
setIntProperty(int prop, int areaId, int val)
Set int value of property This method may take couple seconds to complete, so it needs to be called from an non-main thread. |
<E>
void
|
setProperty(Class<E> clazz, int propId, int areaId, E val)
Set value of car property by areaId. |
void
|
unregisterCallback(CarPropertyManager.CarPropertyEventCallback callback)
Stop getting property update for the given callback. |
void
|
unregisterCallback(CarPropertyManager.CarPropertyEventCallback callback, int propertyId)
Stop getting property update for the given callback and property. |
Inherited methods | |
---|---|
Constants
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 an 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 ON_CHANGE 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
Public methods
getAreaId
public int getAreaId (int propId, int area)
Returns areaId contains the seletcted area for the property.
Parameters | |
---|---|
propId |
int : Property ID |
area |
int : Area enum such as Enums in VehicleAreaSeat . |
Returns | |
---|---|
int |
AreaId contains the selected area for the property. |
Throws | |
---|---|
IllegalArgumentException |
if the property is not available in the vehicle for the selected area. |
getBooleanProperty
public boolean getBooleanProperty (int prop, int area)
Returns value of a bool property
This method may take couple seconds to complete, so it needs to be called from an non-main thread.
Parameters | |
---|---|
prop |
int : Property ID to get |
area |
int : Area of the property to get |
Returns | |
---|---|
boolean |
value of a bool property. |
getCarPropertyConfig
public CarPropertyConfig<?> getCarPropertyConfig (int propId)
Get CarPropertyConfig by property Id.
Parameters | |
---|---|
propId |
int : Property ID |
Returns | |
---|---|
CarPropertyConfig<?> |
CarPropertyConfig for the selected property.
Null if the property is not available. |
getFloatProperty
public float getFloatProperty (int prop, int area)
Returns value of a float property
This method may take couple seconds to complete, so it needs to be called from an non-main thread.
Parameters | |
---|---|
prop |
int : Property ID to get |
area |
int : Area of the property to get |
Returns | |
---|---|
float |
getIntArrayProperty
public int[] getIntArrayProperty (int prop, int area)
Returns value of a integer array property
This method may take couple seconds to complete, so it needs to be called from an non-main thread.
Parameters | |
---|---|
prop |
int : Property ID to get |
area |
int : Zone of the property to get |
Returns | |
---|---|
int[] |
getIntProperty
public int getIntProperty (int prop, int area)
Returns value of a integer property
This method may take couple seconds to complete, so it needs to be called form an non-main thread.
Parameters | |
---|---|
prop |
int : Property ID to get |
area |
int : Zone of the property to get |
Returns | |
---|---|
int |
getProperty
public CarPropertyValue<E> getProperty (Class<E> clazz, int propId, int areaId)
Return CarPropertyValue
This method may take couple seconds to complete, so it needs to be called from an non-main thread.
Clients that declare a ApplicationInfo.targetSdkVersion
equal
or later than Build.VERSION_CODES#R
will receive the following exceptions when
request is failed.
CarInternalErrorException
PropertyAccessDeniedSecurityException
PropertyNotAvailableAndRetryException
PropertyNotAvailableException
IllegalArgumentException
Clients that declare a ApplicationInfo.targetSdkVersion
earlier than Build.VERSION_CODES#R
will receive the following exceptions when request
is failed.
IllegalStateException
when there is an error detected in cars.IllegalArgumentException
when the property in the areaId is not supplied.
Parameters | |
---|---|
clazz |
Class : The class object for the CarPropertyValue |
propId |
int : Property ID to get |
areaId |
int : Zone of the property to get |
Returns | |
---|---|
CarPropertyValue<E> |
CarPropertyValue. Null if property's id is invalid. |
Throws | |
---|---|
|
android.car.hardware.property.CarInternalErrorException CarInternalErrorException} when there is an error detected in cars. |
|
android.car.hardware.property.PropertyAccessDeniedSecurityException PropertyAccessDeniedSecurityException} when cars denied the access of the property. |
|
android.car.hardware.property.PropertyNotAvailableAndRetryException PropertyNotAvailableAndRetryException} when the property is temporarily not available and likely that retrying will be successful. |
|
android.car.hardware.property.PropertyNotAvailableException PropertyNotAvailableException} when the property is temporarily not available. |
|
java.lang.IllegalArgumentException IllegalArgumentException} when the property in the areaId is not supplied. |
getProperty
public CarPropertyValue<E> getProperty (int propId, int areaId)
Query CarPropertyValue with property id and areaId.
This method may take couple seconds to complete, so it needs to be called from an non-main thread.
Clients that declare a ApplicationInfo.targetSdkVersion
equal
or later than Build.VERSION_CODES#R
will receive the following exceptions when
request is failed.
CarInternalErrorException
PropertyAccessDeniedSecurityException
PropertyNotAvailableAndRetryException
PropertyNotAvailableException
IllegalArgumentException
Clients that declare a ApplicationInfo.targetSdkVersion
earlier than Build.VERSION_CODES#R
will receive the following exceptions when request
is failed.
IllegalStateException
when there is an error detected in cars.IllegalArgumentException
when the property in the areaId is not supplied.
Parameters | |
---|---|
propId |
int : Property Id |
areaId |
int : areaId |
Returns | |
---|---|
CarPropertyValue<E> |
CarPropertyValue. Null if property's id is invalid. |
Throws | |
---|---|
|
android.car.hardware.property.CarInternalErrorException CarInternalErrorException} when there is an error detected in cars. |
|
android.car.hardware.property.PropertyAccessDeniedSecurityException PropertyAccessDeniedSecurityException} when cars denied the access of the property. |
|
android.car.hardware.property.PropertyNotAvailableAndRetryException PropertyNotAvailableAndRetryException} when the property is temporarily not available and likely that retrying will be successful. |
|
android.car.hardware.property.PropertyNotAvailableException PropertyNotAvailableException} when the property is temporarily not available. |
|
java.lang.IllegalArgumentException IllegalArgumentException} when the property in the areaId is not supplied. |
getPropertyList
public List<CarPropertyConfig> getPropertyList (ArraySet<Integer> propertyIds)
Parameters | |
---|---|
propertyIds |
ArraySet : property ID list |
Returns | |
---|---|
List<CarPropertyConfig> |
List of properties implemented by this car in given property ID list that application may access. |
getPropertyList
public List<CarPropertyConfig> getPropertyList ()
Returns | |
---|---|
List<CarPropertyConfig> |
List of properties implemented by this car that the application may access. |
isPropertyAvailable
public boolean isPropertyAvailable (int propId, int area)
Check whether a given property is available or disabled based on the car's current state.
Parameters | |
---|---|
propId |
int : Property Id |
area |
int : AreaId of property |
Returns | |
---|---|
boolean |
true if STATUS_AVAILABLE, false otherwise (eg STATUS_UNAVAILABLE) |
registerCallback
public boolean registerCallback (CarPropertyManager.CarPropertyEventCallback callback, int propertyId, float rate)
Register CarPropertyEventCallback
to get property updates. Multiple listeners
can be registered for a single property or the same listener can be used for different
properties. If the same listener is registered again for the same property, it will be
updated to new rate.
Rate could be one of the following:
CarPropertyManager#SENSOR_RATE_ONCHANGE
CarPropertyManager#SENSOR_RATE_NORMAL
CarPropertyManager#SENSOR_RATE_UI
CarPropertyManager#SENSOR_RATE_FAST
CarPropertyManager#SENSOR_RATE_FASTEST
Note:Rate has no effect if the property has one of the following change modes:
CarPropertyConfig#VEHICLE_PROPERTY_CHANGE_MODE_STATIC
CarPropertyConfig#VEHICLE_PROPERTY_CHANGE_MODE_ONCHANGE
CarPropertyConfig#getChangeMode()
for details.
If rate is higher than CarPropertyConfig#getMaxSampleRate()
, it will be registered
with max sample rate.
If rate is lower than CarPropertyConfig#getMinSampleRate()
, it will be registered
with min sample rate.
Parameters | |
---|---|
callback |
CarPropertyManager.CarPropertyEventCallback : CarPropertyEventCallback to be registered. |
propertyId |
int : PropertyId to subscribe |
rate |
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
public void setBooleanProperty (int prop, int areaId, boolean val)
Modifies a property. If the property modification doesn't occur, an error event shall be generated and propagated back to the application.
This method may take couple seconds to complete, so it needs to be called from an non-main thread.
Parameters | |
---|---|
prop |
int : Property ID to modify |
areaId |
int : AreaId to apply the modification. |
val |
boolean : Value to set |
setFloatProperty
public void setFloatProperty (int prop, int areaId, float val)
Set float value of property
This method may take couple seconds to complete, so it needs to be called from an non-main thread.
Parameters | |
---|---|
prop |
int : Property ID to modify |
areaId |
int : AreaId to apply the modification |
val |
float : Value to set |
setIntProperty
public void setIntProperty (int prop, int areaId, int val)
Set int value of property
This method may take couple seconds to complete, so it needs to be called from an non-main thread.
Parameters | |
---|---|
prop |
int : Property ID to modify |
areaId |
int : AreaId to apply the modification |
val |
int : Value to set |
setProperty
public void setProperty (Class<E> clazz, int propId, int areaId, E val)
Set value of car property by areaId.
If multiple clients set a property for the same area id simultaneously, which one takes precedence is undefined. Typically, the last set operation (in the order that they are issued to the car's ECU) overrides the previous set operations.
This method may take couple seconds to complete, so it needs to be called form an non-main thread.
Clients that declare a ApplicationInfo.targetSdkVersion
equal
or later than Build.VERSION_CODES#R
will receive the following exceptions when
request is failed.
CarInternalErrorException
PropertyAccessDeniedSecurityException
PropertyNotAvailableAndRetryException
PropertyNotAvailableException
IllegalArgumentException
Clients that declare a ApplicationInfo.targetSdkVersion
earlier than Build.VERSION_CODES#R
will receive the following exceptions when request
is failed.
RuntimeException
when the property is temporarily not available.IllegalStateException
when there is an error detected in cars.IllegalArgumentException
when the property in the areaId is not supplied
Parameters | |
---|---|
clazz |
Class : The class object for the CarPropertyValue |
propId |
int : Property ID |
areaId |
int : areaId |
val |
E : Value of CarPropertyValue |
Throws | |
---|---|
|
android.car.hardware.property.CarInternalErrorException CarInternalErrorException} when there is an error detected in cars. |
|
android.car.hardware.property.PropertyAccessDeniedSecurityException PropertyAccessDeniedSecurityException} when cars denied the access of the property. |
|
android.car.hardware.property.PropertyNotAvailableException PropertyNotAvailableException} when the property is temporarily not available. |
|
android.car.hardware.property.PropertyNotAvailableAndRetryException PropertyNotAvailableAndRetryException} when the property is temporarily not available and likely that retrying will be successful. |
|
java.lang.IllegalStateException IllegalStateException} when get an unexpected error code. |
|
java.lang.IllegalArgumentException IllegalArgumentException} when the property in the areaId is not supplied. |
unregisterCallback
public void unregisterCallback (CarPropertyManager.CarPropertyEventCallback callback)
Stop getting property update for the given callback. If there are multiple registrations for this callback, all listening will be stopped.
Parameters | |
---|---|
callback |
CarPropertyManager.CarPropertyEventCallback : CarPropertyEventCallback to be unregistered. |
unregisterCallback
public void unregisterCallback (CarPropertyManager.CarPropertyEventCallback callback, int propertyId)
Stop getting property update for the given callback and property. If the same callback is used for other properties, those subscriptions will not be affected.
Parameters | |
---|---|
callback |
CarPropertyManager.CarPropertyEventCallback : CarPropertyEventCallback to be unregistered. |
propertyId |
int : PropertyId to be unregistered. |
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 2023-01-18 UTC.