summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn2014-03-07 13:00:39 -0600
committerDianne Hackborn2014-03-07 13:00:39 -0600
commit9552cdf434ac1c9ff8730f5492d649845ad4f86c (patch)
tree6eed63de494b181b64a48916e60d2993410f62dd /libsuspend
parent7d2998ea18f099eb24027a546cff6093516de7e5 (diff)
downloadplatform-system-core-9552cdf434ac1c9ff8730f5492d649845ad4f86c.tar.gz
platform-system-core-9552cdf434ac1c9ff8730f5492d649845ad4f86c.tar.xz
platform-system-core-9552cdf434ac1c9ff8730f5492d649845ad4f86c.zip
Add ability to have a callback when wakeups happen.
Change-Id: I02ff0e035bf8a97bd1a3b6b1699181fc3a137d79
Diffstat (limited to 'libsuspend')
-rw-r--r--libsuspend/autosuspend_wakeup_count.c16
-rw-r--r--libsuspend/include/suspend/autosuspend.h7
2 files changed, 23 insertions, 0 deletions
diff --git a/libsuspend/autosuspend_wakeup_count.c b/libsuspend/autosuspend_wakeup_count.c
index a88e67700..7483a8fb2 100644
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -25,6 +25,7 @@
25#include <unistd.h> 25#include <unistd.h>
26 26
27#define LOG_TAG "libsuspend" 27#define LOG_TAG "libsuspend"
28//#define LOG_NDEBUG 0
28#include <cutils/log.h> 29#include <cutils/log.h>
29 30
30#include "autosuspend_ops.h" 31#include "autosuspend_ops.h"
@@ -37,6 +38,7 @@ static int wakeup_count_fd;
37static pthread_t suspend_thread; 38static pthread_t suspend_thread;
38static sem_t suspend_lockout; 39static sem_t suspend_lockout;
39static const char *sleep_state = "mem"; 40static const char *sleep_state = "mem";
41static void (*wakeup_func)(void) = NULL;
40 42
41static void *suspend_thread_func(void *arg __attribute__((unused))) 43static void *suspend_thread_func(void *arg __attribute__((unused)))
42{ 44{
@@ -80,6 +82,11 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
80 if (ret < 0) { 82 if (ret < 0) {
81 strerror_r(errno, buf, sizeof(buf)); 83 strerror_r(errno, buf, sizeof(buf));
82 ALOGE("Error writing to %s: %s\n", SYS_POWER_STATE, buf); 84 ALOGE("Error writing to %s: %s\n", SYS_POWER_STATE, buf);
85 } else {
86 void (*func)(void) = wakeup_func;
87 if (func != NULL) {
88 (*func)();
89 }
83 } 90 }
84 } 91 }
85 92
@@ -131,6 +138,15 @@ static int autosuspend_wakeup_count_disable(void)
131 return ret; 138 return ret;
132} 139}
133 140
141void set_wakeup_callback(void (*func)(void))
142{
143 if (wakeup_func != NULL) {
144 ALOGE("Duplicate wakeup callback applied, keeping original");
145 return;
146 }
147 wakeup_func = func;
148}
149
134struct autosuspend_ops autosuspend_wakeup_count_ops = { 150struct autosuspend_ops autosuspend_wakeup_count_ops = {
135 .enable = autosuspend_wakeup_count_enable, 151 .enable = autosuspend_wakeup_count_enable,
136 .disable = autosuspend_wakeup_count_disable, 152 .disable = autosuspend_wakeup_count_disable,
diff --git a/libsuspend/include/suspend/autosuspend.h b/libsuspend/include/suspend/autosuspend.h
index f56fc6acb..10e3d27d2 100644
--- a/libsuspend/include/suspend/autosuspend.h
+++ b/libsuspend/include/suspend/autosuspend.h
@@ -43,6 +43,13 @@ int autosuspend_enable(void);
43 */ 43 */
44int autosuspend_disable(void); 44int autosuspend_disable(void);
45 45
46/*
47 * set_wakeup_callback
48 *
49 * Set a function to be called each time the device wakes up from suspend.
50 */
51void set_wakeup_callback(void (*func)(void));
52
46__END_DECLS 53__END_DECLS
47 54
48#endif 55#endif