Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

CarSensorManager

public final class CarSensorManager
extends Object

java.lang.Object
   ↳ android.car.hardware.CarSensorManager


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_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_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.

static boolean isSensorSupported(int[] sensorList, int sensorType)

Check if given sensorList is including the sensorType.

boolean registerListener(CarSensorManager.OnSensorChangedListener listener, int sensorType, int rate)

Register CarSensorManager.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

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_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. This requires ERROR(/Car#PERMISSION_CAR_DYNAMICS_STATE) permission.

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 which will be >= 0. This requires Car.PERMISSION_SPEED permission.

Constant Value: 291504647 (0x11600207)

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[ERROR(/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

public static final int SENSOR_TYPE_EV_CHARGE_PORT_CONNECTED

Set to true if EV charging port is connected.

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.

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.

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_*.

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.

Constant Value: 289408009 (0x11400409)

SENSOR_TYPE_NIGHT

public static final int SENSOR_TYPE_NIGHT

Day/night sensor. Sensor data is intValues[0].

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. This requires ERROR(/Car#PERMISSION_MILEAGE) permission.

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(OnSensorChangedListener, int, int) will be ignored and all changes will be notified.

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. This requires ERROR(/Car#PERMISSION_CAR_DYNAMICS_STATE) permission.

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.

Parameters
type int: A sensor to request

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

Throws
CarNotConnectedException if the connection to the car service has been lost.

getPropertyList

public List<CarPropertyConfig> getPropertyList ()

Get list of properties represented by CarSensorManager for this car.

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

Throws
CarNotConnectedException if the connection to the car service has been lost.

getSupportedSensors

public int[] getSupportedSensors ()

Give the list of CarSensors available in the connected car.

Returns
int[] array of all sensor types supported.

Throws
CarNotConnectedException if the connection to the car service has been lost.

isSensorSupported

public boolean isSensorSupported (int sensorType)

Tells if given sensor is supported or not.

Returns
boolean true if the sensor is supported.

Throws
CarNotConnectedException if the connection to the car service has been lost.

isSensorSupported

public static boolean isSensorSupported (int[] sensorList, 
                int sensorType)

Check if given sensorList is including the sensorType.

Returns
boolean

registerListener

public boolean registerListener (CarSensorManager.OnSensorChangedListener listener, 
                int sensorType, 
                int rate)

Register CarSensorManager.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.

Requires Car.PERMISSION_SPEED for SENSOR_TYPE_CAR_SPEED and SENSOR_TYPE_WHEEL_TICK_DISTANCE, ERROR(/Car#PERMISSION_MILEAGE) for SENSOR_TYPE_ODOMETER, Car.PERMISSION_ENERGY for SENSOR_TYPE_FUEL_LEVEL and (@link #SENSOR_TYPE_EV_BATTERY_LEVEL and ERROR(/#SENSOR_TYPE_EV_CHARGE_RATE), ERROR(/Car#PERMISSION_CAR_DYNAMICS_STATE) for SENSOR_TYPE_ABS_ACTIVE and SENSOR_TYPE_TRACTION_CONTROL_ACTIVE

Parameters
sensorType int: sensor type to subscribe.

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.

Returns
boolean if the sensor was successfully enabled.

Throws
CarNotConnectedException if the connection to the car service has been lost.
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.

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.