Subscription.Builder
public
static
final
class
Subscription.Builder
extends Object
java.lang.Object | |
↳ | android.car.hardware.property.Subscription.Builder |
Builder for Subscription
Summary
Public constructors | |
---|---|
Builder(int propertyId)
|
Public methods | |
---|---|
Subscription.Builder
|
addAreaId(int areaId)
Adds an areaId for the Subscription being built. |
Subscription
|
build()
Builds and returns the Subscription |
Subscription.Builder
|
setResolution(float resolution)
Sets the resolution for a continuous property. |
Subscription.Builder
|
setUpdateRateFast()
Sets the update rate to |
Subscription.Builder
|
setUpdateRateFastest()
Sets the update rate to |
Subscription.Builder
|
setUpdateRateHz(float updateRateHz)
Sets the update rate in Hz for continuous property. |
Subscription.Builder
|
setUpdateRateNormal()
Sets the update rate to |
Subscription.Builder
|
setUpdateRateUi()
Sets the update rate to |
Subscription.Builder
|
setVariableUpdateRateEnabled(boolean enabled)
Enables/Disables variable update rate. |
Inherited methods | |
---|---|
Public constructors
Builder
public Builder (int propertyId)
Parameters | |
---|---|
propertyId |
int |
Public methods
addAreaId
public Subscription.Builder addAreaId (int areaId)
Adds an areaId for the Subscription being built. If the areaId is already present, then the operation is ignored.
Parameters | |
---|---|
areaId |
int : The areaId to add for the given builder |
Returns | |
---|---|
Subscription.Builder |
The original Builder object. This value cannot be null . |
build
public Subscription build ()
Builds and returns the Subscription
Returns | |
---|---|
Subscription |
Throws | |
---|---|
IllegalStateException |
if build is used more than once. |
setResolution
public Subscription.Builder setResolution (float resolution)
Sets the resolution for a continuous property.
The resolution defines the number of significant digits the incoming property updates
will be rounded to. For example, when a client subscribes at a resolution of 0.01
, the system will round incoming property values to the nearest 0.01. Similarly, if
a client subscribes at resolution 10.0
, the client will get property updates
rounded to the nearest 10. As such, registering with a resolution of 0.0
means
that the client is requesting maximum granularity on incoming property updates. By
default, resolution is set to 0.0
for all [propId, areaId]s in this option,
unless set to a different value via this function.
Clients can only set the resolution to be an integer power of 10 (i.e, 0.01,
0.1, 1.0, 10.0
). If a client attempts to subscribe at a resolution that does not belong
to this set, an IllegalArgumentException
will be thrown.
This feature works best when used with the variable update rate (VUR) feature. When
VUR is enabled and the client sets a resolution of, for example, 10.0
, then the
client will receive property updates only when the rounded property value changes in the
magnitude of 10. For example, if the client is subscribing to the vehicle property VehiclePropertyIds.PERF_VEHICLE_SPEED
at a resolution of 1.0f
, the
system will not propagate a change in vehicle speed from 24.2 to 24.3 up the stack since
it is not required by the client, but will propagate a change from 24.4 to 24.6.
Including a resolution when used alongside VUR creates a better system performance, and is thus STRONGLY RECOMMENDED to subscribe to a property at the finest resolution that is required by the client and no more.
This option is only meaningful for continuous properties, so its value will be ignored for non-continuous properties.
Parameters | |
---|---|
resolution |
float |
Returns | |
---|---|
Subscription.Builder |
The original Builder object. This value cannot be null . |
Throws | |
---|---|
IllegalArgumentException |
if resolution is not an integer power of 10. |
setUpdateRateFast
public Subscription.Builder setUpdateRateFast ()
Sets the update rate to CarPropertyManager#SENSOR_RATE_FAST
Returns | |
---|---|
Subscription.Builder |
The original Builder object. This value cannot be null . |
setUpdateRateFastest
public Subscription.Builder setUpdateRateFastest ()
Sets the update rate to CarPropertyManager#SENSOR_RATE_FASTEST
Returns | |
---|---|
Subscription.Builder |
The original Builder object. This value cannot be null . |
setUpdateRateHz
public Subscription.Builder setUpdateRateHz (float updateRateHz)
Sets the update rate in Hz for continuous property.
For CarPropertyConfig#VEHICLE_PROPERTY_CHANGE_MODE_ONCHANGE
properties, this
operation has no effect and update rate is defaulted to 0
.
The update rate decides the hardware polling rate (if supported) and will be sanitized
to a range between CarPropertyConfig#getMinSampleRate
and
CarPropertyConfig#getMaxSampleRate
.
For better system performance, it is recommended to set this to the smallest
reasonable value, e.g. ERROR(/CarPropertyManager.SENSOR_RATE_NORMAL)
.
Parameters | |
---|---|
updateRateHz |
float : The update rate to set for the given builder
Value is between 0.0 and 100.0 inclusive |
Returns | |
---|---|
Subscription.Builder |
The original Builder object. This value cannot be null . |
setUpdateRateNormal
public Subscription.Builder setUpdateRateNormal ()
Sets the update rate to CarPropertyManager#SENSOR_RATE_NORMAL
Returns | |
---|---|
Subscription.Builder |
The original Builder object. This value cannot be null . |
setUpdateRateUi
public Subscription.Builder setUpdateRateUi ()
Sets the update rate to CarPropertyManager#SENSOR_RATE_UI
Returns | |
---|---|
Subscription.Builder |
The original Builder object. This value cannot be null . |
setVariableUpdateRateEnabled
public Subscription.Builder setVariableUpdateRateEnabled (boolean enabled)
Enables/Disables variable update rate.
This option is only meaningful for continuous property.
By default, variable update rate is enabled for all [propId, areaId]s in this options,
unless disabled via this function or not supported for a specific [propId, areaId]
represented by
AreaIdConfig#isVariableUpdateRateSupported
returning false
.
For better system performance, it is STRONGLY RECOMMENDED NOT TO DISABLE variable update rate unless the client relies on continuously arriving property update events (e.g. for system health checking).
If variable update rate is enabled, then client will receive property update events only when the property's value changes (a.k.a behaves the same as an on-change property).
If variable update rate is disabled, then client will receive all the property update events based on the update rate even if the events contain the same property value.
E.g. a vehicle speed subscribed at 10hz will cause the vehicle hardware to poll 10 times per second. If the vehicle is initially parked at time 0s, and start moving at speed 1 at time 1s. If variable update rate is enabled, the client will receive one initial value of speed 0 at time 0s, and one value of speed 1 at time 1s. If variable update rate is disabled, the client will receive 10 events of speed 0 from 0s to 1s, and 10 events of speed 1 from 1s to 2s.
Parameters | |
---|---|
enabled |
boolean |
Returns | |
---|---|
Subscription.Builder |
The original Builder object. This value cannot be null . |