• 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 <memory>
21 
22 #include <batteryservice/BatteryService.h>
23 #include <utils/String8.h>
24 #include <utils/Vector.h>
25 
26 #include <healthd/healthd.h>
27 
28 namespace android {
29 namespace hardware {
30 namespace health {
31 namespace V1_0 {
32 struct HealthInfo;
33 }  // namespace V1_0
34 namespace V2_0 {
35 struct HealthInfo;
36 }  // namespace V2_0
37 namespace V2_1 {
38 struct HealthInfo;
39 }  // namespace V2_1
40 }  // namespace health
41 }  // namespace hardware
42 
43 class BatteryMonitor {
44   public:
45 
46     enum PowerSupplyType {
47         ANDROID_POWER_SUPPLY_TYPE_UNKNOWN = 0,
48         ANDROID_POWER_SUPPLY_TYPE_AC,
49         ANDROID_POWER_SUPPLY_TYPE_USB,
50         ANDROID_POWER_SUPPLY_TYPE_WIRELESS,
51         ANDROID_POWER_SUPPLY_TYPE_BATTERY
52     };
53 
54     BatteryMonitor();
55     ~BatteryMonitor();
56     void init(struct healthd_config *hc);
57     int getChargeStatus();
58     status_t getProperty(int id, struct BatteryProperty *val);
59     void dumpState(int fd);
60 
61     const android::hardware::health::V1_0::HealthInfo& getHealthInfo_1_0() const;
62     const android::hardware::health::V2_0::HealthInfo& getHealthInfo_2_0() const;
63     const android::hardware::health::V2_1::HealthInfo& getHealthInfo_2_1() const;
64 
65     void updateValues(void);
66     void logValues(void);
67     bool isChargerOnline();
68 
69     static void logValues(const android::hardware::health::V2_1::HealthInfo& health_info,
70                           const struct healthd_config& healthd_config);
71 
72   private:
73     struct healthd_config *mHealthdConfig;
74     Vector<String8> mChargerNames;
75     bool mBatteryDevicePresent;
76     int mBatteryFixedCapacity;
77     int mBatteryFixedTemperature;
78     std::unique_ptr<android::hardware::health::V2_1::HealthInfo> mHealthInfo;
79 
80     int readFromFile(const String8& path, std::string* buf);
81     PowerSupplyType readPowerSupplyType(const String8& path);
82     bool getBooleanField(const String8& path);
83     int getIntField(const String8& path);
84     bool isScopedPowerSupply(const char* name);
85 };
86 
87 }; // namespace android
88 
89 #endif // HEALTHD_BATTERY_MONTIOR_H
90