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 private: 70 struct healthd_config *mHealthdConfig; 71 Vector<String8> mChargerNames; 72 bool mBatteryDevicePresent; 73 int mBatteryFixedCapacity; 74 int mBatteryFixedTemperature; 75 std::unique_ptr<android::hardware::health::V2_1::HealthInfo> mHealthInfo; 76 77 int readFromFile(const String8& path, std::string* buf); 78 PowerSupplyType readPowerSupplyType(const String8& path); 79 bool getBooleanField(const String8& path); 80 int getIntField(const String8& path); 81 bool isScopedPowerSupply(const char* name); 82 }; 83 84 }; // namespace android 85 86 #endif // HEALTHD_BATTERY_MONTIOR_H 87