Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _HEALTHD_H_ |
| 18 | #define _HEALTHD_H_ |
| 19 | |
| 20 | #include <batteryservice/BatteryService.h> |
Todd Poynor | e14b37e | 2014-05-20 13:54:40 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
Todd Poynor | 7b27f27 | 2013-09-06 15:14:24 -0700 | [diff] [blame] | 22 | #include <utils/Errors.h> |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 23 | #include <utils/String8.h> |
Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 24 | |
Todd Poynor | 9face5c | 2013-08-08 12:24:53 -0700 | [diff] [blame] | 25 | // periodic_chores_interval_fast, periodic_chores_interval_slow: intervals at |
| 26 | // which healthd wakes up to poll health state and perform periodic chores, |
| 27 | // in units of seconds: |
| 28 | // |
| 29 | // periodic_chores_interval_fast is used while the device is not in |
| 30 | // suspend, or in suspend and connected to a charger (to watch for battery |
| 31 | // overheat due to charging). The default value is 60 (1 minute). Value |
| 32 | // -1 turns off periodic chores (and wakeups) in these conditions. |
| 33 | // |
| 34 | // periodic_chores_interval_slow is used when the device is in suspend and |
| 35 | // not connected to a charger (to watch for a battery drained to zero |
| 36 | // remaining capacity). The default value is 600 (10 minutes). Value -1 |
| 37 | // tuns off periodic chores (and wakeups) in these conditions. |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 38 | // |
| 39 | // power_supply sysfs attribute file paths. Set these to specific paths |
| 40 | // to use for the associated battery parameters. healthd will search for |
| 41 | // appropriate power_supply attribute files to use for any paths left empty: |
| 42 | // |
| 43 | // batteryStatusPath: charging status (POWER_SUPPLY_PROP_STATUS) |
| 44 | // batteryHealthPath: battery health (POWER_SUPPLY_PROP_HEALTH) |
| 45 | // batteryPresentPath: battery present (POWER_SUPPLY_PROP_PRESENT) |
| 46 | // batteryCapacityPath: remaining capacity (POWER_SUPPLY_PROP_CAPACITY) |
| 47 | // batteryVoltagePath: battery voltage (POWER_SUPPLY_PROP_VOLTAGE_NOW) |
| 48 | // batteryTemperaturePath: battery temperature (POWER_SUPPLY_PROP_TEMP) |
| 49 | // batteryTechnologyPath: battery technology (POWER_SUPPLY_PROP_TECHNOLOGY) |
| 50 | // batteryCurrentNowPath: battery current (POWER_SUPPLY_PROP_CURRENT_NOW) |
| 51 | // batteryChargeCounterPath: battery accumulated charge |
| 52 | // (POWER_SUPPLY_PROP_CHARGE_COUNTER) |
Todd Poynor | 9face5c | 2013-08-08 12:24:53 -0700 | [diff] [blame] | 53 | |
| 54 | struct healthd_config { |
| 55 | int periodic_chores_interval_fast; |
| 56 | int periodic_chores_interval_slow; |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 57 | |
| 58 | android::String8 batteryStatusPath; |
| 59 | android::String8 batteryHealthPath; |
| 60 | android::String8 batteryPresentPath; |
| 61 | android::String8 batteryCapacityPath; |
| 62 | android::String8 batteryVoltagePath; |
| 63 | android::String8 batteryTemperaturePath; |
| 64 | android::String8 batteryTechnologyPath; |
| 65 | android::String8 batteryCurrentNowPath; |
Todd Poynor | bc10211 | 2013-08-27 18:11:49 -0700 | [diff] [blame] | 66 | android::String8 batteryCurrentAvgPath; |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 67 | android::String8 batteryChargeCounterPath; |
Todd Poynor | e14b37e | 2014-05-20 13:54:40 -0700 | [diff] [blame] | 68 | |
| 69 | int (*energyCounter)(int64_t *); |
Ruchi Kandoi | a84b1f6 | 2014-10-21 18:24:11 -0700 | [diff] [blame] | 70 | int boot_min_cap; |
Ruchi Kandoi | bdf11c7 | 2014-09-25 19:44:42 -0700 | [diff] [blame] | 71 | bool (*screen_on)(android::BatteryProperties *props); |
Todd Poynor | 9face5c | 2013-08-08 12:24:53 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Todd Poynor | 7b27f27 | 2013-09-06 15:14:24 -0700 | [diff] [blame] | 74 | // Global helper functions |
| 75 | |
Todd Poynor | 98c23d8 | 2013-09-09 20:02:55 -0700 | [diff] [blame] | 76 | int healthd_register_event(int fd, void (*handler)(uint32_t)); |
Todd Poynor | 7b27f27 | 2013-09-06 15:14:24 -0700 | [diff] [blame] | 77 | void healthd_battery_update(); |
| 78 | android::status_t healthd_get_property(int id, |
| 79 | struct android::BatteryProperty *val); |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 80 | void healthd_dump_battery_state(int fd); |
Todd Poynor | 7b27f27 | 2013-09-06 15:14:24 -0700 | [diff] [blame] | 81 | |
Todd Poynor | c7464c9 | 2013-09-10 12:40:00 -0700 | [diff] [blame] | 82 | struct healthd_mode_ops { |
| 83 | void (*init)(struct healthd_config *config); |
| 84 | int (*preparetowait)(void); |
| 85 | void (*heartbeat)(void); |
| 86 | void (*battery_update)(struct android::BatteryProperties *props); |
| 87 | }; |
| 88 | |
| 89 | extern struct healthd_mode_ops *healthd_mode_ops; |
| 90 | |
Todd Poynor | fea5b4d | 2013-09-09 12:09:08 -0700 | [diff] [blame] | 91 | // Charger mode |
| 92 | |
| 93 | void healthd_mode_charger_init(struct healthd_config *config); |
| 94 | int healthd_mode_charger_preparetowait(void); |
| 95 | void healthd_mode_charger_heartbeat(void); |
| 96 | void healthd_mode_charger_battery_update( |
| 97 | struct android::BatteryProperties *props); |
| 98 | |
Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 99 | // The following are implemented in libhealthd_board to handle board-specific |
| 100 | // behavior. |
| 101 | // |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 102 | // healthd_board_init() is called at startup time to modify healthd's |
| 103 | // configuration according to board-specific requirements. config |
| 104 | // points to the healthd configuration values described above. To use default |
| 105 | // values, this function can simply return without modifying the fields of the |
| 106 | // config parameter. |
Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 107 | |
Todd Poynor | 9face5c | 2013-08-08 12:24:53 -0700 | [diff] [blame] | 108 | void healthd_board_init(struct healthd_config *config); |
Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 109 | |
| 110 | // Process updated battery property values. This function is called when |
| 111 | // the kernel sends updated battery status via a uevent from the power_supply |
| 112 | // subsystem, or when updated values are polled by healthd, as for periodic |
| 113 | // poll of battery state. |
| 114 | // |
| 115 | // props are the battery properties read from the kernel. These values may |
| 116 | // be modified in this call, prior to sending the modified values to the |
| 117 | // Android runtime. |
| 118 | // |
| 119 | // Return 0 to indicate the usual kernel log battery status heartbeat message |
| 120 | // is to be logged, or non-zero to prevent logging this information. |
| 121 | |
| 122 | int healthd_board_battery_update(struct android::BatteryProperties *props); |
| 123 | |
| 124 | #endif /* _HEALTHD_H_ */ |