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 aidl::android::hardware::health {
29 class HealthInfo;
30 }  // namespace aidl::android::hardware::health
31 
32 namespace android {
33 namespace hardware {
34 namespace health {
35 namespace V1_0 {
36 struct HealthInfo;
37 }  // namespace V1_0
38 namespace V2_0 {
39 struct HealthInfo;
40 }  // namespace V2_0
41 namespace V2_1 {
42 struct HealthInfo;
43 }  // namespace V2_1
44 }  // namespace health
45 }  // namespace hardware
46 
47 class BatteryMonitor {
48   public:
49 
50     enum PowerSupplyType {
51         ANDROID_POWER_SUPPLY_TYPE_UNKNOWN = 0,
52         ANDROID_POWER_SUPPLY_TYPE_AC,
53         ANDROID_POWER_SUPPLY_TYPE_USB,
54         ANDROID_POWER_SUPPLY_TYPE_WIRELESS,
55         ANDROID_POWER_SUPPLY_TYPE_BATTERY,
56         ANDROID_POWER_SUPPLY_TYPE_DOCK
57     };
58 
59     enum BatteryHealthStatus {
60         BH_UNKNOWN = -1,
61         BH_NOMINAL,
62         BH_MARGINAL,
63         BH_NEEDS_REPLACEMENT,
64         BH_FAILED,
65         BH_NOT_AVAILABLE,
66         BH_INCONSISTENT,
67     };
68 
69     BatteryMonitor();
70     ~BatteryMonitor();
71     void init(struct healthd_config *hc);
72     int getChargeStatus();
73     status_t getProperty(int id, struct BatteryProperty *val);
74     void dumpState(int fd);
75 
76     android::hardware::health::V1_0::HealthInfo getHealthInfo_1_0() const;
77     android::hardware::health::V2_0::HealthInfo getHealthInfo_2_0() const;
78     android::hardware::health::V2_1::HealthInfo getHealthInfo_2_1() const;
79     const aidl::android::hardware::health::HealthInfo& getHealthInfo() const;
80 
81     void updateValues(void);
82     void logValues(void);
83     bool isChargerOnline();
84 
85     int setChargingPolicy(int value);
86     int getChargingPolicy();
87     int getBatteryHealthData(int id);
88 
89     static void logValues(const android::hardware::health::V2_1::HealthInfo& health_info,
90                           const struct healthd_config& healthd_config);
91 
92   private:
93     struct healthd_config *mHealthdConfig;
94     Vector<String8> mChargerNames;
95     bool mBatteryDevicePresent;
96     int mBatteryFixedCapacity;
97     int mBatteryFixedTemperature;
98     int mBatteryHealthStatus;
99     std::unique_ptr<aidl::android::hardware::health::HealthInfo> mHealthInfo;
100 };
101 
102 }; // namespace android
103 
104 #endif // HEALTHD_BATTERY_MONTIOR_H
105