summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuchi Kandoi2015-05-13 16:57:08 -0500
committerAdam Lesinski2015-06-25 15:15:22 -0500
commitd3027d85f30a13d03e2c58c009215bf0b48f9ac9 (patch)
treed253aac259a7893e97b111c3473cd7bbe037794d /libsuspend
parent3c2086dabdb87e027412bb4405279128a321e184 (diff)
downloadplatform-system-core-d3027d85f30a13d03e2c58c009215bf0b48f9ac9.tar.gz
platform-system-core-d3027d85f30a13d03e2c58c009215bf0b48f9ac9.tar.xz
platform-system-core-d3027d85f30a13d03e2c58c009215bf0b48f9ac9.zip
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 ee4ebe74a..23a029027 100644
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -19,6 +19,7 @@
19#include <pthread.h> 19#include <pthread.h>
20#include <semaphore.h> 20#include <semaphore.h>
21#include <stddef.h> 21#include <stddef.h>
22#include <stdbool.h>
22#include <string.h> 23#include <string.h>
23#include <sys/stat.h> 24#include <sys/stat.h>
24#include <sys/types.h> 25#include <sys/types.h>
@@ -38,7 +39,7 @@ static int wakeup_count_fd;
38static pthread_t suspend_thread; 39static pthread_t suspend_thread;
39static sem_t suspend_lockout; 40static sem_t suspend_lockout;
40static const char *sleep_state = "mem"; 41static const char *sleep_state = "mem";
41static void (*wakeup_func)(void) = NULL; 42static void (*wakeup_func)(bool success) = NULL;
42 43
43static void *suspend_thread_func(void *arg __attribute__((unused))) 44static void *suspend_thread_func(void *arg __attribute__((unused)))
44{ 45{
@@ -46,6 +47,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
46 char wakeup_count[20]; 47 char wakeup_count[20];
47 int wakeup_count_len; 48 int wakeup_count_len;
48 int ret; 49 int ret;
50 bool success;
49 51
50 while (1) { 52 while (1) {
51 usleep(100000); 53 usleep(100000);
@@ -72,6 +74,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
72 continue; 74 continue;
73 } 75 }
74 76
77 success = true;
75 ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count); 78 ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
76 ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len)); 79 ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len));
77 if (ret < 0) { 80 if (ret < 0) {
@@ -81,13 +84,11 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
81 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE); 84 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
82 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state))); 85 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
83 if (ret < 0) { 86 if (ret < 0) {
84 strerror_r(errno, buf, sizeof(buf)); 87 success = false;
85 ALOGE("Error writing to %s: %s\n", SYS_POWER_STATE, buf); 88 }
86 } else { 89 void (*func)(bool success) = wakeup_func;
87 void (*func)(void) = wakeup_func; 90 if (func != NULL) {
88 if (func != NULL) { 91 (*func)(success);
89 (*func)();
90 }
91 } 92 }
92 } 93 }
93 94
@@ -139,7 +140,7 @@ static int autosuspend_wakeup_count_disable(void)
139 return ret; 140 return ret;
140} 141}
141 142
142void set_wakeup_callback(void (*func)(void)) 143void set_wakeup_callback(void (*func)(bool success))
143{ 144{
144 if (wakeup_func != NULL) { 145 if (wakeup_func != NULL) {
145 ALOGE("Duplicate wakeup callback applied, keeping original"); 146 ALOGE("Duplicate wakeup callback applied, keeping original");
diff --git a/libsuspend/include/suspend/autosuspend.h b/libsuspend/include/suspend/autosuspend.h
index 10e3d27d2..59188a804 100644
--- a/libsuspend/include/suspend/autosuspend.h
+++ b/libsuspend/include/suspend/autosuspend.h
@@ -18,6 +18,7 @@
18#define _LIBSUSPEND_AUTOSUSPEND_H_ 18#define _LIBSUSPEND_AUTOSUSPEND_H_
19 19
20#include <sys/cdefs.h> 20#include <sys/cdefs.h>
21#include <stdbool.h>
21 22
22__BEGIN_DECLS 23__BEGIN_DECLS
23 24
@@ -46,9 +47,11 @@ int autosuspend_disable(void);
46/* 47/*
47 * set_wakeup_callback 48 * set_wakeup_callback
48 * 49 *
49 * Set a function to be called each time the device wakes up from suspend. 50 * Set a function to be called each time the device returns from suspend.
51 * success is true if the suspend was sucessful and false if the suspend
52 * aborted due to some reason.
50 */ 53 */
51void set_wakeup_callback(void (*func)(void)); 54void set_wakeup_callback(void (*func)(bool success));
52 55
53__END_DECLS 56__END_DECLS
54 57