Dynamically change vehicle properties in Android Automotive

2025-01-17

This tutorial will cover a specific use case with Android Automotive: how to dynamically change vehicle properties?

Concepts

In Android Automotive, Vehicle HAL abstracts parameters of the vehicle and handles them via Vehicle Properties.

These parameters include the vehicle speed, doors opening, gear selection, fuel level, and many more. VehiclePropertyIds includes a more detailed list.

In a real vehicle, the Vehicle HAL continuously communicates with various vehicle sensors and ECUs to retrieve the value of these parameters. The Vehicle HAL exposes the retrieved values to Android apps.

In an automotive emulator, the Vehicle HAL is not connected to any real hardware. For testing and demonstration purposes, the tutorial implements a way to dynamically inject values for these properties via a gRPC server running on the device. The tutorial also uses a gRPC client running either on the device or on a host machine.

This approach allows mocking the state of the vehicle in a simple way. This approach can be useful in the context of automated tests.

Using the gRPC client

For this example, a small gRPC client is able to get and set the values of a subset of vehicle properties. You can try it as follows:

1. On the device, click on the icon at the bottom navigation area. Swipe to the right. Start the VehicleDemo application. The application displays the current state of some vehicle properties. 2. Open a new browser tab with the IP address of your device. Go to the Shell panel. 3. Run the following commands:

# Open the fuel door:
./system/vendor/bin/grpc-vhal-aidl-client -s 0.0.0.0:45001 -i 287310600 -v 1
# Connecting to server at 0.0.0.0:45001
# Connected to the server at 0.0.0.0:45001
# Setting the value of 287310600 to 1

# Get whether the fuel door is opened (1) or not (0):
./system/vendor/bin/grpc-vhal-aidl-client -s 0.0.0.0:45001 -i 287310600
# Connecting to server at 0.0.0.0:45001
# Connected to the server at 0.0.0.0:45001
# The value of 287310600 is:
# VehiclePropValue{timestamp: 288592858284, areaId: 0, prop: 287310600, status: AVAILABLE,
# value: RawPropValues{int32Values: [1], floatValues: [], int64Values: [], byteValues: [], stringValue: []}}

The fuel door now appears in red in the VehicleDemo application.

This small demonstration client only covers a subset of vehicle properties. You can implement your own gRPC client.

Access the gRPC server

The gRPC server running on the device is accessible via TCP requests on <virtual_device_IP_address:45001>. Open this port in your AWS EC2 security group.

Then you can implement your gRPC client by relying on the AAOS VehicleServer.proto gRPC APIs and the corresponding proto files: