اعتبارًا من 27 آذار (مارس) 2025، ننصحك باستخدام android-latest-release بدلاً من aosp-main لإنشاء AOSP والمساهمة فيه. لمزيد من المعلومات، يُرجى الاطّلاع على التغييرات في AOSP.
يستند التنفيذ المرجعي إلى بنية من طبقتَين. في الطبقة العليا،
DefaultVehicleHal، يتم تنفيذ واجهة VHAL AIDL وتوفير منطق VHAL
العام لجميع الأجهزة. في الطبقة السفلية، ينفذ FakeVehicleHardware
واجهة IVehicleHardware. تحاكي هذه الفئة منطق VHAL
للتفاعل مع الأجهزة الفعلية أو ناقل بيانات المركبة، وهي خاصة بالجهاز. يمكن للمورّدين
اختياريًا تكييف هذه البنية نفسها وإعادة استخدام فئة DefaultVehicleHal نفسها (بإضافتها
لإعادة كتابة طريقة) وتقديم تنفيذ IVehicleHardware خاص بهم.
الشكل 1. مرجع تنفيذ VHAL
يحتوي DefaultVehicleHal
على المنطق التالي الذي يُعدّ عامًا ويمكن تطبيقه على أي عملية تنفيذ لـ VHAL.
تنفيذ واجهة IVehicle
تُجري عمليات فحص أساسية للبيانات المُدخلة، بما في ذلك التحقّق من عدم توفّر أرقام تعريف مكرّرة.
تخصيص عناصر العميل (مثل GetValuesClient) لكل عملية لكل عميل رابط، وإضافة كل عنصر إلى مجموعة عالمية
تدير منطق عمليات الاستدعاء غير المتزامنة، مثل إضافة طلب في انتظار المراجعة إلى مجموعة طلبات في انتظار المراجعة.
يحلّ الطلبات المعلّقة عند تلقّي النتائج أو يعرض خطأ عند انتهاء مهلة أحد الطلبات المعلّقة
تُستخدم لتحويل LargeParcelable إلى سلسلة وتحويلها من سلسلة (راجِع
ParcelableUtils.h).
إدارة الاشتراك (راجِع SubscriptionManager.h)
التحقّق من الأذونات (اطّلِع على الدالتَين checkReadPermission و
checkWritePermission).
تستدعي هذه الدالة IVehicleHardware.checkHealth بشكل دوري وترسل إشارات فحص الأداء (اطّلِع على دالة
checkHealth).
IVehicleHardware
هي واجهة عامة تُستخدَم لتمثيل تنفيذ VHAL الخاص بالأجهزة. التنفيذ المرجعي لـ IVehicleHardware هو
FakeVehicleHardware،
الذي يستخدم خريطة في الذاكرة لتخزين قيمة السمة ولا
يتواصل مع ناقل بيانات المركبة الفعلي. ومن المفترض أن يتم تشغيلها على محاكي بدون
أي تبعيات خاصة بالأجهزة. يجب ألا تستخدم عمليات تنفيذ المورّدين هذا الإطار كما هو، ويجب أن تضيف
منطقًا خاصًا بوحدة تحكّم المركبة.
بدءًا من Android 14، يقرأ FakeVehicleHardware إعدادات الموقع المتوافقة أثناء التشغيل
أثناء الإعداد من مجلد /vendor/etc/automotive/vhalconfig/ على الجهاز،
الذي يحتوي على ملف إعدادات بتنسيق JSON. اطّلِع على
ملف README المرجعي لتنسيق VHAL
لمعرفة تنسيق ملف الإعدادات ومحتواه.
تتيح FakeVehicleHardware أيضًا إلغاء ملف الإعدادات للاختبار. في حال ضبط
سمة النظام persist.vendor.vhal_init_value_override (يجب ضبط
هذه السمة في وقت الإنشاء أو في وقت مبكر جدًا أثناء عملية التمهيد قبل بدء VHAL)، يتم استخدامملف الإعدادات
من مجلد /vendor/etc/automotive/vhaloverride/ على الجهاز لإلغاء
الإعدادات الحالية. يمكن أن يستخدم موفِّر الخدمة نهجًا مشابهًا لكي لا تكون إعدادات المواقع المتوافقة مع VHAL-
برمجية ثابتة، بل يمكن تحديدها ديناميكيًا في وقت البدء.
يجب أن تكون قائمة إعدادات سمات المركبات ثابتة بعد بدء VHAL.
بدءًا من Android 16، يوفّر GRPCVehicleHardware
طريقة أخرى لتنفيذ IVehicleHardware المرجعية. يفترض هذا التنفيذ
توفُّر خادم منفصل يعمل على جهاز أو جهاز افتراضي بعيد يحتوي على منطق معالجة
الموقع. يعمل VHAL الذي يعمل على أجهزة AAOS كخادم وكيل يعيد توجيه الطلبات إلى
الخادم البعيد. اطّلِع على grpc
لمعرفة المزيد من التفاصيل.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Reference implementation\n\nWe provide a\n[reference implementation](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/automotive/vehicle/aidl/impl/current)\nfor the AIDL VHAL. The main service thread is implemented\nat\n[`VehicleService.cpp`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/automotive/vehicle/aidl/impl/current/vhal/src/VehicleService.cpp).\nThe VHAL interface implementation is located at\n[`DefaultVehicleHal.cpp`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/automotive/vehicle/aidl/impl/current/vhal/src/DefaultVehicleHal.cpp).\n\n\nThe reference implementation is based on a two-layer architecture. On the upper layer,\n`DefaultVehicleHal`, implements VHAL AIDL interface and provides VHAL logic\ngeneric to all hardware devices. On the lower layer, `FakeVehicleHardware`,\nimplements the `IVehicleHardware` interface. This class simulates the VHAL logic\nof interacting with actual hardware or vehicle bus and is device-specific. Optionally, vendors\ncan adapt this same architecture, reuse the same `DefaultVehicleHal` class (extending\nit to overwrite a method), and provide their own `IVehicleHardware` implementation.\n**Figure 1.** VHAL reference implementation\n\n[`DefaultVehicleHal`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/automotive/vehicle/aidl/impl/current/vhal/src/DefaultVehicleHal.cpp)\ncontains the following logic, which is considered to be generic and can apply to any VHAL\nimplementation.\n\n- Implements the `IVehicle` interface.\n- Performs basic input checks, including a check for duplicate IDs.\n- Allocates client objects (for example, `GetValuesClient`) for each operation for each binder client, and adds each to a global pool.\n- Manages async callbacks logic, such as adding a pending request to a pending request pool. Resolves pending requests when we receive the results or returns error when one of the pending requests times out.\n- Serializes and deserializes `LargeParcelable` (see `ParcelableUtils.h`).\n- Manages subscription (see `SubscriptionManager.h`).\n- Checks permissions. (See the `checkReadPermission` and `checkWritePermission` functions).\n- Periodically calls `IVehicleHardware.checkHealth` and sends heartbeat signals (see the `checkHealth` function).\n\n[`IVehicleHardware`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/automotive/vehicle/aidl/impl/current/hardware/include/IVehicleHardware.h)\nis a generic interface used to represent a VHAL's hardware-specific\nimplementation. The reference implementation for `IVehicleHardware` is\n[`FakeVehicleHardware`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/automotive/vehicle/aidl/impl/current/fake_impl/hardware/src/FakeVehicleHardware.cpp),\nwhich uses an in-memory map to store property value and does\nnot communicate with an actual vehicle bus. It's intended to run on an emulator and have no\nhardware-specific dependencies. Vendor implementations must not use it as-is and must add\nvehicle bus-specific logic.\n\nStarting in Android 14, `FakeVehicleHardware` reads the supported property config at run-time\nduring initialization from the device's `/vendor/etc/automotive/vhalconfig/` folder,\nwhich contains a JSON-style config file. See the\n[reference VHAL README file](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/automotive/vehicle/aidl/impl/current/default_config/config/README.md)\nfor config file format and config file content.\n\n`FakeVehicleHardware` also supports config file override for testing. If the\nsystem property `persist.vendor.vhal_init_value_override` is set (this property must be\nset at build time or very early during boot before VHAL initialization), it uses the config\nfile from the `/vendor/etc/automotive/vhaloverride/` folder on the device to override\nthe existing configuration. A vendor implementation can use a similar approach so that the VHAL-\nsupported property configuration is not hard-coded and can be dynamically decided at start time.\nThe list of vehicle property configs must be static after VHAL is initialized.\n\nStarting in Android 16, [`GRPCVehicleHardware`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/automotive/vehicle/aidl/impl/current/grpc/GRPCVehicleHardware.cpp)\nprovides another reference `IVehicleHardware` implementation. This implementation\nassumes there is a separate server running on a remote machine or VM which contains the property\nhandling logic. The VHAL running on AAOS devices acts as a proxy that forwards requests to\nthe remote server. See [grpc](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/automotive/vehicle/aidl/impl/current/README.md#grpc)\nfor more details."]]