diff options
Diffstat (limited to 'charger/charger.c')
-rw-r--r-- | charger/charger.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/charger/charger.c b/charger/charger.c index abf5517..353bdf0 100644 --- a/charger/charger.c +++ b/charger/charger.c @@ -21,25 +21,30 @@ #include <errno.h> #include <fcntl.h> #include <linux/input.h> -#include <linux/netlink.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/poll.h> -#include <sys/socket.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/un.h> #include <time.h> #include <unistd.h> +#include <sys/socket.h> +#include <linux/netlink.h> + #include <cutils/android_reboot.h> #include <cutils/klog.h> #include <cutils/list.h> #include <cutils/misc.h> #include <cutils/uevent.h> +#ifdef CHARGER_ENABLE_SUSPEND +#include <suspend/autosuspend.h> +#endif + #include "minui/minui.h" #ifndef max @@ -351,6 +356,21 @@ static void remove_supply(struct charger *charger, struct power_supply *supply) free(supply); } +#ifdef CHARGER_ENABLE_SUSPEND +static int request_suspend(bool enable) +{ + if (enable) + return autosuspend_enable(); + else + return autosuspend_disable(); +} +#else +static int request_suspend(bool enable) +{ + return 0; +} +#endif + static void parse_uevent(const char *msg, struct uevent *uevent) { uevent->action = ""; @@ -684,6 +704,8 @@ static void update_screen_state(struct charger *charger, int64_t now) charger->next_screen_transition = -1; gr_fb_blank(true); LOGV("[%lld] animation done\n", now); + if (charger->num_supplies_online > 0) + request_suspend(true); return; } @@ -823,8 +845,10 @@ static void process_key(struct charger *charger, int code, int64_t now) } } else { /* if the power key got released, force screen state cycle */ - if (key->pending) + if (key->pending) { + request_suspend(false); kick_animation(charger->batt_anim); + } } } @@ -842,6 +866,7 @@ static void handle_input_state(struct charger *charger, int64_t now) static void handle_power_supply_state(struct charger *charger, int64_t now) { if (charger->num_supplies_online == 0) { + request_suspend(false); if (charger->next_pwr_check == -1) { charger->next_pwr_check = now + UNPLUGGED_SHUTDOWN_TIME; LOGI("[%lld] device unplugged: shutting down in %lld (@ %lld)\n", @@ -974,7 +999,9 @@ int main(int argc, char **argv) ev_sync_key_state(set_key_callback, charger); +#ifndef CHARGER_DISABLE_INIT_BLANK gr_fb_blank(true); +#endif charger->next_screen_transition = now - 1; charger->next_key_check = -1; |