2025-01-17
This tutorial will cover a specific use case with Android Automotive: how to dynamically change vehicle properties?
Concepts
In Android Automotive, the vehicle parameters are abstracted by the Vehicle HAL and handled via Vehicle Properties.
These parameters include the vehicle speed, doors opening, gear selection, fuel level, and many more (see VehiclePropertyIds for 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 and expose them to Android apps.
In an automotive emulator, the Vehicle HAL is not connected to any real hardware.
For testing and demonstration purposes, a way to dynamically inject values for these properties is implemented via a gRPC server running on the device and a gRPC client running either on the device or on a host machine.
This setup mocks the state of the vehicle in a simple way.
This approach is useful in the context of automated tests.
Using the gRPC client
For this example, a small gRPC client is implemented.
The gRPC client can get and set the values of a subset of vehicle properties.
You can try the example as follows:
1. On the device, click on the icon at the bottom navigation area. 2. Swipe to the right. 3. Start the VehicleDemo application. 4. Observe the current state of some vehicle properties. 5. Open a new browser tab with the IP address of your device. 6. Go to the Shell panel. 7. 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.
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 port 45001 in your AWS EC2 security group.
Then implement your gRPC client by relying on the AAOS VehicleServer.proto gRPC APIs and the corresponding proto files.