How to use Bluetooth HIDL?

2.1k views Asked by At

I'm developping an AOSP app that have to send HCI command to Bluetooth chipset.

I found that i can use this interface : https://source.android.com/reference/hidl/android/hardware/bluetooth/1.0/IBluetoothHci

To use it, i tried to follow this page : https://source.android.com/devices/architecture/hidl-java/index.html

If i understand well, i have to create an Android.mk file and put

LOCAL_STATIC_JAVA_LIBRARIES +=  [email protected]

But i don't understand how ? I'm still new in AOSP developpement, how can i use this library ?

1

There are 1 answers

0
Simpl On BEST ANSWER

If you are an application developer:

The IBluetoothHci you found defines the interface of the Bluetooth Hardware Abstraction Layer (HAL). HAL interfaces are not accessible from apps directly but are used by framework services, which provide interfaces that can be used by apps. I recommend checking out the Android SDK: https://developer.android.com/guide/topics/connectivity/bluetooth

If you are a platform developer:

In case you plan to write a service with more privileges (you build the AOSP yourself and flash the whole device) you are right.IBluetoothHci is the interface to use. You would probably want to switch from using Android.mk to Android.bp, because Android.mk files are deprecated. In your code I would expect to see something like this:

import android.hardware.bluetooth.V1_0.IBluetoothHci;
...
// retry to wait until the service starts up if it is in the manifest
IBluetoothHci bluetooth = IBluetoothHci.getService(true /* retry */); // throws NoSuchElementException if not available
bluetooth.initialize();

Hints on how to use a HAL interface can also be found in the respective VTS tests (they are written in C++ though): https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp