2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
ネイティブ クライアントで VHAL を使用する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
VHAL では、Java とネイティブ クライアントをサポートしています。カーサービスは、VHAL の唯一の Java クライアントです。一般的な自動車アプリでは、Car API(CarPropertyManager
など)を使用して VHAL のプロパティにアクセスします。VHAL との直接通信は行いません。実際、SELinux にブロックされます。詳しくは、パッケージ インデックスの Car API ドキュメントをご覧ください。
Android 13 以降のネイティブ クライアントでは、VHAL と直接通信する代わりに libvhalclient
を使用します。これは、AIDL および HIDL VHAL 実装のための 1 つの共通インターフェース、IVhalClient.h
を公開するクライアント ライブラリです。次の例は、VHAL ネイティブ クライアントを作成し、それを使用して車両識別番号(VIN)を取得する方法を示しています。
using ::aidl::android::hardware::automotive::vehicle::VehicleProperty;
using ::android::frameworks::automotive::vhal::IVhalClient;
using ::android::hardware::automotive::vehicle::toInt;
auto vhalClient = IVhalClient::tryCreate();
if (vhalClient == nullptr) {
// handle error.
}
auto result = vhalClient->getValueSync(
*vhalClient->createHalPropValue(toInt(VehicleProperty::INFO_VIN)));
// Use result
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-03-26 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-26 UTC。"],[],[],null,["# Use VHAL with the native client\n\nVHAL supports Java and native clients. Car Service is the only\nJava client for VHAL. For car apps, use the Car APIs (for example,\n[`CarPropertyManager`](https://developer.android.com/reference/android/car/hardware/property/CarPropertyManager))\nto access VHAL properties instead of directly communicating with\nthe VHAL. In fact, SELinux blocks direct access. For details, see the Car API documentation at\n[Package Index](https://developer.android.com/reference/android/car/packages).\n\nFor native clients, starting with Android 13, use\n[`libvhalclient`](https://android.googlesource.com/platform/packages/services/Car/+/refs/heads/android16-release/cpp/vhal/client/) instead of directly\nconnecting with VHAL. This is a client library that exposes one common interface,\n`IVhalClient.h` for AIDL and HIDL VHAL implementations. The following example shows\nhow to create a VHAL native client and use it to get a Vehicle Identification Number (VIN) number: \n\n```c++\n#include \u003cIVhalClient.h\u003e\n#include \u003cVehicleHalTypes.h\u003e\n#include \u003cVehicleUtils.h\u003e\n\nusing ::aidl::android::hardware::automotive::vehicle::VehicleProperty;\nusing ::android::frameworks::automotive::vhal::IVhalClient;\nusing ::android::hardware::automotive::vehicle::toInt;\n\nint main(int argc, char** argv) {\n auto vhalClient = IVhalClient::tryCreate();\n if (vhalClient == nullptr) {\n // handle error.\n return -1;\n }\n auto result = vhalClient-\u003egetValueSync(\n *vhalClient-\u003ecreateHalPropValue(toInt(VehicleProperty::INFO_VIN)));\n // Use result\n\n return 0;\n}\n```\n\nYou must configure SELinux policy to allow your native client to access VHAL. For example: \n\n```text\n# Define my domain\ntype my_native_daemon, domain;\n\n# Define the exec file type.\ntype my_native_daemon_exec, exec_type, file_type, system_file_type;\n\n# Initialize domain.\ninit_daemon_domain(my_native_daemon)\n\n# Allow using hwbinder for HIDL VHAL, not required if AIDL is used.\nhwbinder_use(my_native_daemon)\n# Allow using binder for AIDL VHAL\nbinder_use(my_native_daemon)\n# Allow my_native_daemon to be a VHAL client.\nhal_client_domain(my_native_daemon, hal_vehicle)\n```\n\n\u003cbr /\u003e"]]