Introduction
With the introduction of Project Treble in Android 8.0, the operating system architectural boundary was split between the framework (System) and the hardware implementation (Vendor). To facilitate this, a new IPC mechanism called HwBinder was created specifically for HALs, along with a dedicated service manager to handle hardware services.
hwservicemanager vs servicemanager
Android runs two distinct binder domains:
/dev/binder: Used by standard framework services (likeActivityManager). Managed by theservicemanagerdaemon./dev/hwbinder: Used by HIDL (Hardware Interface Definition Language) HALs. Managed by thehwservicemanagerdaemon.
hwservicemanager serves the same fundamental purpose as servicemanager: it acts as a central registry where hardware services announce their presence, and clients (like the system server) look them up to establish a connection.
Registering and Retrieving HAL services
A vendor HAL process registers itself with hwservicemanager using the HIDL C++ API registerAsService().
// Vendor HAL process
#include <android/hardware/light/2.0/ILight.h>
using android::hardware::light::V2_0::ILight;
using android::hardware::light::V2_0::implementation::Light;
int main() {
android::sp<ILight> service = new Light();
// Registers with hwservicemanager under the name "default"
android::status_t status = service->registerAsService("default");
android::hardware::joinRpcThreadpool();
return 0;
}
On the framework side, a client retrieves the service using getService():
// Framework client
android::sp<ILight> light = ILight::getService("default");
if (light != nullptr) {
light->setLight(...);
}
HIDL Service Manifest
Unlike the standard servicemanager which accepts any service registration dynamically, hwservicemanager strictly enforces access control via the VINTF (Vendor Interface Object) manifest.
Before a HAL can be registered or retrieved, it must be declared in the device's manifest.xml. If a vendor daemon attempts to register a HIDL service that is not declared in the manifest, hwservicemanager will reject the registration.
<!-- device/vendor/manifest.xml -->
<hal format="hidl">
<name>android.hardware.light</name>
<transport>hwbinder</transport>
<version>2.0</version>
<interface>
<name>ILight</name>
<instance>default</instance>
</interface>
</hal>
This strict manifesto ensures that the framework knows exactly which HAL versions the vendor partition provides at boot time, enforcing Treble compatibility requirements.