Search code examples
androidandroid-sensorshalsensormanager

Android HAL makes system stuck in poll() function


We are working on custom development board and currently, we are implementing "Sensor HAL" on Android 7.1.

We have implemented "Sensor HAL" APIs as per Android sensor service requirement(sensor.h) and able to build .so file for the same. (Due to some custom modifications we are not able to use the already available HAL.)

After integrating "Sensor HAL" we see Android goes in the hung state and not able to reach till Android lock screen.

Our observation w.r.t Android Sensor service behavior

  1. SensorService: nuSensorService starting...

  2. "Sensor HAL" Loaded by sensor service

  3. "Sensor HAL" open call successful

  4. "Sensor HAL" get_sensor_list call successful

  5. "Sensor HAL" poll function call successful every-time.

  6. Android booting stuck at "Bootanimation" screen

LOGS FOR REFERENCE

01-01 00:58:48.258 1461 1461 D SensorService: nuSensorService starting...
01-01 00:58:48.260 1461 1461 D Sensor_HAL: OpenSensors: name=poll
01-01 00:58:48.260 1461 1461 D Sensor_HAL: Exiting... OpenSensors: name=poll
01-01 00:58:48.260 1461 1461 D Sensor_HAL: Entering @GetSensorList
01-01 00:58:48.260 1461 1461 D Sensor_HAL: Exiting @GetSensorList
01-01 00:58:48.261 1461 1461 D Sensor_HAL: Entering @SensorDeviceActivate, handle 0, enabled 0
01-01 00:58:48.261 1461 1461 D Sensor_HAL: Entering @SensorDeviceActivate, handle 1, enabled 0
01-01 00:58:48.262 1461 1461 D Sensor_HAL: Entering @SensorDeviceActivate, handle 2, enabled 0
01-01 00:58:48.262 1461 1461 D Sensor_HAL: Entering @GetSensorList
01-01 00:58:48.262 1461 1461 D Sensor_HAL: Exiting @GetSensorList
01-01 00:58:48.262 1461 1461 D Sensor_HAL: Entering @GetSensorList
01-01 00:58:48.262 1461 1461 D Sensor_HAL: Exiting @GetSensorList
01-01 00:58:48.264 1461 1463 D SensorService: nuSensorService thread starting...
01-01 00:58:49.953 1461 1462 D SensorService: new thread SensorEventAckReceiver

=> The above calls poll function which is causing the system hang.

=> Android booting stuck here.

Please note that the current implementation of poll() command is returning the dummy Accelerometer events with timestamps to the upper layer. The return value is the number of data events copied.

Please correct me if you find something is missing or wrong in understanding.


Solution

  • Guys,

    Finally, I am able to fix this issue with the delay adding in the same function.

    Poll() function is being called in the thread and sending events to system client (SensorManager). Since we are directly returning from the function without any delay, the events will be pushed at larger speed and there is no time for scheduling of other threads.

    For this to complete consider amount of delay is required.