[[["เข้าใจง่าย","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-07-27 UTC"],[],[],null,["# Packages\n\n| **Note:** This section uses sample `.hal` files to illustrate how HIDL language constructs map to C++.\n\nWith few exceptions, HIDL interface packages are located in\n`hardware/interfaces` or the `vendor/` directory. The\n`hardware/interfaces` top-level maps directly to the\n`android.hardware` package namespace; the version is a subdirectory\nunder the package (not interface) namespace.\n\nThe `hidl-gen` compiler compiles the `.hal` files into\na set of a `.h` and `.cpp` files. From these autogenerated\nfiles a shared library that client/server implementations link against is built.\nThe `Android.bp` file that builds this shared library is\nautogenerated by the `hardware/interfaces/update-makefiles.sh`\nscript. Every time you add a new package to `hardware/interfaces`, or\nadd/remove `.hal` files to/from an existing package, you must rerun\nthe script to ensure the generated shared library is up-to-date.\n\nFor example, the `IFoo.hal` sample file should be located in\n`hardware/interfaces/samples/1.0`. The sample\n`IFoo.hal` file creates an IFoo interface in the\n**samples** package: \n\n```c++\npackage android.hardware.samples@1.0;\ninterface IFoo {\n struct Foo {\n int64_t someValue;\n handle myHandle;\n };\n\n someMethod() generates (vec\u003cuint32_t\u003e);\n anotherMethod(Foo foo) generates (int32_t ret);\n};\n```\n\nGenerated files\n---------------\n\nAutogenerated files in a HIDL package are linked into a single shared\nlibrary with the same name as the package (for example,\n`android.hardware.samples@1.0`). The shared library also exports a\nsingle header, `IFoo.h`, which can be included by clients and\nservers. Using the `hidl-gen` compiler with the `IFoo.hal`\ninterface file as an input, binderized mode has the following autogenerated\nfiles:\n\n**Figure 1.** Files generated by compiler.\n\n- `IFoo.h`. Describes the pure `IFoo` interface in a C++ class; it contains the methods and types defined in the `IFoo` interface in the `IFoo.hal` file, translated to C++ types where necessary. **Doesn't contain** details related to the RPC mechanism (for example, `HwBinder`) used to implement this interface. The class is namespaced with the package and version, for example, `::android::hardware::samples::IFoo::V1_0`. Both clients and servers include this header: Clients for calling methods on it and servers for implementing those methods.\n- `IHwFoo.h`. Header file that contains declarations for functions that serialize data types used in the interface. Developers should never include his header directly (it doesn't contain any classes).\n- `BpHwFoo.h`. A class that inherits from `IFoo` and describes the `HwBinder` proxy (client-side) implementation of the interface. Developers should never refer to this class directly.\n- `BnHwFoo.h`. A class that holds a reference to an `IFoo` implementation and describes the `HwBinder` stub (server-side) implementation of the interface. Developers should never refer to this class directly.\n- `FooAll.cpp`. A class that contains the implementations for both the `HwBinder` proxy and the `HwBinder` stub. When a client calls an interface method, the proxy automatically marshals the arguments from the client and sends the transaction to the binder kernel driver, which delivers the transaction to the stub on the other side (which then calls the actual server implementation).\n\nThe files are structured similarly to the files generated by\n`aidl-cpp` (for details, see \"Passthrough mode\" in the\n[HIDL Overview](/docs/core/architecture/hidl)). The only\nautogenerated file that is independent of the RPC mechanism used by HIDL is\n`IFoo.h`; all other files are tied to the HwBinder RPC mechanism used\nby HIDL. Therefore, client and server implementations **should never\ndirectly refer to anything other than `IFoo`** . To achieve\nthis, include only `IFoo.h` and link against the generated shared\nlibrary.\n| **Note:** HwBinder is only one possible transport; new transports might be added in the future.\n\nLink to shared libraries\n------------------------\n\nA client or server that uses any interface in a package must include the\nshared library of that package in **one (1)** of the following\nlocations:\n\n- In **Android.mk** : \n\n ```c++\n LOCAL_SHARED_LIBRARIES += android.hardware.samples@1.0\n ```\n- In **Android.bp** : \n\n ```c++\n shared_libs: [\n /* ... */\n \"android.hardware.samples@1.0\",\n ],\n ```\n\nAdditional libraries you might need to include:\n\n| `libhidlbase` | Includes standard HIDL data types. Starting in Android 10, this also contains all of the symbols previously in `libhidltransport` and `libhwbinder`. |\n| `libhidltransport` | Handles the transport of HIDL calls over different RPC/IPC mechanisms. **Android 10 deprecates this library.** |\n| `libhwbinder` | Binder-specific symbols. **Android 10 deprecates this library.** |\n| `libfmq` | Fast Message Queue IPC. |\n|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|\n\nNamespaces\n----------\n\nHIDL functions and types such as `Return\u003cT\u003e` and\n`Void()` are declared in namespace `::android::hardware`.\nThe C++ namespace of a package is determined by the package name and version.\nFor example, a package **mypackage** with version 1.2 under\n`hardware/interfaces` has the following qualities:\n\n- **C++ namespace** is `::android::hardware::mypackage::V1_2`\n- **Fully qualified name** of `IMyInterface` in that package is: `::android::hardware::mypackage::V1_2::IMyInterface`. (`IMyInterface` is an identifier, not part of the namespace).\n- **Types** defined in the package's `types.hal` file are identified as: `::android::hardware::mypackage::V1_2::MyPackageType`"]]