summaryrefslogtreecommitdiffstats
path: root/libsuspend
diff options
context:
space:
mode:
authorRuchi Kandoi <kandoiruchi@google.com>2015-05-13 14:57:08 -0700
committerAdam Lesinski <adamlesinski@google.com>2015-06-25 13:15:22 -0700
commitd3027d85f30a13d03e2c58c009215bf0b48f9ac9 (patch)
treed253aac259a7893e97b111c3473cd7bbe037794d /libsuspend
parent3c2086dabdb87e027412bb4405279128a321e184 (diff)
downloadsystem_core-d3027d85f30a13d03e2c58c009215bf0b48f9ac9.zip
system_core-d3027d85f30a13d03e2c58c009215bf0b48f9ac9.tar.gz
system_core-d3027d85f30a13d03e2c58c009215bf0b48f9ac9.tar.bz2
Adds a parameter to the wakeup_callback to report sucessful wakeup or suspend aborts.
Adds the call to wakeup_callback when the write to the /sys/power/state fails. This will help userspace account for the suspend aborts. Bug: 17478088 Bug: 18179405 Change-Id: Icd1194cfbaf61044ca0b2fe63a10a4c52e1535bc
Diffstat (limited to 'libsuspend')
-rw-r--r--libsuspend/autosuspend_wakeup_count.c19
-rw-r--r--libsuspend/include/suspend/autosuspend.h7
2 files changed, 15 insertions, 11 deletions
diff --git a/libsuspend/autosuspend_wakeup_count.c b/libsuspend/autosuspend_wakeup_count.c
index ee4ebe7..23a0290 100644
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -19,6 +19,7 @@
#include <pthread.h>
#include <semaphore.h>
#include <stddef.h>
+#include <stdbool.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -38,7 +39,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 (*wakeup_func)(bool success) = NULL;
static void *suspend_thread_func(void *arg __attribute__((unused)))
{
@@ -46,6 +47,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
char wakeup_count[20];
int wakeup_count_len;
int ret;
+ bool success;
while (1) {
usleep(100000);
@@ -72,6 +74,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
continue;
}
+ success = true;
ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len));
if (ret < 0) {
@@ -81,13 +84,11 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
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)();
- }
+ success = false;
+ }
+ void (*func)(bool success) = wakeup_func;
+ if (func != NULL) {
+ (*func)(success);
}
}
@@ -139,7 +140,7 @@ static int autosuspend_wakeup_count_disable(void)
return ret;
}
-void set_wakeup_callback(void (*func)(void))
+void set_wakeup_callback(void (*func)(bool success))
{
if (wakeup_func != NULL) {
ALOGE("Duplicate wakeup callback applied, keeping original");
diff --git a/libsuspend/include/suspend/autosuspend.h b/libsuspend/include/suspend/autosuspend.h
index 10e3d27..59188a8 100644
--- a/libsuspend/include/suspend/autosuspend.h
+++ b/libsuspend/include/suspend/autosuspend.h
@@ -18,6 +18,7 @@
#define _LIBSUSPEND_AUTOSUSPEND_H_
#include <sys/cdefs.h>
+#include <stdbool.h>
__BEGIN_DECLS
@@ -46,9 +47,11 @@ int autosuspend_disable(void);
/*
* set_wakeup_callback
*
- * Set a function to be called each time the device wakes up from suspend.
+ * Set a function to be called each time the device returns from suspend.
+ * success is true if the suspend was sucessful and false if the suspend
+ * aborted due to some reason.
*/
-void set_wakeup_callback(void (*func)(void));
+void set_wakeup_callback(void (*func)(bool success));
__END_DECLS