To allow app developers to register new device drivers with the framework, Android Things introduces the concept of a user driver. User drivers are components registered from within apps that extend existing Android framework services. They allow any application to inject hardware events into the framework that other apps can process using the standard Android APIs.
In many apps, using Peripheral I/O to communicate directly with external hardware devices is sufficient. However, there are some benefits to integrating your hardware with the rest of the Android framework:
- Portability: Application code that purely targets the Android framework can run on a variety of different boards and configurations without additional abstractions for the device driver implementation.
- Reuse: You can pull existing Android code snippets and libraries into your application without the need to modify or fork them to handle your specific hardware implementation.
- Integration: Android often combines data from various services together to enhance the information reported to apps or create new virtual data sets. User drivers can contribute to this process.
Device driver types
Location - GNSS satellite constellations, such as GPS, provide high accuracy physical location information to apps. Integrating the location results from receiver devices with a user driver allows the framework to connect that data with other location sources, such as WiFi, and Google's Fused Location Provider.
HID - Human Interface Devices (HID) provide user input to apps. Touch pads, keyboards, and game controllers are all examples of devices that provide this type of input. Input user drivers let devices interact with the enhanced input framework APIs, such as Gesture Support or Drag and Drop.
Sensors - Sensors measure and report the conditions of the physical environment. The Android sensor framework implements sensor fusion to combine the raw data from multiple physical sensors into a single virtual sensor. This is particularly common with motion sensors, such as accelerometers and gyroscopes. Connecting your sensor to the framework with a user driver allows the data it produces to be included in sensor fusion.
LoWPAN - Low-power Wireless Personal Area Networks enable devices to connect and exchange data over local mesh networks. The radios for these networks are specialized and not typically found onboard most devices natively. LoWPAN drivers enable you to integrate an external radio module into the LoWPAN API.
If you separate driver functionality into multiple apps, use foreground services
for all apps except the primary
HOME target. In doing so, you avoid
limitations placed on background apps. For more information, see the Background
Execution Limits guide.