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 @@ #include #include #include +#include #include #include #include @@ -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 10e3d27d2..59188a804 100644 --- a/libsuspend/include/suspend/autosuspend.h +++ b/libsuspend/include/suspend/autosuspend.h @@ -18,6 +18,7 @@ #define _LIBSUSPEND_AUTOSUSPEND_H_ #include +#include __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