summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYabin Cui2016-02-17 14:21:34 -0600
committerYabin Cui2016-02-23 12:52:43 -0600
commitf6dbc6d4b830c57c0155a607d0d8a2cb6b1e0040 (patch)
tree87b05d21591a3d412a9ac5c64c384ae316ce90dd /healthd/include
parentac3387b71baf99b2680af038c5997eb52218f661 (diff)
downloadplatform-system-core-f6dbc6d4b830c57c0155a607d0d8a2cb6b1e0040.tar.gz
platform-system-core-f6dbc6d4b830c57c0155a607d0d8a2cb6b1e0040.tar.xz
platform-system-core-f6dbc6d4b830c57c0155a607d0d8a2cb6b1e0040.zip
healthd: separate libbatterymonitor for use in recovery.
Bug: 26879394 Change-Id: I97b5b4994c42988ce43f5085b8b4b25e9e80c9fa (cherry picked from commit e98e177a34eb3200b9f95be8379223271933b885)
Diffstat (limited to 'healthd/include')
-rw-r--r--healthd/include/healthd/BatteryMonitor.h65
-rw-r--r--healthd/include/healthd/healthd.h126
2 files changed, 191 insertions, 0 deletions
diff --git a/healthd/include/healthd/BatteryMonitor.h b/healthd/include/healthd/BatteryMonitor.h
new file mode 100644
index 000000000..31c4e0920
--- /dev/null
+++ b/healthd/include/healthd/BatteryMonitor.h
@@ -0,0 +1,65 @@
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_BATTERYMONITOR_H
18#define HEALTHD_BATTERYMONITOR_H
19
20#include <batteryservice/BatteryService.h>
21#include <binder/IInterface.h>
22#include <utils/String8.h>
23#include <utils/Vector.h>
24
25#include <healthd/healthd.h>
26
27namespace android {
28
29class BatteryMonitor {
30 public:
31
32 enum PowerSupplyType {
33 ANDROID_POWER_SUPPLY_TYPE_UNKNOWN = 0,
34 ANDROID_POWER_SUPPLY_TYPE_AC,
35 ANDROID_POWER_SUPPLY_TYPE_USB,
36 ANDROID_POWER_SUPPLY_TYPE_WIRELESS,
37 ANDROID_POWER_SUPPLY_TYPE_BATTERY
38 };
39
40 BatteryMonitor();
41 void init(struct healthd_config *hc);
42 bool update(void);
43 status_t getProperty(int id, struct BatteryProperty *val);
44 void dumpState(int fd);
45
46 private:
47 struct healthd_config *mHealthdConfig;
48 Vector<String8> mChargerNames;
49 bool mBatteryDevicePresent;
50 bool mAlwaysPluggedDevice;
51 int mBatteryFixedCapacity;
52 int mBatteryFixedTemperature;
53 struct BatteryProperties props;
54
55 int getBatteryStatus(const char* status);
56 int getBatteryHealth(const char* status);
57 int readFromFile(const String8& path, char* buf, size_t size);
58 PowerSupplyType readPowerSupplyType(const String8& path);
59 bool getBooleanField(const String8& path);
60 int getIntField(const String8& path);
61};
62
63}; // namespace android
64
65#endif // HEALTHD_BATTERY_MONTIOR_H
diff --git a/healthd/include/healthd/healthd.h b/healthd/include/healthd/healthd.h
new file mode 100644
index 000000000..34ea55f66
--- /dev/null
+++ b/healthd/include/healthd/healthd.h
@@ -0,0 +1,126 @@
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>
21#include <sys/types.h>
22#include <utils/Errors.h>
23#include <utils/String8.h>
24
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.
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)
53
54struct healthd_config {
55 int periodic_chores_interval_fast;
56 int periodic_chores_interval_slow;
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;
66 android::String8 batteryCurrentAvgPath;
67 android::String8 batteryChargeCounterPath;
68 android::String8 batteryFullChargePath;
69 android::String8 batteryCycleCountPath;
70
71 int (*energyCounter)(int64_t *);
72 int boot_min_cap;
73 bool (*screen_on)(android::BatteryProperties *props);
74};
75
76// Global helper functions
77
78int healthd_register_event(int fd, void (*handler)(uint32_t));
79void healthd_battery_update();
80android::status_t healthd_get_property(int id,
81 struct android::BatteryProperty *val);
82void healthd_dump_battery_state(int fd);
83
84struct healthd_mode_ops {
85 void (*init)(struct healthd_config *config);
86 int (*preparetowait)(void);
87 void (*heartbeat)(void);
88 void (*battery_update)(struct android::BatteryProperties *props);
89};
90
91extern struct healthd_mode_ops *healthd_mode_ops;
92
93// Charger mode
94
95void healthd_mode_charger_init(struct healthd_config *config);
96int healthd_mode_charger_preparetowait(void);
97void healthd_mode_charger_heartbeat(void);
98void healthd_mode_charger_battery_update(
99 struct android::BatteryProperties *props);
100
101// The following are implemented in libhealthd_board to handle board-specific
102// behavior.
103//
104// healthd_board_init() is called at startup time to modify healthd's
105// configuration according to board-specific requirements. config
106// points to the healthd configuration values described above. To use default
107// values, this function can simply return without modifying the fields of the
108// config parameter.
109
110void healthd_board_init(struct healthd_config *config);
111
112// Process updated battery property values. This function is called when
113// the kernel sends updated battery status via a uevent from the power_supply
114// subsystem, or when updated values are polled by healthd, as for periodic
115// poll of battery state.
116//
117// props are the battery properties read from the kernel. These values may
118// be modified in this call, prior to sending the modified values to the
119// Android runtime.
120//
121// Return 0 to indicate the usual kernel log battery status heartbeat message
122// is to be logged, or non-zero to prevent logging this information.
123
124int healthd_board_battery_update(struct android::BatteryProperties *props);
125
126#endif /* _HEALTHD_H_ */