• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
27 namespace android {
28 
29 class 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     int getChargeStatus();
44     status_t getProperty(int id, struct BatteryProperty *val);
45     void dumpState(int fd);
46 
47   private:
48     struct healthd_config *mHealthdConfig;
49     Vector<String8> mChargerNames;
50     bool mBatteryDevicePresent;
51     bool mAlwaysPluggedDevice;
52     int mBatteryFixedCapacity;
53     int mBatteryFixedTemperature;
54     struct BatteryProperties props;
55 
56     int getBatteryStatus(const char* status);
57     int getBatteryHealth(const char* status);
58     int readFromFile(const String8& path, char* buf, size_t size);
59     PowerSupplyType readPowerSupplyType(const String8& path);
60     bool getBooleanField(const String8& path);
61     int getIntField(const String8& path);
62 };
63 
64 }; // namespace android
65 
66 #endif // HEALTHD_BATTERY_MONTIOR_H
67