Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Wakeup from suspend to end autolock grace period
When display is first dimmed and then blanked based on user inactivity,
the tklock is not immediately set. This so called grace period allows
user some time wake up the display and still get back to the application
that was active before blanking. But in case the device suspends, it
can also mean that things like device lock and application activity
states evaluation gets delayed until the device wakes up from suspend
to turn on the display - which can cause for example visual hiccups
and missing notification leds.

Use the mce-hbtimer functionality to force wakeup from suspend when
the grace period is up.

[mce] Wakeup from suspend to end autolock grace period. Fixes JB#28706
  • Loading branch information
spiiroin committed May 19, 2015
1 parent 6112f54 commit b7761eb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .depend
Expand Up @@ -1073,6 +1073,7 @@ tklock.o:\
mce-conf.h\
mce-dbus.h\
mce-gconf.h\
mce-hbtimer.h\
mce-io.h\
mce-log.h\
mce.h\
Expand All @@ -1090,6 +1091,7 @@ tklock.pic.o:\
mce-conf.h\
mce-dbus.h\
mce-gconf.h\
mce-hbtimer.h\
mce-io.h\
mce-log.h\
mce.h\
Expand Down
98 changes: 45 additions & 53 deletions tklock.c
Expand Up @@ -29,6 +29,7 @@
#include "mce-conf.h"
#include "mce-gconf.h"
#include "mce-dbus.h"
#include "mce-hbtimer.h"
#include "evdev.h"

#ifdef ENABLE_WAKELOCKS
Expand Down Expand Up @@ -187,11 +188,12 @@ static void tklock_lid_sensor_rethink(void);
// autolock state machine

static gboolean tklock_autolock_cb(gpointer aptr);
static void tklock_autolock_resume(void);
static void tklock_autolock_evaluate(void);
static void tklock_autolock_enable(void);
static void tklock_autolock_disable(void);
static void tklock_autolock_rethink(void);
static void tklock_autolock_init(void);
static void tklock_autolock_quit(void);

// proximity locking state machine

Expand Down Expand Up @@ -626,15 +628,8 @@ static void tklock_datapipe_device_resumed_cb(gconstpointer data)
{
(void) data;

/* We do not want to wakeup from suspend just to end the
* grace period, so regular timer is used for it. However,
* if we happen to resume for some other reason, check if
* the timeout has already passed */

tklock_autolock_resume();

/* And the same applies for proximity locking too */

/* Re-evaluate proximity locking after resuming from
* suspend. */
tklock_proxlock_resume();
}

Expand Down Expand Up @@ -2235,7 +2230,7 @@ static void tklock_lid_sensor_rethink(void)
* ========================================================================= */

static int64_t tklock_autolock_tick = MAX_TICK;
static guint tklock_autolock_id = 0;
static mce_hbtimer_t *tklock_autolock_timer = 0;

static void tklock_autolock_evaluate(void)
{
Expand Down Expand Up @@ -2275,66 +2270,44 @@ static gboolean tklock_autolock_cb(gpointer aptr)
{
(void)aptr;

if( tklock_autolock_id ) {
tklock_autolock_id = 0;
tklock_autolock_tick = MIN_TICK;
tklock_autolock_tick = MIN_TICK;
mce_log(LL_DEBUG, "autolock timer triggered");
tklock_autolock_evaluate();

mce_log(LL_DEBUG, "autolock timer triggered");
tklock_autolock_evaluate();
}
return false;
return FALSE;
}

static void tklock_autolock_disable(void)
{
tklock_autolock_tick = MAX_TICK;

if( tklock_autolock_id ) {
g_source_remove(tklock_autolock_id), tklock_autolock_id = 0;
mce_log(LL_DEBUG, "autolock timer stopped");
}
}

static void tklock_autolock_resume(void)
{
/* Do we have a timer to re-evaluate? */
if( !tklock_autolock_id )
if( !mce_hbtimer_is_active(tklock_autolock_timer) )
goto EXIT;

/* Clear old timer */
g_source_remove(tklock_autolock_id), tklock_autolock_id = 0;

int64_t now = tklock_monotick_get();

if( now >= tklock_autolock_tick ) {
/* Opportunistic triggering on resume */
mce_log(LL_DEBUG, "autolock time passed while suspended");
tklock_autolock_tick = MIN_TICK;
tklock_autolock_evaluate();
}
else {
/* Re-calculate wakeup time */
int delay = (int)(tklock_autolock_tick - now);
mce_log(LL_DEBUG, "adjusting autolock time after resume (%d ms)", delay);
tklock_autolock_id = g_timeout_add(delay, tklock_autolock_cb, 0);
}
mce_hbtimer_stop(tklock_autolock_timer);
mce_log(LL_DEBUG, "autolock timer stopped");

EXIT:
return;
}

static void tklock_autolock_enable(void)
{
if( !tklock_autolock_id ) {
int delay = mce_clip_int(MINIMUM_AUTOLOCK_DELAY,
MAXIMUM_AUTOLOCK_DELAY,
tklock_autolock_delay);
if( mce_hbtimer_is_active(tklock_autolock_timer) )
goto EXIT;

tklock_autolock_tick = tklock_monotick_get() + delay;
int delay = mce_clip_int(MINIMUM_AUTOLOCK_DELAY,
MAXIMUM_AUTOLOCK_DELAY,
tklock_autolock_delay);

tklock_autolock_id = g_timeout_add(delay, tklock_autolock_cb, 0);
mce_log(LL_DEBUG, "autolock timer started (%d ms)", delay);
}
tklock_autolock_tick = tklock_monotick_get() + delay;

mce_hbtimer_set_period(tklock_autolock_timer, delay);
mce_hbtimer_start(tklock_autolock_timer);
mce_log(LL_DEBUG, "autolock timer started (%d ms)", delay);

EXIT:
return;
}

static void tklock_autolock_rethink(void)
Expand All @@ -2353,6 +2326,21 @@ static void tklock_autolock_rethink(void)
}
}

static void
tklock_autolock_init(void)
{
tklock_autolock_timer = mce_hbtimer_create("autolock-timer",
tklock_autolock_delay,
tklock_autolock_cb, 0);
}

static void
tklock_autolock_quit(void)
{
mce_hbtimer_delete(tklock_autolock_timer),
tklock_autolock_timer = 0;
}

/* ========================================================================= *
* PROXIMITY LOCKING STATE MACHINE
*
Expand Down Expand Up @@ -5463,6 +5451,8 @@ gboolean mce_tklock_init(void)
/* get dynamic config, install change monitors */
tklock_gconf_init();

tklock_autolock_init();

/* attach to internal state variables */
tklock_datapipe_init();

Expand Down Expand Up @@ -5493,6 +5483,8 @@ void mce_tklock_exit(void)
tklock_notif_quit();
tklock_ui_notify_cancel();

tklock_autolock_quit();

// FIXME: check that final state is sane

return;
Expand Down

0 comments on commit b7761eb

Please sign in to comment.