diff --git a/libsuspend/autosuspend.c b/libsuspend/autosuspend.c index 1d6c4349e..09fc0617e 100644 --- a/libsuspend/autosuspend.c +++ b/libsuspend/autosuspend.c @@ -28,8 +28,7 @@ static struct autosuspend_ops *autosuspend_ops; static bool autosuspend_enabled; static bool autosuspend_inited; -static int autosuspend_init(void) -{ +static int autosuspend_init(void) { if (autosuspend_inited) { return 0; } @@ -51,8 +50,7 @@ out: return 0; } -int autosuspend_enable(void) -{ +int autosuspend_enable(void) { int ret; ret = autosuspend_init(); @@ -75,8 +73,7 @@ int autosuspend_enable(void) return 0; } -int autosuspend_disable(void) -{ +int autosuspend_disable(void) { int ret; ret = autosuspend_init(); @@ -98,3 +95,16 @@ int autosuspend_disable(void) autosuspend_enabled = false; return 0; } + +void autosuspend_set_wakeup_callback(void (*func)(bool success)) { + int ret; + + ret = autosuspend_init(); + if (ret) { + return; + } + + ALOGV("set_wakeup_callback"); + + autosuspend_ops->set_wakeup_callback(func); +} diff --git a/libsuspend/autosuspend_ops.h b/libsuspend/autosuspend_ops.h index 698e25be8..2f435d97f 100644 --- a/libsuspend/autosuspend_ops.h +++ b/libsuspend/autosuspend_ops.h @@ -20,10 +20,9 @@ struct autosuspend_ops { int (*enable)(void); int (*disable)(void); + void (*set_wakeup_callback)(void (*func)(bool success)); }; -struct autosuspend_ops *autosuspend_autosleep_init(void); -struct autosuspend_ops *autosuspend_earlysuspend_init(void); struct autosuspend_ops *autosuspend_wakeup_count_init(void); #endif diff --git a/libsuspend/autosuspend_wakeup_count.c b/libsuspend/autosuspend_wakeup_count.c index 0a172be79..81cb44cd9 100644 --- a/libsuspend/autosuspend_wakeup_count.c +++ b/libsuspend/autosuspend_wakeup_count.c @@ -42,7 +42,7 @@ static int state_fd; static int wakeup_count_fd; static pthread_t suspend_thread; static sem_t suspend_lockout; -static const char *sleep_state = "mem"; +static const char* sleep_state = "mem"; static void (*wakeup_func)(bool success) = NULL; static int sleep_time = BASE_SLEEP_TIME; @@ -55,8 +55,7 @@ static void update_sleep_time(bool success) { sleep_time = MIN(sleep_time * 2, 60000000); } -static void *suspend_thread_func(void *arg __attribute__((unused))) -{ +static void* suspend_thread_func(void* arg __attribute__((unused))) { char buf[80]; char wakeup_count[20]; int wakeup_count_len; @@ -117,8 +116,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused))) return NULL; } -static int autosuspend_wakeup_count_enable(void) -{ +static int autosuspend_wakeup_count_enable(void) { char buf[80]; int ret; @@ -136,8 +134,7 @@ static int autosuspend_wakeup_count_enable(void) return ret; } -static int autosuspend_wakeup_count_disable(void) -{ +static int autosuspend_wakeup_count_disable(void) { char buf[80]; int ret; @@ -155,8 +152,7 @@ static int autosuspend_wakeup_count_disable(void) return ret; } -void set_wakeup_callback(void (*func)(bool success)) -{ +static void autosuspend_set_wakeup_callback(void (*func)(bool success)) { if (wakeup_func != NULL) { ALOGE("Duplicate wakeup callback applied, keeping original"); return; @@ -165,12 +161,12 @@ void set_wakeup_callback(void (*func)(bool success)) } struct autosuspend_ops autosuspend_wakeup_count_ops = { - .enable = autosuspend_wakeup_count_enable, - .disable = autosuspend_wakeup_count_disable, + .enable = autosuspend_wakeup_count_enable, + .disable = autosuspend_wakeup_count_disable, + .set_wakeup_callback = autosuspend_set_wakeup_callback, }; -struct autosuspend_ops *autosuspend_wakeup_count_init(void) -{ +struct autosuspend_ops* autosuspend_wakeup_count_init(void) { int ret; char buf[80]; diff --git a/libsuspend/include/suspend/autosuspend.h b/libsuspend/include/suspend/autosuspend.h index 59188a804..e130ca3df 100644 --- a/libsuspend/include/suspend/autosuspend.h +++ b/libsuspend/include/suspend/autosuspend.h @@ -51,7 +51,7 @@ int autosuspend_disable(void); * success is true if the suspend was sucessful and false if the suspend * aborted due to some reason. */ -void set_wakeup_callback(void (*func)(bool success)); +void autosuspend_set_wakeup_callback(void (*func)(bool success)); __END_DECLS