VHAL, Java और नेटिव क्लाइंट के साथ काम करता है. वीएचएएल के लिए, Car Service ही एकमात्र
Java क्लाइंट है. कार ऐप्लिकेशन के लिए, वीएचएएल प्रॉपर्टी को ऐक्सेस करने के लिए, सीधे वीएचएएल के साथ बातचीत करने के बजाय, कार एपीआई (उदाहरण के लिए,
CarPropertyManager
) का इस्तेमाल करें. असल में, SELinux सीधे ऐक्सेस को ब्लॉक करता है. ज़्यादा जानकारी के लिए, पैकेज इंडेक्स पर जाकर, Car API का दस्तावेज़ देखें.
Android 13 के बाद के वर्शन वाले नेटिव क्लाइंट के लिए, VHAL से सीधे तौर पर कनेक्ट करने के बजाय, libvhalclient
का इस्तेमाल करें. यह एक क्लाइंट लाइब्रेरी है, जो एआईडीएल और एचआईडीएल वीएचएएल लागू करने के लिए, एक सामान्य इंटरफ़ेस,
IVhalClient.h
दिखाती है. नीचे दिए गए उदाहरण में, VHAL नेटिव क्लाइंट बनाने और वाहन की पहचान करने वाला नंबर (वीआईएन) पाने के लिए उसका इस्तेमाल करने का तरीका बताया गया है:
#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; }
अपने नेटिव क्लाइंट को VHAL को ऐक्सेस करने की अनुमति देने के लिए, आपको SELinux नीति को कॉन्फ़िगर करना होगा. उदाहरण के लिए:
# 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)