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