VHAL supporta i client Java e nativi. Car Service è l'unico
client Java per VHAL. Per le app per auto, utilizza le API Car (ad esempio CarPropertyManager
) per accedere alle proprietà VHAL anziché comunicare direttamente con il VHAL. Infatti, SELinux blocca l'accesso diretto. Per maggiori dettagli, consulta la documentazione dell'API Car nell'Indice dei pacchetti.
Per i client nativi, a partire da Android 13, utilizza
libvhalclient
anziché connetterti direttamente
con VHAL. Si tratta di una libreria client che espone un'interfaccia comune,IVhalClient.h
per le implementazioni VHAL di AIDL e HIDL. L'esempio seguente mostra come creare un client VHAL nativo e utilizzarlo per ottenere un numero di telaio (VIN):
#include <IVhalClient.h> #include <VehicleHalTypes.h> #include <VehicleUtils.h> using ::aidl::android::hardware::automotive::vehicle::VehicleProperty; using ::android::frameworks::automotive::vhal::IVhalClient; using ::android::hardware::automotive::vehicle::toInt; int main(int argc, char** argv) { auto vhalClient = IVhalClient::tryCreate(); if (vhalClient == nullptr) { // handle error. return -1; } auto result = vhalClient->getValueSync( *vhalClient->createHalPropValue(toInt(VehicleProperty::INFO_VIN))); // Use result return 0; }
Devi configurare il criterio SELinux per consentire al client nativo di accedere a VHAL. Ad esempio:
# Define my domain type my_native_daemon, domain; # Define the exec file type. type my_native_daemon_exec, exec_type, file_type, system_file_type; # Initialize domain. init_daemon_domain(my_native_daemon) # Allow using hwbinder for HIDL VHAL, not required if AIDL is used. hwbinder_use(my_native_daemon) # Allow using binder for AIDL VHAL binder_use(my_native_daemon) # Allow my_native_daemon to be a VHAL client. hal_client_domain(my_native_daemon, hal_vehicle)