xref: /aosp_15_r20/system/core/healthd/include/healthd/BatteryMonitor_v1.h (revision 00c7fec1bb09f3284aad6a6f96d2f63dfc3650ad)
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_V1_H
18 #define HEALTHD_BATTERYMONITOR_V1_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     BatteryMonitor();
60     ~BatteryMonitor();
61     void init(struct healthd_config *hc);
62     int getChargeStatus();
63     status_t getProperty(int id, struct BatteryProperty *val);
64     void dumpState(int fd);
65 
66     android::hardware::health::V1_0::HealthInfo getHealthInfo_1_0() const;
67     android::hardware::health::V2_0::HealthInfo getHealthInfo_2_0() const;
68     android::hardware::health::V2_1::HealthInfo getHealthInfo_2_1() const;
69     const aidl::android::hardware::health::HealthInfo& getHealthInfo() const;
70 
71     void updateValues(void);
72     void logValues(void);
73     bool isChargerOnline();
74 
75     static void logValues(const android::hardware::health::V2_1::HealthInfo& health_info,
76                           const struct healthd_config& healthd_config);
77 
78   private:
79     struct healthd_config *mHealthdConfig;
80     Vector<String8> mChargerNames;
81     bool mBatteryDevicePresent;
82     int mBatteryFixedCapacity;
83     int mBatteryFixedTemperature;
84     std::unique_ptr<aidl::android::hardware::health::HealthInfo> mHealthInfo;
85 };
86 
87 }; // namespace android
88 
89 #endif // HEALTHD_BATTERYMONITOR_V1_H
90