Dynamically change vehicle properties in Android Automotive

2025-01-17

This tutorial explains how to dynamically change vehicle properties in Android Automotive.

In Android Automotive, several vehicle parameters are abstracted by the Vehicle HAL and exposed via Vehicle Properties.

Examples of vehicle parameters include vehicle speed, doors opening, gear selection, and fuel level.

The Vehicle HAL is the hardware abstraction layer that exposes vehicle parameters to the Android framework.

Vehicle Properties are a collection of parameters that expose values such as speed, doors opening, gear selection, and fuel level.

See VehiclePropertyIds for a more detailed list of vehicle properties.

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

In an automotive emulator, the VHAL is not connected to any real hardware.

For testing and demonstration purposes, a way to dynamically inject values for these properties via a gRPC server (running on the device) and a gRPC client (running either on the device or on a host machine) was implemented.

This allows you to mock the state of the vehicle in a simple way, which can be very useful in the context of automated tests.

Using the gRPC client

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

On the device, click on the icon at the bottom navigation area, swipe to the right and start the VehicleDemo application. It displays the current state of some vehicle properties.

Open a new browser tab with the IP address of your device, and go to the Shell panel:

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: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:45001
# The value of 287310600 is:
# VehiclePropValue{timestamp: 288592858284, areaId: 0, prop: 287310600, status: AVAILABLE,
# value: RawPropValues{int32Values: [1], floatValues: [], int64Values: [], byteValues: [], stringValue: }}
# 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 the 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: }}
# 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 the 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: }}

This small demonstration client only covers a subset of vehicle properties, but the good news is that 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> (don’t forget to 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.