Search code examples
androidandroid-source

How to get a custom sensors.imx8.so to be used by Android?


I'm porting Android to a custom iMX8 board.

Part of this work is implementing libsensors for this board's hardware, particularly the accelerometer.

ST provide a sensors HAL. This HAL is producing sensors.imx8.so, when Android is built:

smarc_mx8mq:/ # ls -lA vendor/lib/hw/sensors.imx8.so                                                                                          
-rw-r--r-- 1 root root 122684 2021-09-06 14:50 vendor/lib/hw/sensors.imx8.so
smarc_mx8mq:/ # ls -lA vendor/lib64/hw/sensors.imx8.so                                                                                         
-rw-r--r-- 1 root root 144208 2021-09-06 14:50 vendor/lib64/hw/sensors.imx8.so

Android is not using this sensors HAL at all:

smarc_mx8mq:/ # lsof | grep libsensor                                                                                                         
main       3609       root  mem       REG              179,5     94928       2271 /system/lib64/libsensor.so
main       3610       root  mem       REG              179,5     71304       1580 /system/lib/libsensor.so
audioserver  3645 audioserve  mem       REG              179,5     56984       2272 /system/lib64/libsensorprivacy.so
cameraserver  3655 cameraserv  mem       REG              179,5     40852       1581 /system/lib/libsensorprivacy.so
system_server  3890     system  mem       REG              179,5     56600       2274 /system/lib64/libsensorservicehidl.so
...a dozen more lines...

smarc_mx8mq:/ # lsof | grep sensors.imx8
1|smarc_mx8mq:/ #

Android is building the sensors.imx8.so, but not using it or running any part of it. (I've added lots of logging to check.)

How do I make Android use sensors.imx8.so?


Update:

I've found the following lines in adb logcat:

09-03 15:45:27.906  3413  3413 I hwservicemanager: getTransport: Cannot find entry [email protected]::ISensors/default in either framework or device manifest.
09-03 15:45:27.910  3413  3413 I hwservicemanager: getTransport: Cannot find entry [email protected]::ISensors/default in either framework or device manifest.

This makes it look as if I need to add sensors.imx8.so to a manifest, but device/embedian/imx8m/smarc_mx8mq/manifest.xml looks like:

<manifest version="1.0" type="device" target-level="4">
    <hal format="hidl">
        <name>android.hardware.radio</name>
        <transport>hwbinder</transport>
        <version>1.4</version>
        <interface>
            <name>IRadio</name>
            <instance>slot1</instance>
        </interface>
    </hal>
    <hal format="hidl">
        <name>android.hardware.graphics.allocator</name>
        <transport>hwbinder</transport>
        <impl level="generic"></impl>
        <version>2.0</version>
        <interface>
            <name>IAllocator</name>
            <instance>default</instance>
        </interface>
    </hal>
    ...many more...

The stanzas do not specify library (path) names, so I do not see how adding a sensors stanza will help.


Update:

With the stanza:

<hal format="hidl">
    <name>android.hardware.sensors</name>
    <transport>hwbinder</transport>
    <version>1.0</version>
    <interface>
        <name>ISensors</name>
        <instance>default</instance>
    </interface>
</hal>

The errors are now:

09-03 15:52:50.873  3890  3987 I ServiceManagement: getService: Trying again for [email protected]::ISensors/default...
09-03 15:52:51.873  3890  3987 W ServiceManagement: Waited one second for [email protected]::ISensors/default
09-03 15:52:51.874  3890  3987 I ServiceManagement: getService: Trying again for [email protected]::ISensors/default...
09-03 15:52:52.874  3890  3987 W ServiceManagement: Waited one second for [email protected]::ISensors/default
09-03 15:52:52.876  3890  3987 I ServiceManagement: getService: Trying again for [email protected]::ISensors/default...
09-03 15:52:53.876  3890  3987 W ServiceManagement: Waited one second for [email protected]::ISensors/default

I chose version 1.0, after reading https://source.android.com/devices/sensors/hal-interface and https://source.android.com/devices/sensors/sensors-hal2

(The ST Sensors HAL has get_sensors_list() from 1.0 but not getSensorsList() from 2.0.)


Solution

  • The solution was to add:

    PRODUCT_PACKAGES += [email protected]
    PRODUCT_PACKAGES += [email protected]
    

    to smarc_mx8mq.mk and correct the stanza to:

    <hal format="hidl">
        <name>android.hardware.sensors</name>
        <transport>hwbinder</transport>
        <version>1.0</version>
        <interface>
            <name>ISensors</name>
            <instance>default</instance>
        </interface>
        <fqname>@1.0::ISensors/default</fqname>
    </hal>