Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[hybris-adaptors] Use wakelock to ensure proximity data io. Fixes JB#…
…39550

While android hal takes care of blocking suspend while sensorfwd is
processing sensor events, this does not guarantee that clients receive
sensor changes before the device falls back to suspend.

So far this has not been a problem as only proximity sensor changes are
tracked in suspend and mce can tap into suspend proof evdev input devices
and ignore data passed by sensorfwd. However at least Sony Xperia X does
not make evdev sources available and mce needs to rely on data from
sensorfwd and the device can fall back to suspend before mce has a chance
to read the sensor data.

Obtain a wakelock that is automatically canceled by kernel after one second
when sending proximity sensor data to clients.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Aug 31, 2017
1 parent 818be65 commit ab99754
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions core/hybrisadaptor.cpp
Expand Up @@ -28,6 +28,10 @@
#include <hardware/hardware.h>
#include <hardware/sensors.h>

#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#ifndef SENSOR_TYPE_ACCELEROMETER
#define SENSOR_TYPE_ACCELEROMETER (1)
#endif
Expand Down Expand Up @@ -617,6 +621,29 @@ void HybrisAdaptorReader::startReader()
start();
}

static void ObtainTemporaryWakeLock()
{
static bool triedToOpen = false;
static int wakeLockFd = -1;

if (!triedToOpen) {
triedToOpen = true;
wakeLockFd = ::open("/sys/power/wake_lock", O_RDWR);
if (wakeLockFd == -1) {
sensordLogW() << "wake locks not available:" << ::strerror(errno);
}
}

if (wakeLockFd != -1) {
sensordLogD() << "wake lock to guard sensor data io";
static const char m[] = "sensorfwd_pass_data 1000000000\n";
if( ::write(wakeLockFd, m, sizeof m - 1) == -1 ) {
sensordLogW() << "wake locking failed:" << ::strerror(errno);
::close(wakeLockFd), wakeLockFd = -1;
}
}
}

void HybrisAdaptorReader::run()
{
int err = 0;
Expand All @@ -628,6 +655,7 @@ void HybrisAdaptorReader::run()
sensordLogW() << "poll() failed" << strerror(-err);
QThread::msleep(1000);
} else {
bool blockSuspend = false;
bool errorInInput = false;

for (int i = 0; i < numberOfEvents; i++) {
Expand All @@ -637,9 +665,17 @@ void HybrisAdaptorReader::run()
sensordLogW()<< QString("incorrect event version (version=%1, expected=%2").arg(data.version).arg(sizeof(sensors_event_t));
errorInInput = true;
}
if (data.type == SENSOR_TYPE_PROXIMITY) {
blockSuspend = true;
}
hybrisManager()->processSample(data);

}

if (blockSuspend) {
ObtainTemporaryWakeLock();
}

if (errorInInput)
QThread::msleep(50);
}
Expand Down

0 comments on commit ab99754

Please sign in to comment.