blob: 23a54bf33090f0f5395df6254e580206dc409c01 [file] [log] [blame]
Todd Poynor10b235e2013-08-07 15:25:14 -07001/*
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 Poynor7b27f272013-09-06 15:14:24 -070021#include <utils/Errors.h>
Todd Poynorf5d30122013-08-12 17:03:35 -070022#include <utils/String8.h>
Todd Poynor10b235e2013-08-07 15:25:14 -070023
Todd Poynor9face5c2013-08-08 12:24:53 -070024// periodic_chores_interval_fast, periodic_chores_interval_slow: intervals at
25// which healthd wakes up to poll health state and perform periodic chores,
26// in units of seconds:
27//
28// periodic_chores_interval_fast is used while the device is not in
29// suspend, or in suspend and connected to a charger (to watch for battery
30// overheat due to charging). The default value is 60 (1 minute). Value
31// -1 turns off periodic chores (and wakeups) in these conditions.
32//
33// periodic_chores_interval_slow is used when the device is in suspend and
34// not connected to a charger (to watch for a battery drained to zero
35// remaining capacity). The default value is 600 (10 minutes). Value -1
36// tuns off periodic chores (and wakeups) in these conditions.
Todd Poynorf5d30122013-08-12 17:03:35 -070037//
38// power_supply sysfs attribute file paths. Set these to specific paths
39// to use for the associated battery parameters. healthd will search for
40// appropriate power_supply attribute files to use for any paths left empty:
41//
42// batteryStatusPath: charging status (POWER_SUPPLY_PROP_STATUS)
43// batteryHealthPath: battery health (POWER_SUPPLY_PROP_HEALTH)
44// batteryPresentPath: battery present (POWER_SUPPLY_PROP_PRESENT)
45// batteryCapacityPath: remaining capacity (POWER_SUPPLY_PROP_CAPACITY)
46// batteryVoltagePath: battery voltage (POWER_SUPPLY_PROP_VOLTAGE_NOW)
47// batteryTemperaturePath: battery temperature (POWER_SUPPLY_PROP_TEMP)
48// batteryTechnologyPath: battery technology (POWER_SUPPLY_PROP_TECHNOLOGY)
49// batteryCurrentNowPath: battery current (POWER_SUPPLY_PROP_CURRENT_NOW)
50// batteryChargeCounterPath: battery accumulated charge
51// (POWER_SUPPLY_PROP_CHARGE_COUNTER)
Todd Poynor9face5c2013-08-08 12:24:53 -070052
53struct healthd_config {
54 int periodic_chores_interval_fast;
55 int periodic_chores_interval_slow;
Todd Poynorf5d30122013-08-12 17:03:35 -070056
57 android::String8 batteryStatusPath;
58 android::String8 batteryHealthPath;
59 android::String8 batteryPresentPath;
60 android::String8 batteryCapacityPath;
61 android::String8 batteryVoltagePath;
62 android::String8 batteryTemperaturePath;
63 android::String8 batteryTechnologyPath;
64 android::String8 batteryCurrentNowPath;
Todd Poynorbc102112013-08-27 18:11:49 -070065 android::String8 batteryCurrentAvgPath;
Todd Poynorf5d30122013-08-12 17:03:35 -070066 android::String8 batteryChargeCounterPath;
Todd Poynor9face5c2013-08-08 12:24:53 -070067};
68
Todd Poynor7b27f272013-09-06 15:14:24 -070069// Global helper functions
70
Todd Poynor98c23d82013-09-09 20:02:55 -070071int healthd_register_event(int fd, void (*handler)(uint32_t));
Todd Poynor7b27f272013-09-06 15:14:24 -070072void healthd_battery_update();
73android::status_t healthd_get_property(int id,
74 struct android::BatteryProperty *val);
Todd Poynor020369d2013-09-18 20:09:33 -070075void healthd_dump_battery_state(int fd);
Todd Poynor7b27f272013-09-06 15:14:24 -070076
Todd Poynorc7464c92013-09-10 12:40:00 -070077struct healthd_mode_ops {
78 void (*init)(struct healthd_config *config);
79 int (*preparetowait)(void);
80 void (*heartbeat)(void);
81 void (*battery_update)(struct android::BatteryProperties *props);
82};
83
84extern struct healthd_mode_ops *healthd_mode_ops;
85
Todd Poynorfea5b4d2013-09-09 12:09:08 -070086// Charger mode
87
88void healthd_mode_charger_init(struct healthd_config *config);
89int healthd_mode_charger_preparetowait(void);
90void healthd_mode_charger_heartbeat(void);
91void healthd_mode_charger_battery_update(
92 struct android::BatteryProperties *props);
93
Todd Poynor10b235e2013-08-07 15:25:14 -070094// The following are implemented in libhealthd_board to handle board-specific
95// behavior.
96//
Todd Poynorf5d30122013-08-12 17:03:35 -070097// healthd_board_init() is called at startup time to modify healthd's
98// configuration according to board-specific requirements. config
99// points to the healthd configuration values described above. To use default
100// values, this function can simply return without modifying the fields of the
101// config parameter.
Todd Poynor10b235e2013-08-07 15:25:14 -0700102
Todd Poynor9face5c2013-08-08 12:24:53 -0700103void healthd_board_init(struct healthd_config *config);
Todd Poynor10b235e2013-08-07 15:25:14 -0700104
105// Process updated battery property values. This function is called when
106// the kernel sends updated battery status via a uevent from the power_supply
107// subsystem, or when updated values are polled by healthd, as for periodic
108// poll of battery state.
109//
110// props are the battery properties read from the kernel. These values may
111// be modified in this call, prior to sending the modified values to the
112// Android runtime.
113//
114// Return 0 to indicate the usual kernel log battery status heartbeat message
115// is to be logged, or non-zero to prevent logging this information.
116
117int healthd_board_battery_update(struct android::BatteryProperties *props);
118
119#endif /* _HEALTHD_H_ */