Skip to content

Commit

Permalink
Re-evaluate autolock if device wakes up from suspend
Browse files Browse the repository at this point in the history
When display is automatically dimmed and then blanked there is a 30 second
grace period before tklock gets applied. Since the device most likely
also suspends soon after blanking the screen and we do not want to wake
up just to toggle the tklock state, the end of grace period is evaluated
when display is about to be turned on. This can cause ipc timing problems
if powerkey/doubletap is configured also to remove the tklock.

Also do opportunistic grace period end detection if the device wakes up
from suspend due to reasons that would not cause the display to turn on.
This should make it less likely that both lock and unlock happen at the
same time.

[mce] Re-evaluate autolock if device wakes up from suspend
  • Loading branch information
spiiroin committed Oct 28, 2014
1 parent 6154e96 commit 9efa7db
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions datapipe.c
Expand Up @@ -42,6 +42,9 @@ datapipe_struct led_pattern_activate_pipe;
/** LED pattern to deactivate; read only */
datapipe_struct led_pattern_deactivate_pipe;

/** resumed from suspend notification; read only */
datapipe_struct device_resumed_pipe;

/** Non-synthetized user activity; read only */
datapipe_struct user_activity_pipe;

Expand Down Expand Up @@ -802,6 +805,8 @@ void mce_datapipe_init(void)
0, GINT_TO_POINTER(0));
setup_datapipe(&led_pattern_activate_pipe, READ_ONLY, FREE_CACHE,
0, NULL);
setup_datapipe(&device_resumed_pipe, READ_ONLY, DONT_FREE_CACHE,
0, NULL);
setup_datapipe(&led_pattern_deactivate_pipe, READ_ONLY, FREE_CACHE,
0, NULL);
setup_datapipe(&user_activity_pipe, READ_ONLY, DONT_FREE_CACHE,
Expand Down Expand Up @@ -905,6 +910,7 @@ void mce_datapipe_quit(void)
free_datapipe(&user_activity_pipe);
free_datapipe(&led_pattern_deactivate_pipe);
free_datapipe(&led_pattern_activate_pipe);
free_datapipe(&device_resumed_pipe);
free_datapipe(&led_brightness_pipe);
free_datapipe(&lpm_brightness_pipe);
free_datapipe(&display_brightness_pipe);
Expand Down
1 change: 1 addition & 0 deletions datapipe.h
Expand Up @@ -79,6 +79,7 @@ extern datapipe_struct lpm_brightness_pipe;
extern datapipe_struct device_inactive_pipe;
extern datapipe_struct led_pattern_activate_pipe;
extern datapipe_struct led_pattern_deactivate_pipe;
extern datapipe_struct device_resumed_pipe;
extern datapipe_struct user_activity_pipe;
extern datapipe_struct display_state_pipe;
extern datapipe_struct display_state_req_pipe;
Expand Down
5 changes: 5 additions & 0 deletions mce-io.c
Expand Up @@ -187,6 +187,11 @@ static void io_detect_resume(void)
mce_log(LL_DEVEL, "time skip: assume %"PRId64".%03"PRId64"s suspend",
skip / 1000, skip % 1000);

// notify in case some timers need re-evaluating
execute_datapipe_output_triggers(&device_resumed_pipe,
&prev,
USE_INDATA);

EXIT:
return;
}
Expand Down
47 changes: 47 additions & 0 deletions tklock.c
Expand Up @@ -173,6 +173,7 @@ static int64_t tklock_monotick_get(void);

static void tklock_datapipe_system_state_cb(gconstpointer data);
static void tklock_datapipe_device_lock_active_cb(gconstpointer data);
static void tklock_datapipe_device_resumed_cb(gconstpointer data);
static void tklock_datapipe_lipstick_available_cb(gconstpointer data);
static void tklock_datapipe_update_mode_cb(gconstpointer data);
static void tklock_datapipe_display_state_cb(gconstpointer data);
Expand Down Expand Up @@ -215,6 +216,7 @@ static void tklock_datapipe_quit(void);

static gboolean tklock_autolock_cb(gpointer aptr);
static bool tklock_autolock_exceeded(void);
static void tklock_autolock_reschedule(void);
static void tklock_autolock_schedule(int delay);
static void tklock_autolock_cancel(void);
static void tklock_autolock_rethink(void);
Expand Down Expand Up @@ -557,6 +559,19 @@ static void tklock_datapipe_device_lock_active_cb(gconstpointer data)
return;
}

/** Resumed from suspend notification */
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_reschedule();
}

/** Lipstick dbus name is reserved; assume false */
static bool lipstick_available = false;

Expand Down Expand Up @@ -1532,6 +1547,10 @@ static void tklock_datapipe_user_activity_cb(gconstpointer data)
static datapipe_binding_t tklock_datapipe_triggers[] =
{
// output triggers
{
.datapipe = &device_resumed_pipe,
.output_cb = tklock_datapipe_device_resumed_cb,
},
{
.datapipe = &lipstick_available_pipe,
.output_cb = tklock_datapipe_lipstick_available_cb,
Expand Down Expand Up @@ -1796,6 +1815,34 @@ static void tklock_autolock_cancel(void)
}
}

static void tklock_autolock_reschedule(void)
{
/* Do we have a timer to re-evaluate? */
if( !tklock_autolock_id )
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 ) {
mce_log(LL_DEBUG, "autolock time passed while suspended; lock now");
/* Trigger time passed while suspended */
tklock_autolock_tick = MAX_TICK;
tklock_ui_set(true);
}
else {
/* Re-calculate wakeup time */
mce_log(LL_DEBUG, "adjusting autolock time after resume");
int delay = (int)(tklock_autolock_tick - now);
tklock_autolock_id = g_timeout_add(delay, tklock_autolock_cb, 0);
}

EXIT:
return;
}

static void tklock_autolock_schedule(int delay)
{
if( tklock_autolock_id )
Expand Down

0 comments on commit 9efa7db

Please sign in to comment.