STMicroelectronics / STMems_Android_Sensor_HAL_IIO

DISCONTINUED (October 2022): the maintenance for this repository has been discontinued. Please refer to https://github.com/STMicroelectronics/st-mems-android-linux-sensors-hal for the up-to-date HAL repository. This repository contains ST Android sensor Hardware Abstraction Layer (HAL) for MEMS Linux IIO drivers
Apache License 2.0
34 stars 21 forks source link

How to get sensors.imx8.so to be used by Android 10? #11

Closed fadedbee closed 2 years ago

fadedbee commented 3 years ago

I've followed the instructions in the README.md and I now have the following shared object libraries:

 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
-rw-r--r-- 1 root root 144208 2021-09-06 14:50 /vendor/lib64/hw/sensors.imx8.so

I have added logging to these libraries and can see that they are not being used. (None of the logging is output.)

This is confirmed by:

    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:/ #

With adb logcat I see:

09-03 15:45:27.906  3413  3413 I hwservicemanager: getTransport: Cannot find entry android.hardware.sensors@2.0::ISensors/default in either framework or device manifest.
09-03 15:45:27.910  3413  3413 I hwservicemanager: getTransport: Cannot find entry android.hardware.sensors@1.0::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. I do not see how adding a sensors stanza will help.

How do I make Android use these new shared libraries and see the accelerometer?

fadedbee commented 3 years ago

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 android.hardware.sensors@1.0::ISensors/default...
    09-03 15:52:51.873  3890  3987 W ServiceManagement: Waited one second for android.hardware.sensors@1.0::ISensors/default
    09-03 15:52:51.874  3890  3987 I ServiceManagement: getService: Trying again for android.hardware.sensors@1.0::ISensors/default...
    09-03 15:52:52.874  3890  3987 W ServiceManagement: Waited one second for android.hardware.sensors@1.0::ISensors/default
    09-03 15:52:52.876  3890  3987 I ServiceManagement: getService: Trying again for android.hardware.sensors@1.0::ISensors/default...
    09-03 15:52:53.876  3890  3987 W ServiceManagement: Waited one second for android.hardware.sensors@1.0::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.)

fadedbee commented 2 years ago

The problem I had was that the vendor AOSP distribution was not including Sensors at all.

The solution was to add:

    PRODUCT_PACKAGES += android.hardware.sensors@1.0-impl
    PRODUCT_PACKAGES += android.hardware.sensors@1.0-service

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>