CarSensorManager
public
final
class
CarSensorManager
extends Object
java.lang.Object | |
↳ | android.car.hardware.CarSensorManager |
This class was deprecated
in API level 29.
Use CarPropertyManager
instead.
API for monitoring car sensor data.
Summary
Nested classes | |
---|---|
interface |
CarSensorManager.OnSensorChangedListener
Listener for car sensor data change. |
Constants | |
---|---|
int |
SENSOR_RATE_FAST
|
int |
SENSOR_RATE_FASTEST
Read sensor at the maximum rate. |
int |
SENSOR_RATE_NORMAL
Read sensor in default normal rate set for each sensors. |
int |
SENSOR_RATE_ONCHANGE
Read on_change type sensors |
int |
SENSOR_RATE_UI
|
int |
SENSOR_TYPE_ABS_ACTIVE
Set to true when ABS is active. |
int |
SENSOR_TYPE_CAR_SPEED
This sensor represents vehicle speed in m/s. |
int |
SENSOR_TYPE_ENGINE_OIL_LEVEL
Oil level sensor. |
int |
SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE
Outside Environment like temperature. |
int |
SENSOR_TYPE_EV_BATTERY_CHARGE_RATE
Indicates the instantaneous battery charging rate in mW. |
int |
SENSOR_TYPE_EV_BATTERY_LEVEL
Indicates battery level of the car. |
int |
SENSOR_TYPE_EV_CHARGE_PORT_CONNECTED
Set to true if EV charging port is connected. |
int |
SENSOR_TYPE_EV_CHARGE_PORT_OPEN
Set to true if EV charging port is open. |
int |
SENSOR_TYPE_FUEL_DOOR_OPEN
Set to true if the fuel door is open. |
int |
SENSOR_TYPE_FUEL_LEVEL
Indicates fuel level of the car. |
int |
SENSOR_TYPE_GEAR
This represents the current position of transmission gear. |
int |
SENSOR_TYPE_IGNITION_STATE
Represents ignition state. |
int |
SENSOR_TYPE_NIGHT
Day/night sensor. |
int |
SENSOR_TYPE_ODOMETER
Total travel distance of the car in Kilometer. |
int |
SENSOR_TYPE_PARKING_BRAKE
Represents the current status of parking brake. |
int |
SENSOR_TYPE_RPM
Represents engine RPM of the car. |
int |
SENSOR_TYPE_TRACTION_CONTROL_ACTIVE
Set to true when traction control is active. |
int |
SENSOR_TYPE_WHEEL_TICK_DISTANCE
Represents wheel distance in millimeters. |
Public methods | |
---|---|
CarSensorEvent
|
getLatestSensorEvent(int type)
Get the most recent CarSensorEvent for the given type. |
List<CarPropertyConfig<T>>
|
getPropertyList()
Get list of properties represented by CarSensorManager for this car. |
int[]
|
getSupportedSensors()
Give the list of CarSensors available in the connected car. |
boolean
|
isSensorSupported(int sensorType)
Tells if given sensor is supported or not. |
boolean
|
registerListener(CarSensorManager.OnSensorChangedListener listener, int sensorType, int rate)
Register |
void
|
unregisterListener(CarSensorManager.OnSensorChangedListener listener, int sensorType)
Stop getting sensor update for the given listener and sensor. |
void
|
unregisterListener(CarSensorManager.OnSensorChangedListener listener)
Stop getting sensor update for the given listener. |
Inherited methods | |
---|---|
Constants
SENSOR_RATE_FAST
public static final int SENSOR_RATE_FAST
Constant Value: 10 (0x0000000a)
SENSOR_RATE_FASTEST
public static final int SENSOR_RATE_FASTEST
Read sensor at the maximum rate. Actual rate will be different depending on the sensor.
Constant Value: 100 (0x00000064)
SENSOR_RATE_NORMAL
public static final int SENSOR_RATE_NORMAL
Read sensor in default normal rate set for each sensors. This is default rate.
Constant Value: 1 (0x00000001)
SENSOR_RATE_ONCHANGE
public static final int SENSOR_RATE_ONCHANGE
Read on_change type sensors
Constant Value: 0 (0x00000000)
SENSOR_RATE_UI
public static final int SENSOR_RATE_UI
Constant Value: 5 (0x00000005)
SENSOR_TYPE_ABS_ACTIVE
public static final int SENSOR_TYPE_ABS_ACTIVE
Set to true when ABS is active. This sensor is event driven.
Constant Value: 287310858 (0x1120040a)
SENSOR_TYPE_CAR_SPEED
public static final int SENSOR_TYPE_CAR_SPEED
This sensor represents vehicle speed in m/s.
Sensor data in CarSensorEvent
is a float. When the vehicle is moving forward,
SENSOR_TYPE_CAR_SPEED is positive and negative when the vehicle is moving backward. Also,
this value is independent of SENSOR_TYPE_GEAR. For example, if SENSOR_TYPE_GEAR is CarSensorEvent.GEAR_NEUTRAL
, SENSOR_TYPE_CAR_SPEED is positive when the vehicle is moving
forward, negative when moving backward, and zero when not moving.
Constant Value: 291504647 (0x11600207)
SENSOR_TYPE_ENGINE_OIL_LEVEL
public static final int SENSOR_TYPE_ENGINE_OIL_LEVEL
Oil level sensor.
Constant Value: 289407747 (0x11400303)
SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE
public static final int SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE
Outside Environment like temperature.
This requires Car#PERMISSION_EXTERIOR_ENVIRONMENT
permission.
Constant Value: 291505923 (0x11600703)
SENSOR_TYPE_EV_BATTERY_CHARGE_RATE
public static final int SENSOR_TYPE_EV_BATTERY_CHARGE_RATE
Indicates the instantaneous battery charging rate in mW.
This requires Car#PERMISSION_ENERGY
permission.
Constant Value: 291504908 (0x1160030c)
SENSOR_TYPE_EV_BATTERY_LEVEL
public static final int SENSOR_TYPE_EV_BATTERY_LEVEL
Indicates battery level of the car.
In CarSensorEvent
, represents battery level in WH. floatValues of
INDEX_EV_BATTERY_CAPACITY_ACTUAL property represents the actual battery capacity in
WH. The battery degrades over time, so this value is expected to drop slowly over the life
of the vehicle.
This requires Car#PERMISSION_ENERGY
permission.
Constant Value: 291504905 (0x11600309)
SENSOR_TYPE_EV_CHARGE_PORT_CONNECTED
public static final int SENSOR_TYPE_EV_CHARGE_PORT_CONNECTED
Set to true if EV charging port is connected.
This requires Car#PERMISSION_ENERGY_PORTS
permission.
Constant Value: 287310603 (0x1120030b)
SENSOR_TYPE_EV_CHARGE_PORT_OPEN
public static final int SENSOR_TYPE_EV_CHARGE_PORT_OPEN
Set to true if EV charging port is open.
This requires Car#PERMISSION_ENERGY_PORTS
permission.
Constant Value: 287310602 (0x1120030a)
SENSOR_TYPE_FUEL_DOOR_OPEN
public static final int SENSOR_TYPE_FUEL_DOOR_OPEN
Set to true if the fuel door is open.
This requires Car#PERMISSION_ENERGY_PORTS
permission.
Constant Value: 287310600 (0x11200308)
SENSOR_TYPE_FUEL_LEVEL
public static final int SENSOR_TYPE_FUEL_LEVEL
Indicates fuel level of the car.
In CarSensorEvent
, represents fuel level in milliliters.
This requires Car#PERMISSION_ENERGY
permission.
Constant Value: 291504903 (0x11600307)
SENSOR_TYPE_GEAR
public static final int SENSOR_TYPE_GEAR
This represents the current position of transmission gear. Sensor data in
CarSensorEvent
is an intValues[0]. For the meaning of the value, check
CarSensorEvent#GEAR_NEUTRAL
and other GEAR_*.
This requires Car#PERMISSION_POWERTRAIN
permission.
Constant Value: 289408000 (0x11400400)
SENSOR_TYPE_IGNITION_STATE
public static final int SENSOR_TYPE_IGNITION_STATE
Represents ignition state. The value should be one of the constants that starts with
IGNITION_STATE_* in CarSensorEvent
.
This requires Car#PERMISSION_POWERTRAIN
permission.
Constant Value: 289408009 (0x11400409)
SENSOR_TYPE_NIGHT
public static final int SENSOR_TYPE_NIGHT
Day/night sensor. Sensor data is intValues[0].
This requires Car#PERMISSION_EXTERIOR_ENVIRONMENT
permission.
Constant Value: 287310855 (0x11200407)
SENSOR_TYPE_ODOMETER
public static final int SENSOR_TYPE_ODOMETER
Total travel distance of the car in Kilometer. Sensor data is a float.
Constant Value: 291504644 (0x11600204)
SENSOR_TYPE_PARKING_BRAKE
public static final int SENSOR_TYPE_PARKING_BRAKE
Represents the current status of parking brake. Sensor data in CarSensorEvent
is an
intValues[0]. Value of 1 represents parking brake applied while 0 means the other way
around. For this sensor, rate in registerListener(android.car.hardware.CarSensorManager.OnSensorChangedListener, int, int)
will be ignored and all changes will be notified.
This requires Car#PERMISSION_POWERTRAIN
permission.
Constant Value: 287310850 (0x11200402)
SENSOR_TYPE_RPM
public static final int SENSOR_TYPE_RPM
Represents engine RPM of the car. Sensor data in CarSensorEvent
is a float.
Constant Value: 291504901 (0x11600305)
SENSOR_TYPE_TRACTION_CONTROL_ACTIVE
public static final int SENSOR_TYPE_TRACTION_CONTROL_ACTIVE
Set to true when traction control is active. This sensor is event driven.
Constant Value: 287310859 (0x1120040b)
SENSOR_TYPE_WHEEL_TICK_DISTANCE
public static final int SENSOR_TYPE_WHEEL_TICK_DISTANCE
Represents wheel distance in millimeters. Some cars may not have individual sensors on each
wheel. If a value is not available, Long.MAX_VALUE will be reported. The wheel distance
accumulates over time. It increments on forward movement, and decrements on reverse. Wheel
distance shall be reset to zero each time a vehicle is started by the user.
This requires Car#PERMISSION_SPEED
permission.
Constant Value: 290521862 (0x11510306)
Public methods
getLatestSensorEvent
public CarSensorEvent getLatestSensorEvent (int type)
Get the most recent CarSensorEvent for the given type. Note that latest sensor data from car will not be available if it was never subscribed before. This call will return immediately with null if there is no data available.
Returns | |
---|---|
CarSensorEvent |
null if there was no sensor update since connected to the car. |
getPropertyList
public List<CarPropertyConfig<T>> getPropertyList ()
Get list of properties represented by CarSensorManager for this car.
Returns | |
---|---|
List<CarPropertyConfig<T>> |
List of CarPropertyConfig objects available via Car Sensor Manager. |
getSupportedSensors
public int[] getSupportedSensors ()
Give the list of CarSensors available in the connected car.
Returns | |
---|---|
int[] |
array of all sensor types supported. Sensor types is the same as property id. |
isSensorSupported
public boolean isSensorSupported (int sensorType)
Tells if given sensor is supported or not.
Returns | |
---|---|
boolean |
true if the sensor is supported. |
registerListener
public boolean registerListener (CarSensorManager.OnSensorChangedListener listener, int sensorType, int rate)
Register OnSensorChangedListener
to get repeated sensor updates. Multiple listeners
can be registered for a single sensor or the same listener can be used for different sensors.
If the same listener is registered again for the same sensor, it will be either ignored or
updated depending on the rate.
Returns | |
---|---|
boolean |
if the sensor was successfully enabled. |
Throws | |
---|---|
IllegalArgumentException |
for wrong argument like wrong rate |
SecurityException |
if missing the appropriate permission |
unregisterListener
public void unregisterListener (CarSensorManager.OnSensorChangedListener listener, int sensorType)
Stop getting sensor update for the given listener and sensor. If the same listener is used for other sensors, those subscriptions will not be affected.
Parameters | |
---|---|
listener |
CarSensorManager.OnSensorChangedListener : Listener for car sensor data change. |
sensorType |
int : Property Id
Value is SENSOR_TYPE_CAR_SPEED , SENSOR_TYPE_RPM , SENSOR_TYPE_ODOMETER , SENSOR_TYPE_FUEL_LEVEL , SENSOR_TYPE_PARKING_BRAKE , SENSOR_TYPE_GEAR , SENSOR_TYPE_NIGHT , SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE , SENSOR_TYPE_IGNITION_STATE , SENSOR_TYPE_WHEEL_TICK_DISTANCE , SENSOR_TYPE_ABS_ACTIVE , SENSOR_TYPE_TRACTION_CONTROL_ACTIVE , SENSOR_TYPE_FUEL_DOOR_OPEN , SENSOR_TYPE_EV_BATTERY_LEVEL , SENSOR_TYPE_EV_CHARGE_PORT_OPEN , SENSOR_TYPE_EV_CHARGE_PORT_CONNECTED , SENSOR_TYPE_EV_BATTERY_CHARGE_RATE , or SENSOR_TYPE_ENGINE_OIL_LEVEL |
unregisterListener
public void unregisterListener (CarSensorManager.OnSensorChangedListener listener)
Stop getting sensor update for the given listener. If there are multiple registrations for this listener, all listening will be stopped.
Parameters | |
---|---|
listener |
CarSensorManager.OnSensorChangedListener : Listener for car sensor data change. |
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 2024-04-11 UTC.