diff options
-rw-r--r-- | healthd/healthd.cpp | 24 | ||||
-rw-r--r-- | healthd/healthd.h | 32 | ||||
-rw-r--r-- | healthd/healthd_board_default.cpp | 2 |
3 files changed, 33 insertions, 25 deletions
diff --git a/healthd/healthd.cpp b/healthd/healthd.cpp index 89178fa..158274c 100644 --- a/healthd/healthd.cpp +++ b/healthd/healthd.cpp @@ -37,10 +37,11 @@ using namespace android; // Periodic chores intervals in seconds #define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 1) #define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (60 * 10) -static int periodic_chores_interval_fast = - DEFAULT_PERIODIC_CHORES_INTERVAL_FAST; -static int periodic_chores_interval_slow = - DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW; + +static struct healthd_config healthd_config = { + .periodic_chores_interval_fast = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST, + .periodic_chores_interval_slow = DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW, +}; #define POWER_SUPPLY_SUBSYSTEM "power_supply" @@ -84,7 +85,8 @@ static void battery_update(void) { // slow wake interval when on battery (watch for drained battery). int new_wake_interval = gBatteryMonitor->update() ? - periodic_chores_interval_fast : periodic_chores_interval_slow; + healthd_config.periodic_chores_interval_fast : + healthd_config.periodic_chores_interval_slow; if (new_wake_interval != wakealarm_wake_interval) wakealarm_set_interval(new_wake_interval); @@ -94,12 +96,12 @@ static void battery_update(void) { // poll at fast rate while awake and let alarm wake up at slow rate when // asleep. - if (periodic_chores_interval_fast == -1) + if (healthd_config.periodic_chores_interval_fast == -1) awake_poll_interval = -1; else awake_poll_interval = - new_wake_interval == periodic_chores_interval_fast ? - -1 : periodic_chores_interval_fast * 1000; + new_wake_interval == healthd_config.periodic_chores_interval_fast ? + -1 : healthd_config.periodic_chores_interval_fast * 1000; } static void periodic_chores() { @@ -150,10 +152,7 @@ static void wakealarm_init(void) { return; } - healthd_board_poll_intervals(&periodic_chores_interval_fast, - &periodic_chores_interval_slow); - - wakealarm_set_interval(periodic_chores_interval_fast); + wakealarm_set_interval(healthd_config.periodic_chores_interval_fast); } static void wakealarm_event(void) { @@ -262,6 +261,7 @@ int main(int argc, char **argv) { } } + healthd_board_init(&healthd_config); wakealarm_init(); uevent_init(); binder_init(); diff --git a/healthd/healthd.h b/healthd/healthd.h index 18ad03a..895be40 100644 --- a/healthd/healthd.h +++ b/healthd/healthd.h @@ -19,25 +19,33 @@ #include <batteryservice/BatteryService.h> -// The following are implemented in libhealthd_board to handle board-specific -// behavior. +// periodic_chores_interval_fast, periodic_chores_interval_slow: intervals at +// which healthd wakes up to poll health state and perform periodic chores, +// in units of seconds: // -// Set periodic poll intervals in seconds. +// periodic_chores_interval_fast is used while the device is not in +// suspend, or in suspend and connected to a charger (to watch for battery +// overheat due to charging). The default value is 60 (1 minute). Value +// -1 turns off periodic chores (and wakeups) in these conditions. // -// fast_interval is used while the device is not in suspend, or in suspend and -// connected to a charger (to watch for battery overheat due to charging). -// The default value is 60 (1 minute). Value -1 turns off fast_interval -// polling. +// periodic_chores_interval_slow is used when the device is in suspend and +// not connected to a charger (to watch for a battery drained to zero +// remaining capacity). The default value is 600 (10 minutes). Value -1 +// tuns off periodic chores (and wakeups) in these conditions. + +struct healthd_config { + int periodic_chores_interval_fast; + int periodic_chores_interval_slow; +}; + +// The following are implemented in libhealthd_board to handle board-specific +// behavior. // -// slow_interval is used when the device is in suspend and not connected to a -// charger (to watch for a battery drained to zero remaining capacity). The -// default value is 600 (10 minutes). Value -1 tuns off slow interval -// polling. // // To use the default values, this function can simply return without // modifying the parameters. -void healthd_board_poll_intervals(int *fast_interval, int *slow_interval); +void healthd_board_init(struct healthd_config *config); // Process updated battery property values. This function is called when // the kernel sends updated battery status via a uevent from the power_supply diff --git a/healthd/healthd_board_default.cpp b/healthd/healthd_board_default.cpp index 82f37fe..b2bb516 100644 --- a/healthd/healthd_board_default.cpp +++ b/healthd/healthd_board_default.cpp @@ -16,7 +16,7 @@ #include <healthd.h> -void healthd_board_poll_intervals(int *fast_interval, int *slow_interval) +void healthd_board_init(struct healthd_config *config) { // use defaults } |