Google is committed to advancing racial equity for Black communities. See how.

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> 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 OnSensorChangedListener to get repeated sensor updates.

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

Added in API level 29
Deprecated in API level 29
public static final int SENSOR_RATE_FAST

Constant Value: 10 (0x0000000a)

SENSOR_RATE_FASTEST

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

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

Added in API level 29
Deprecated in API level 29
public static final int SENSOR_RATE_ONCHANGE

Read on_change type sensors

Constant Value: 0 (0x00000000)

SENSOR_RATE_UI

Added in API level 29
Deprecated in API level 29
public static final int SENSOR_RATE_UI

Constant Value: 5 (0x00000005)

SENSOR_TYPE_ABS_ACTIVE

Added in API level 29
Deprecated in API level 29
public static final int SENSOR_TYPE_ABS_ACTIVE

Set to true when ABS is active. This sensor is event driven. This requires ERROR(Car#PERMISSION_CAR_DYNAMICS_STATE/android.car.Car#PERMISSION_CAR_DYNAMICS_STATE Car#PERMISSION_CAR_DYNAMICS_STATE) permission.

Constant Value: 287310858 (0x1120040a)

SENSOR_TYPE_CAR_SPEED

Added in API level 29
Deprecated in API level 29
public static final int SENSOR_TYPE_CAR_SPEED

This sensor represents vehicle speed in m/s. Sensor data in CarSensorEvent is a float which will be >= 0. This requires Car#PERMISSION_SPEED permission.

Constant Value: 291504647 (0x11600207)

SENSOR_TYPE_ENGINE_OIL_LEVEL

Added in API level 29
Deprecated in API level 29
public static final int SENSOR_TYPE_ENGINE_OIL_LEVEL

Oil level sensor. This requires ERROR(Car#PERMISSION_CAR_ENGINE_DETAILED/android.car.Car#PERMISSION_CAR_ENGINE_DETAILED Car#PERMISSION_CAR_ENGINE_DETAILED) permission

Constant Value: 289407747 (0x11400303)

SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE

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

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

Added in API level 29
Deprecated in API level 29
public static final int SENSOR_TYPE_EV_BATTERY_LEVEL

Indicates battery level of the car. In CarSensorEvent, represents battery level in WH. floatValues[ERROR(CarSensorEvent#INDEX_EV_BATTERY_CAPACITY_ACTUAL/android.car.hardware.CarSensorEvent#INDEX_EV_BATTERY_CAPACITY_ACTUAL CarSensorEvent#INDEX_EV_BATTERY_CAPACITY_ACTUAL)] 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

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

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

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

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

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

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

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

Added in API level 29
Deprecated in API level 29
public static final int SENSOR_TYPE_ODOMETER

Total travel distance of the car in Kilometer. Sensor data is a float. This requires ERROR(Car#PERMISSION_MILEAGE/android.car.Car#PERMISSION_MILEAGE Car#PERMISSION_MILEAGE) permission.

Constant Value: 291504644 (0x11600204)

SENSOR_TYPE_PARKING_BRAKE

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

Added in API level 29
Deprecated in API level 29
public static final int SENSOR_TYPE_RPM

Represents engine RPM of the car. Sensor data in CarSensorEvent is a float. This requires ERROR(Car#PERMISSION_CAR_ENGINE_DETAILED/android.car.Car#PERMISSION_CAR_ENGINE_DETAILED Car#PERMISSION_CAR_ENGINE_DETAILED) permission.

Constant Value: 291504901 (0x11600305)

SENSOR_TYPE_TRACTION_CONTROL_ACTIVE

Added in API level 29
Deprecated in API level 29
public static final int SENSOR_TYPE_TRACTION_CONTROL_ACTIVE

Set to true when traction control is active. This sensor is event driven. This requires ERROR(Car#PERMISSION_CAR_DYNAMICS_STATE/android.car.Car#PERMISSION_CAR_DYNAMICS_STATE Car#PERMISSION_CAR_DYNAMICS_STATE) permission.

Constant Value: 287310859 (0x1120040b)

SENSOR_TYPE_WHEEL_TICK_DISTANCE

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

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

Parameters
type int: A sensor to request 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

Returns
CarSensorEvent null if there was no sensor update since connected to the car.

getPropertyList

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

Get list of properties represented by CarSensorManager for this car.

Returns
List<CarPropertyConfig> List of CarPropertyConfig objects available via Car Sensor Manager.

getSupportedSensors

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

registerListener

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

Parameters
sensorType int: sensor type to subscribe. 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

rate int: how fast the sensor events are delivered. It should be one of SENSOR_RATE_FASTEST, SENSOR_RATE_FAST, SENSOR_RATE_UI, SENSOR_RATE_NORMAL. Rate may not be respected especially when the same sensor is registered with different listener with different rates. Also, rate might be ignored when vehicle property raises events only when the value is actually changed, for example SENSOR_TYPE_PARKING_BRAKE will raise an event only when parking brake was engaged or disengaged. Value is SENSOR_RATE_ONCHANGE, SENSOR_RATE_NORMAL, SENSOR_RATE_UI, SENSOR_RATE_FAST, or SENSOR_RATE_FASTEST

Returns
boolean if the sensor was successfully enabled.

Throws
IllegalArgumentException for wrong argument like wrong rate
SecurityException if missing the appropriate permission

unregisterListener

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

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