Android HALs: How Android Talks to Custom Hardware
On a Linux system an application can often open a device node and start talking to hardware. Android does not work that way. Apps call framework APIs, framework services call a hardware abstraction layer, and only the HAL talks to the kernel driver. Since Android 8 that HAL usually runs as a separate process behind a versioned interface, so the vendor and framework sides can be updated independently.
At a glance
- Android 8
- Project Treble moved HALs behind stable interfaces, separating vendor code from the framework.
- AIDL
- The interface language for new HALs. HIDL is deprecated and should not be used for new work.
- Binder
- The inter-process transport between framework services and HAL processes.
- VINTF
- Manifests and compatibility matrices declaring which HAL versions a device provides and the framework needs.
The problem
Teams new to Android often write a kernel driver, open up the permissions on its device node and call it from an app through JNI. It may work on a development build, but SELinux will deny it on a production build, it bypasses the permission model, and it breaks the separation that lets the system image be updated without rebuilding vendor code.
The opposite mistake is forcing custom hardware into a standard HAL that does not fit, such as presenting a measurement instrument as a sensor, and losing the controls the product actually needs.
On Android the kernel driver is only half the job; the HAL interface is the contract everything above it depends on.
Standard or custom HAL
Where Android already defines a HAL for the device class, such as sensors, camera, audio, lights or power, implement that interface. The framework, apps and compatibility tests then work without changes.
For hardware with no standard HAL, define a vendor AIDL interface marked as stable, version it, and freeze each version before shipping. Expose it through a system service or privileged app, and write SELinux policy that grants only the HAL process access to the device node.
What good looks like
Check whether a standard Android HAL covers the device. If one does, implement it rather than inventing a parallel path.
If not, design a small vendor AIDL interface around what the product needs, not around the register map, and declare it in the device VINTF manifest.
Write the HAL service, init script and SELinux policy together, and test on a user build, as customers will run it.
From app to hardware
- App: Public or vendor API
- Framework service: Permissions and policy
- AIDL HAL: Vendor process, over Binder
- Kernel driver: Device node or sysfs
- Hardware: Registers, buses, interrupts
| Style | Introduced | Status for new work |
|---|---|---|
| Legacy libhardware HAL | Early Android | Superseded; loaded into the calling process |
| Passthrough HIDL | Android 8 | Transitional; avoid for new designs |
| Binderized HIDL | Android 8 | Deprecated; maintain existing HALs only |
| Stable AIDL | Android 11 | Recommended for new HALs |
What it changes
Updatable System
Vendor and framework code can be updated independently because they meet at a versioned interface.
Security
Only the HAL process touches the hardware, and SELinux enforces that on every build.
Compatibility
Standard HALs keep the device passing vendor tests and working with ordinary apps.
Maintainability
A frozen, versioned interface lets the HAL evolve without breaking existing clients.
Where to go next
Keep the HAL thin. Put policy and product logic in the framework or app layer, where it is easier to change and test.
An existing Linux user-space library can sit inside the HAL, if its licence and dependencies suit the vendor partition.
Problems this prevents
- Apps opening device nodes directly
- SELinux denials found only on user builds
- A new HAL written in deprecated HIDL
- Unversioned interfaces that break clients on update
Discuss your project
Email support@aavico.com or use Get in Touch when the website finishes loading.