Merge "Adds a parameter to the wakeup_callback to report sucessful wakeup or suspend aborts." into mnc-dev

This commit is contained in:
Adam Lesinski 2015-06-27 00:40:22 +00:00 committed by Android (Google) Code Review
commit 1eb38187af
2 changed files with 15 additions and 11 deletions

View File

@ -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");

View File

@ -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