Skip to content

Commit

Permalink
Hold wakelock while there are active power key related timers
Browse files Browse the repository at this point in the history
There is a state machine for separating short, long and double
power key presses. The detection logic uses timers, and we need
to ensure the device does not fall back to suspend while the
timers are active.

[mce] Hold wakelock while there are active power key related timers
  • Loading branch information
spiiroin committed Feb 4, 2014
1 parent 4b477df commit 476dda8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .depend
Expand Up @@ -687,6 +687,7 @@ modules/radiostates.pic.o:\
powerkey.o:\
powerkey.c\
datapipe.h\
libwakelock.h\
mce-conf.h\
mce-dbus.h\
mce-dsme.h\
Expand All @@ -697,6 +698,7 @@ powerkey.o:\
powerkey.pic.o:\
powerkey.c\
datapipe.h\
libwakelock.h\
mce-conf.h\
mce-dbus.h\
mce-dsme.h\
Expand Down
1 change: 1 addition & 0 deletions mce.c
Expand Up @@ -288,6 +288,7 @@ static void mce_cleanup_wakelocks(void)
wakelock_unlock("mce_input_handler");
wakelock_unlock("mce_cpu_keepalive");
wakelock_unlock("mce_display_stm");
wakelock_unlock("mce_powerkey_stm");
}
#endif // ENABLE_WAKELOCKS

Expand Down
54 changes: 54 additions & 0 deletions powerkey.c
Expand Up @@ -73,6 +73,10 @@
* remove_input_trigger_from_datapipe()
*/

#ifdef ENABLE_WAKELOCKS
# include "libwakelock.h"
#endif

#if 0 // DEBUG: make all logging from this module "critical"
# undef mce_log
# define mce_log(LEV, FMT, ARGS...) \
Expand Down Expand Up @@ -113,6 +117,43 @@ static gchar *doublepresssignal = NULL;

static void cancel_powerkey_timeout(void);

/** Check if we need to hold a wakelock for power key handling
*
* Effectively wakelock can be acquired only due to power key
* pressed handling in powerkey_trigger().
*
* Releasing wakelock happens after power key is released
* and/or long/double tap timeouts get triggered.
*
* Timer re-programming does not affect wakelock status on purpose.
*/
static void powerkey_wakelock_rethink(void)
{
#ifdef ENABLE_WAKELOCKS
static bool have_lock = false;

bool want_lock = false;

/* hold wakelock while we have active power key timers */
if( powerkey_timeout_cb_id || doublepress_timeout_cb_id ) {
want_lock = true;
}
if( have_lock == want_lock )
goto EXIT;

if( (have_lock = want_lock) ) {
wakelock_lock("mce_powerkey_stm", -1);
mce_log(LL_DEBUG, "acquire wakelock");
}
else {
mce_log(LL_DEBUG, "release wakelock");
wakelock_unlock("mce_powerkey_stm");
}
EXIT:
return;
#endif
}

/**
* Generic logic for key presses
*
Expand Down Expand Up @@ -263,6 +304,9 @@ static gboolean doublepress_timeout_cb(gpointer data)
generic_powerkey_handler(shortpressaction,
shortpresssignal);

/* Release wakelock if all timers are inactive */
powerkey_wakelock_rethink();

return FALSE;
}

Expand Down Expand Up @@ -415,6 +459,9 @@ static gboolean powerkey_timeout_cb(gpointer data)

handle_longpress();

/* Release wakelock if all timers are inactive */
powerkey_wakelock_rethink();

return FALSE;
}

Expand Down Expand Up @@ -596,6 +643,10 @@ static void powerkey_trigger(gconstpointer const data)
handle_shortpress();
}
}

/* Acquire/release a wakelock depending on whether
* there are active powerkey timers or not */
powerkey_wakelock_rethink();
}

EXIT:
Expand Down Expand Up @@ -742,5 +793,8 @@ void mce_powerkey_exit(void)
g_free(longpresssignal);
g_free(shortpresssignal);

/* Release wakelock */
powerkey_wakelock_rethink();

return;
}

0 comments on commit 476dda8

Please sign in to comment.