diff options
author | Dianne Hackborn <hackbod@google.com> | 2014-03-07 11:00:39 -0800 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2014-03-07 11:00:39 -0800 |
commit | 9552cdf434ac1c9ff8730f5492d649845ad4f86c (patch) | |
tree | 6eed63de494b181b64a48916e60d2993410f62dd | |
parent | 7d2998ea18f099eb24027a546cff6093516de7e5 (diff) | |
download | system_core-9552cdf434ac1c9ff8730f5492d649845ad4f86c.zip system_core-9552cdf434ac1c9ff8730f5492d649845ad4f86c.tar.gz system_core-9552cdf434ac1c9ff8730f5492d649845ad4f86c.tar.bz2 |
Add ability to have a callback when wakeups happen.
Change-Id: I02ff0e035bf8a97bd1a3b6b1699181fc3a137d79
-rw-r--r-- | libsuspend/autosuspend_wakeup_count.c | 16 | ||||
-rw-r--r-- | libsuspend/include/suspend/autosuspend.h | 7 |
2 files changed, 23 insertions, 0 deletions
diff --git a/libsuspend/autosuspend_wakeup_count.c b/libsuspend/autosuspend_wakeup_count.c index a88e677..7483a8f 100644 --- a/libsuspend/autosuspend_wakeup_count.c +++ b/libsuspend/autosuspend_wakeup_count.c @@ -25,6 +25,7 @@ #include <unistd.h> #define LOG_TAG "libsuspend" +//#define LOG_NDEBUG 0 #include <cutils/log.h> #include "autosuspend_ops.h" @@ -37,6 +38,7 @@ static int wakeup_count_fd; static pthread_t suspend_thread; static sem_t suspend_lockout; static const char *sleep_state = "mem"; +static void (*wakeup_func)(void) = NULL; static void *suspend_thread_func(void *arg __attribute__((unused))) { @@ -80,6 +82,11 @@ static void *suspend_thread_func(void *arg __attribute__((unused))) if (ret < 0) { strerror_r(errno, buf, sizeof(buf)); ALOGE("Error writing to %s: %s\n", SYS_POWER_STATE, buf); + } else { + void (*func)(void) = wakeup_func; + if (func != NULL) { + (*func)(); + } } } @@ -131,6 +138,15 @@ static int autosuspend_wakeup_count_disable(void) return ret; } +void set_wakeup_callback(void (*func)(void)) +{ + if (wakeup_func != NULL) { + ALOGE("Duplicate wakeup callback applied, keeping original"); + return; + } + wakeup_func = func; +} + struct autosuspend_ops autosuspend_wakeup_count_ops = { .enable = autosuspend_wakeup_count_enable, .disable = autosuspend_wakeup_count_disable, diff --git a/libsuspend/include/suspend/autosuspend.h b/libsuspend/include/suspend/autosuspend.h index f56fc6a..10e3d27 100644 --- a/libsuspend/include/suspend/autosuspend.h +++ b/libsuspend/include/suspend/autosuspend.h @@ -43,6 +43,13 @@ int autosuspend_enable(void); */ int autosuspend_disable(void); +/* + * set_wakeup_callback + * + * Set a function to be called each time the device wakes up from suspend. + */ +void set_wakeup_callback(void (*func)(void)); + __END_DECLS #endif |