AOSP Expert & Production Engineering
3 min read

CarPropertyManager

Interacting with Vehicle Data: CarPropertyManager

For an Android application running within AAOS, the CarPropertyManager is the primary interface for reading, writing, and listening to vehicle hardware data. It acts as the Java/Kotlin bridge over CarService, which in turn talks to the Vehicle HAL.

To use it, an application must first connect to the Car API and request the Car.PROPERTY_SERVICE. Note that interacting with vehicle properties requires specific Android permissions (e.g., android.car.permission.CAR_SPEED or android.car.permission.CONTROL_CAR_CLIMATE).

CarPropertyValue and Area IDs

Data is encapsulated in a CarPropertyValue object. This object contains not just the value itself, but the property ID, status, timestamp, and crucially, the Area ID.

Understanding Area IDs

A vehicle is not a single point in space; it has distinct physical zones. For example, the HVAC temperature can be set independently for the driver and the passenger.

Area IDs define these zones. The types of areas include:

  • GLOBAL: A property that applies to the entire vehicle (e.g., Vehicle Speed, Gear). Area ID is always 0.
  • WINDOW: Specific windows (e.g., Driver window, Sunroof).
  • SEAT: Specific seats (e.g., Row 1 Left, Row 1 Right).
  • MIRROR: Side or rear-view mirrors.
// Example: Reading the driver's HVAC temperature
CarPropertyManager propMgr = (CarPropertyManager) car.getCarManager(Car.PROPERTY_SERVICE);

int driverSeatId = VehicleAreaSeat.SEAT_ROW_1_LEFT;
float temp = propMgr.getFloatProperty(VehiclePropertyIds.HVAC_TEMPERATURE_SET, driverSeatId);

Property Change Listeners

Polling the VHAL for data is inefficient and heavily discouraged. Instead, applications should register listeners to receive callbacks when a property changes.

// Example: Listening for Gear Selection changes
CarPropertyManager.CarPropertyEventCallback callback = new CarPropertyManager.CarPropertyEventCallback() {
    @Override
    public void onChangeEvent(CarPropertyValue value) {
        int gear = (int) value.getValue();
        Log.d("CarApp", "Gear changed to: " + gear);
    }

    @Override
    public void onErrorEvent(int propertyId, int zone) {
        Log.e("CarApp", "Error reading property: " + propertyId);
    }
};

// Register listener for a global property
propMgr.registerCallback(callback, VehiclePropertyIds.GEAR_SELECTION, CarPropertyManager.SENSOR_RATE_ONCHANGE);

Continuous vs. On-Change Properties

When registering a listener, you must specify an update rate. The acceptable rates depend on how the property is defined in the VHAL.

ON_CHANGE Properties

These properties only trigger a callback when the value actually changes. Examples include GEAR_SELECTION or PARKING_BRAKE_ON. You register these using CarPropertyManager.SENSOR_RATE_ONCHANGE.

CONTINUOUS Properties

These properties are constantly sampled by the VHAL. Examples include PERF_VEHICLE_SPEED or ENGINE_RPM. When registering for these, you request a specific sampling rate (in Hertz).

// Requesting vehicle speed updates at 10 Hz
propMgr.registerCallback(callback, VehiclePropertyIds.PERF_VEHICLE_SPEED, 10.0f);

Note: The VHAL may not perfectly honor the requested frequency depending on the underlying CAN bus traffic, but it will attempt to deliver updates as close to the requested rate as possible.

Mastering the CarPropertyManager is essential for building responsive, hardware-aware automotive applications that seamlessly integrate with the driver's physical environment.