Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 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 | #define LOG_TAG "healthd" |
| 18 | |
Yabin Cui | e98e177 | 2016-02-17 12:21:34 -0800 | [diff] [blame] | 19 | #include <healthd/healthd.h> |
| 20 | #include <healthd/BatteryMonitor.h> |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 21 | |
| 22 | #include <dirent.h> |
| 23 | #include <errno.h> |
| 24 | #include <fcntl.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
Mark Salyzyn | acb1ddf | 2015-07-23 09:22:50 -0700 | [diff] [blame] | 27 | #include <sys/types.h> |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 28 | #include <unistd.h> |
Thierry Strudel | f73de6f | 2019-01-11 17:09:20 -0800 | [diff] [blame] | 29 | |
| 30 | #include <algorithm> |
James Hawkins | 588a2ca | 2016-02-18 14:52:46 -0800 | [diff] [blame] | 31 | #include <memory> |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 32 | #include <optional> |
Mark Salyzyn | acb1ddf | 2015-07-23 09:22:50 -0700 | [diff] [blame] | 33 | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 34 | #include <aidl/android/hardware/health/HealthInfo.h> |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 35 | #include <android-base/file.h> |
Elliott Hughes | da46b39 | 2016-10-11 17:09:00 -0700 | [diff] [blame] | 36 | #include <android-base/parseint.h> |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 37 | #include <android-base/strings.h> |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 38 | #include <android/hardware/health/2.1/types.h> |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 39 | #include <android/hardware/health/translate-ndk.h> |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 40 | #include <batteryservice/BatteryService.h> |
| 41 | #include <cutils/klog.h> |
Todd Poynor | 3db03a5 | 2014-05-21 16:28:13 -0700 | [diff] [blame] | 42 | #include <cutils/properties.h> |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 43 | #include <utils/Errors.h> |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 44 | #include <utils/String8.h> |
| 45 | #include <utils/Vector.h> |
| 46 | |
| 47 | #define POWER_SUPPLY_SUBSYSTEM "power_supply" |
| 48 | #define POWER_SUPPLY_SYSFS_PATH "/sys/class/" POWER_SUPPLY_SUBSYSTEM |
Ruchi Kandoi | a78fc23 | 2014-07-10 15:06:21 -0700 | [diff] [blame] | 49 | #define FAKE_BATTERY_CAPACITY 42 |
| 50 | #define FAKE_BATTERY_TEMPERATURE 424 |
Ruchi Kandoi | 5c09ec1 | 2016-02-25 16:19:30 -0800 | [diff] [blame] | 51 | #define MILLION 1.0e6 |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 52 | #define DEFAULT_VBUS_VOLTAGE 5000000 |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 53 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 54 | using HealthInfo_1_0 = android::hardware::health::V1_0::HealthInfo; |
| 55 | using HealthInfo_2_0 = android::hardware::health::V2_0::HealthInfo; |
| 56 | using HealthInfo_2_1 = android::hardware::health::V2_1::HealthInfo; |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 57 | using aidl::android::hardware::health::BatteryCapacityLevel; |
| 58 | using aidl::android::hardware::health::BatteryHealth; |
| 59 | using aidl::android::hardware::health::BatteryStatus; |
| 60 | using aidl::android::hardware::health::HealthInfo; |
| 61 | |
| 62 | namespace { |
| 63 | |
| 64 | // Translate from AIDL back to HIDL definition for getHealthInfo_*_* calls. |
| 65 | // Skips storageInfo and diskStats. |
| 66 | void translateToHidl(const ::aidl::android::hardware::health::HealthInfo& in, |
| 67 | ::android::hardware::health::V1_0::HealthInfo* out) { |
| 68 | out->chargerAcOnline = in.chargerAcOnline; |
| 69 | out->chargerUsbOnline = in.chargerUsbOnline; |
| 70 | out->chargerWirelessOnline = in.chargerWirelessOnline; |
| 71 | out->maxChargingCurrent = in.maxChargingCurrentMicroamps; |
| 72 | out->maxChargingVoltage = in.maxChargingVoltageMicrovolts; |
| 73 | out->batteryStatus = |
| 74 | static_cast<::android::hardware::health::V1_0::BatteryStatus>(in.batteryStatus); |
| 75 | out->batteryHealth = |
| 76 | static_cast<::android::hardware::health::V1_0::BatteryHealth>(in.batteryHealth); |
| 77 | out->batteryPresent = in.batteryPresent; |
| 78 | out->batteryLevel = in.batteryLevel; |
| 79 | out->batteryVoltage = in.batteryVoltageMillivolts; |
| 80 | out->batteryTemperature = in.batteryTemperatureTenthsCelsius; |
| 81 | out->batteryCurrent = in.batteryCurrentMicroamps; |
| 82 | out->batteryCycleCount = in.batteryCycleCount; |
| 83 | out->batteryFullCharge = in.batteryFullChargeUah; |
| 84 | out->batteryChargeCounter = in.batteryChargeCounterUah; |
| 85 | out->batteryTechnology = in.batteryTechnology; |
| 86 | } |
| 87 | |
| 88 | void translateToHidl(const ::aidl::android::hardware::health::HealthInfo& in, |
| 89 | ::android::hardware::health::V2_0::HealthInfo* out) { |
| 90 | translateToHidl(in, &out->legacy); |
| 91 | out->batteryCurrentAverage = in.batteryCurrentAverageMicroamps; |
| 92 | // Skip storageInfo and diskStats |
| 93 | } |
| 94 | |
| 95 | void translateToHidl(const ::aidl::android::hardware::health::HealthInfo& in, |
| 96 | ::android::hardware::health::V2_1::HealthInfo* out) { |
| 97 | translateToHidl(in, &out->legacy); |
| 98 | out->batteryCapacityLevel = static_cast<android::hardware::health::V2_1::BatteryCapacityLevel>( |
| 99 | in.batteryCapacityLevel); |
| 100 | out->batteryChargeTimeToFullNowSeconds = in.batteryChargeTimeToFullNowSeconds; |
| 101 | out->batteryFullChargeDesignCapacityUah = in.batteryFullChargeDesignCapacityUah; |
| 102 | } |
| 103 | |
| 104 | } // namespace |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 105 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 106 | namespace android { |
| 107 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 108 | template <typename T> |
| 109 | struct SysfsStringEnumMap { |
Mark Salyzyn | 6f5b47f | 2014-05-15 15:00:59 -0700 | [diff] [blame] | 110 | const char* s; |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 111 | T val; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 114 | template <typename T> |
| 115 | static std::optional<T> mapSysfsString(const char* str, SysfsStringEnumMap<T> map[]) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 116 | for (int i = 0; map[i].s; i++) |
| 117 | if (!strcmp(str, map[i].s)) |
| 118 | return map[i].val; |
| 119 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 120 | return std::nullopt; |
Yabin Cui | db04a49 | 2016-02-16 17:19:23 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 123 | static void initHealthInfo(HealthInfo* health_info) { |
| 124 | *health_info = HealthInfo{}; |
Yifan Hong | 6cabe9b | 2019-11-05 17:04:50 -0800 | [diff] [blame] | 125 | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 126 | // Enum values may be zero initialized, so they need to be initialized properly. |
| 127 | health_info->batteryCapacityLevel = BatteryCapacityLevel::UNSUPPORTED; |
| 128 | health_info->batteryChargeTimeToFullNowSeconds = |
| 129 | (int64_t)HealthInfo::BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED; |
| 130 | health_info->batteryStatus = BatteryStatus::UNKNOWN; |
| 131 | health_info->batteryHealth = BatteryHealth::UNKNOWN; |
Yifan Hong | 6cabe9b | 2019-11-05 17:04:50 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Todd Poynor | e030a10 | 2018-01-19 14:03:59 -0800 | [diff] [blame] | 134 | BatteryMonitor::BatteryMonitor() |
| 135 | : mHealthdConfig(nullptr), |
| 136 | mBatteryDevicePresent(false), |
| 137 | mBatteryFixedCapacity(0), |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 138 | mBatteryFixedTemperature(0), |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 139 | mHealthInfo(std::make_unique<HealthInfo>()) { |
Yifan Hong | 6cabe9b | 2019-11-05 17:04:50 -0800 | [diff] [blame] | 140 | initHealthInfo(mHealthInfo.get()); |
| 141 | } |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 142 | |
| 143 | BatteryMonitor::~BatteryMonitor() {} |
| 144 | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 145 | HealthInfo_1_0 BatteryMonitor::getHealthInfo_1_0() const { |
| 146 | HealthInfo_1_0 health_info_1_0; |
| 147 | translateToHidl(*mHealthInfo, &health_info_1_0); |
| 148 | return health_info_1_0; |
Yabin Cui | db04a49 | 2016-02-16 17:19:23 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 151 | HealthInfo_2_0 BatteryMonitor::getHealthInfo_2_0() const { |
| 152 | HealthInfo_2_0 health_info_2_0; |
| 153 | translateToHidl(*mHealthInfo, &health_info_2_0); |
| 154 | return health_info_2_0; |
Hridya Valsaraju | 7fa7225 | 2018-01-12 17:44:33 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 157 | HealthInfo_2_1 BatteryMonitor::getHealthInfo_2_1() const { |
| 158 | HealthInfo_2_1 health_info_2_1; |
| 159 | translateToHidl(*mHealthInfo, &health_info_2_1); |
| 160 | return health_info_2_1; |
| 161 | } |
| 162 | |
| 163 | const HealthInfo& BatteryMonitor::getHealthInfo() const { |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 164 | return *mHealthInfo; |
| 165 | } |
| 166 | |
| 167 | BatteryStatus getBatteryStatus(const char* status) { |
| 168 | static SysfsStringEnumMap<BatteryStatus> batteryStatusMap[] = { |
| 169 | {"Unknown", BatteryStatus::UNKNOWN}, |
| 170 | {"Charging", BatteryStatus::CHARGING}, |
| 171 | {"Discharging", BatteryStatus::DISCHARGING}, |
| 172 | {"Not charging", BatteryStatus::NOT_CHARGING}, |
| 173 | {"Full", BatteryStatus::FULL}, |
| 174 | {NULL, BatteryStatus::UNKNOWN}, |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 177 | auto ret = mapSysfsString(status, batteryStatusMap); |
| 178 | if (!ret) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 179 | KLOG_WARNING(LOG_TAG, "Unknown battery status '%s'\n", status); |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 180 | *ret = BatteryStatus::UNKNOWN; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 183 | return *ret; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Stephane Lee | 86f9f6a | 2019-12-19 15:09:41 -0800 | [diff] [blame] | 186 | BatteryCapacityLevel getBatteryCapacityLevel(const char* capacityLevel) { |
| 187 | static SysfsStringEnumMap<BatteryCapacityLevel> batteryCapacityLevelMap[] = { |
| 188 | {"Unknown", BatteryCapacityLevel::UNKNOWN}, |
| 189 | {"Critical", BatteryCapacityLevel::CRITICAL}, |
| 190 | {"Low", BatteryCapacityLevel::LOW}, |
| 191 | {"Normal", BatteryCapacityLevel::NORMAL}, |
| 192 | {"High", BatteryCapacityLevel::HIGH}, |
| 193 | {"Full", BatteryCapacityLevel::FULL}, |
Stephane Lee | 0684604 | 2020-02-12 17:00:24 -0800 | [diff] [blame] | 194 | {NULL, BatteryCapacityLevel::UNSUPPORTED}, |
Stephane Lee | 86f9f6a | 2019-12-19 15:09:41 -0800 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | auto ret = mapSysfsString(capacityLevel, batteryCapacityLevelMap); |
| 198 | if (!ret) { |
Stephane Lee | 0684604 | 2020-02-12 17:00:24 -0800 | [diff] [blame] | 199 | KLOG_WARNING(LOG_TAG, "Unsupported battery capacity level '%s'\n", capacityLevel); |
| 200 | *ret = BatteryCapacityLevel::UNSUPPORTED; |
Stephane Lee | 86f9f6a | 2019-12-19 15:09:41 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | return *ret; |
| 204 | } |
| 205 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 206 | BatteryHealth getBatteryHealth(const char* status) { |
| 207 | static SysfsStringEnumMap<BatteryHealth> batteryHealthMap[] = { |
| 208 | {"Unknown", BatteryHealth::UNKNOWN}, |
| 209 | {"Good", BatteryHealth::GOOD}, |
| 210 | {"Overheat", BatteryHealth::OVERHEAT}, |
| 211 | {"Dead", BatteryHealth::DEAD}, |
| 212 | {"Over voltage", BatteryHealth::OVER_VOLTAGE}, |
| 213 | {"Unspecified failure", BatteryHealth::UNSPECIFIED_FAILURE}, |
| 214 | {"Cold", BatteryHealth::COLD}, |
| 215 | // battery health values from JEITA spec |
| 216 | {"Warm", BatteryHealth::GOOD}, |
| 217 | {"Cool", BatteryHealth::GOOD}, |
| 218 | {"Hot", BatteryHealth::OVERHEAT}, |
| 219 | {NULL, BatteryHealth::UNKNOWN}, |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 220 | }; |
| 221 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 222 | auto ret = mapSysfsString(status, batteryHealthMap); |
| 223 | if (!ret) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 224 | KLOG_WARNING(LOG_TAG, "Unknown battery health '%s'\n", status); |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 225 | *ret = BatteryHealth::UNKNOWN; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 228 | return *ret; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 231 | int BatteryMonitor::readFromFile(const String8& path, std::string* buf) { |
Steven Moreland | 2aac335 | 2017-03-10 22:31:08 -0800 | [diff] [blame] | 232 | if (android::base::ReadFileToString(path.c_str(), buf)) { |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 233 | *buf = android::base::Trim(*buf); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 234 | } |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 235 | return buf->length(); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String8& path) { |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 239 | static SysfsStringEnumMap<int> supplyTypeMap[] = { |
| 240 | {"Unknown", ANDROID_POWER_SUPPLY_TYPE_UNKNOWN}, |
| 241 | {"Battery", ANDROID_POWER_SUPPLY_TYPE_BATTERY}, |
| 242 | {"UPS", ANDROID_POWER_SUPPLY_TYPE_AC}, |
| 243 | {"Mains", ANDROID_POWER_SUPPLY_TYPE_AC}, |
| 244 | {"USB", ANDROID_POWER_SUPPLY_TYPE_USB}, |
| 245 | {"USB_DCP", ANDROID_POWER_SUPPLY_TYPE_AC}, |
| 246 | {"USB_HVDCP", ANDROID_POWER_SUPPLY_TYPE_AC}, |
| 247 | {"USB_CDP", ANDROID_POWER_SUPPLY_TYPE_AC}, |
| 248 | {"USB_ACA", ANDROID_POWER_SUPPLY_TYPE_AC}, |
| 249 | {"USB_C", ANDROID_POWER_SUPPLY_TYPE_AC}, |
| 250 | {"USB_PD", ANDROID_POWER_SUPPLY_TYPE_AC}, |
| 251 | {"USB_PD_DRP", ANDROID_POWER_SUPPLY_TYPE_USB}, |
| 252 | {"Wireless", ANDROID_POWER_SUPPLY_TYPE_WIRELESS}, |
Jack Wu | 06b9041 | 2021-12-15 20:40:21 +0800 | [diff] [blame] | 253 | {"Dock", ANDROID_POWER_SUPPLY_TYPE_DOCK}, |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 254 | {NULL, 0}, |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 255 | }; |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 256 | std::string buf; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 257 | |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 258 | if (readFromFile(path, &buf) <= 0) |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 259 | return ANDROID_POWER_SUPPLY_TYPE_UNKNOWN; |
| 260 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 261 | auto ret = mapSysfsString(buf.c_str(), supplyTypeMap); |
John Stultz | 47a6bf0 | 2019-11-06 00:23:34 +0000 | [diff] [blame] | 262 | if (!ret) { |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 263 | KLOG_WARNING(LOG_TAG, "Unknown power supply type '%s'\n", buf.c_str()); |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 264 | *ret = ANDROID_POWER_SUPPLY_TYPE_UNKNOWN; |
Johan Redestig | 3282861 | 2016-02-03 13:45:54 +0100 | [diff] [blame] | 265 | } |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 266 | |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 267 | return static_cast<BatteryMonitor::PowerSupplyType>(*ret); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | bool BatteryMonitor::getBooleanField(const String8& path) { |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 271 | std::string buf; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 272 | bool value = false; |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 273 | |
| 274 | if (readFromFile(path, &buf) > 0) |
| 275 | if (buf[0] != '0') |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 276 | value = true; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 277 | |
| 278 | return value; |
| 279 | } |
| 280 | |
| 281 | int BatteryMonitor::getIntField(const String8& path) { |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 282 | std::string buf; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 283 | int value = 0; |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 284 | |
| 285 | if (readFromFile(path, &buf) > 0) |
Elliott Hughes | da46b39 | 2016-10-11 17:09:00 -0700 | [diff] [blame] | 286 | android::base::ParseInt(buf, &value); |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 287 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 288 | return value; |
| 289 | } |
| 290 | |
Kazuhiro Inaba | 8e4d982 | 2019-06-12 13:46:08 +0900 | [diff] [blame] | 291 | bool BatteryMonitor::isScopedPowerSupply(const char* name) { |
| 292 | constexpr char kScopeDevice[] = "Device"; |
| 293 | |
| 294 | String8 path; |
| 295 | path.appendFormat("%s/%s/scope", POWER_SUPPLY_SYSFS_PATH, name); |
| 296 | std::string scope; |
| 297 | return (readFromFile(path, &scope) > 0 && scope == kScopeDevice); |
| 298 | } |
| 299 | |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 300 | void BatteryMonitor::updateValues(void) { |
Yifan Hong | 6cabe9b | 2019-11-05 17:04:50 -0800 | [diff] [blame] | 301 | initHealthInfo(mHealthInfo.get()); |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 302 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 303 | if (!mHealthdConfig->batteryPresentPath.isEmpty()) |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 304 | mHealthInfo->batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 305 | else |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 306 | mHealthInfo->batteryPresent = mBatteryDevicePresent; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 307 | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 308 | mHealthInfo->batteryLevel = mBatteryFixedCapacity |
| 309 | ? mBatteryFixedCapacity |
| 310 | : getIntField(mHealthdConfig->batteryCapacityPath); |
| 311 | mHealthInfo->batteryVoltageMillivolts = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; |
Todd Poynor | b45f1f5 | 2013-07-30 18:57:16 -0700 | [diff] [blame] | 312 | |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 313 | if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 314 | mHealthInfo->batteryCurrentMicroamps = getIntField(mHealthdConfig->batteryCurrentNowPath); |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 315 | |
| 316 | if (!mHealthdConfig->batteryFullChargePath.isEmpty()) |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 317 | mHealthInfo->batteryFullChargeUah = getIntField(mHealthdConfig->batteryFullChargePath); |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 318 | |
| 319 | if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 320 | mHealthInfo->batteryCycleCount = getIntField(mHealthdConfig->batteryCycleCountPath); |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 321 | |
Ruchi Kandoi | 3f9886b | 2016-04-07 12:34:40 -0700 | [diff] [blame] | 322 | if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 323 | mHealthInfo->batteryChargeCounterUah = |
| 324 | getIntField(mHealthdConfig->batteryChargeCounterPath); |
Ruchi Kandoi | 3f9886b | 2016-04-07 12:34:40 -0700 | [diff] [blame] | 325 | |
Yifan Hong | 35cb083 | 2019-10-07 13:58:29 -0700 | [diff] [blame] | 326 | if (!mHealthdConfig->batteryCurrentAvgPath.isEmpty()) |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 327 | mHealthInfo->batteryCurrentAverageMicroamps = |
Yifan Hong | 35cb083 | 2019-10-07 13:58:29 -0700 | [diff] [blame] | 328 | getIntField(mHealthdConfig->batteryCurrentAvgPath); |
| 329 | |
Stephane Lee | 86f9f6a | 2019-12-19 15:09:41 -0800 | [diff] [blame] | 330 | if (!mHealthdConfig->batteryChargeTimeToFullNowPath.isEmpty()) |
| 331 | mHealthInfo->batteryChargeTimeToFullNowSeconds = |
| 332 | getIntField(mHealthdConfig->batteryChargeTimeToFullNowPath); |
| 333 | |
Stephane Lee | 1c108ed | 2020-02-10 18:23:57 -0800 | [diff] [blame] | 334 | if (!mHealthdConfig->batteryFullChargeDesignCapacityUahPath.isEmpty()) |
| 335 | mHealthInfo->batteryFullChargeDesignCapacityUah = |
| 336 | getIntField(mHealthdConfig->batteryFullChargeDesignCapacityUahPath); |
Yifan Hong | 35cb083 | 2019-10-07 13:58:29 -0700 | [diff] [blame] | 337 | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 338 | mHealthInfo->batteryTemperatureTenthsCelsius = |
| 339 | mBatteryFixedTemperature ? mBatteryFixedTemperature |
| 340 | : getIntField(mHealthdConfig->batteryTemperaturePath); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 341 | |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 342 | std::string buf; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 343 | |
Stephane Lee | 86f9f6a | 2019-12-19 15:09:41 -0800 | [diff] [blame] | 344 | if (readFromFile(mHealthdConfig->batteryCapacityLevelPath, &buf) > 0) |
| 345 | mHealthInfo->batteryCapacityLevel = getBatteryCapacityLevel(buf.c_str()); |
| 346 | |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 347 | if (readFromFile(mHealthdConfig->batteryStatusPath, &buf) > 0) |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 348 | mHealthInfo->batteryStatus = getBatteryStatus(buf.c_str()); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 349 | |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 350 | if (readFromFile(mHealthdConfig->batteryHealthPath, &buf) > 0) |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 351 | mHealthInfo->batteryHealth = getBatteryHealth(buf.c_str()); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 352 | |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 353 | if (readFromFile(mHealthdConfig->batteryTechnologyPath, &buf) > 0) |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 354 | mHealthInfo->batteryTechnology = String8(buf.c_str()); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 355 | |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 356 | double MaxPower = 0; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 357 | |
ShevT | 9d98a6a | 2018-07-26 11:47:47 +0300 | [diff] [blame] | 358 | for (size_t i = 0; i < mChargerNames.size(); i++) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 359 | String8 path; |
| 360 | path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, |
| 361 | mChargerNames[i].string()); |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 362 | if (getIntField(path)) { |
| 363 | path.clear(); |
| 364 | path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, |
| 365 | mChargerNames[i].string()); |
| 366 | switch(readPowerSupplyType(path)) { |
| 367 | case ANDROID_POWER_SUPPLY_TYPE_AC: |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 368 | mHealthInfo->chargerAcOnline = true; |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 369 | break; |
| 370 | case ANDROID_POWER_SUPPLY_TYPE_USB: |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 371 | mHealthInfo->chargerUsbOnline = true; |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 372 | break; |
| 373 | case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 374 | mHealthInfo->chargerWirelessOnline = true; |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 375 | break; |
Jack Wu | 06b9041 | 2021-12-15 20:40:21 +0800 | [diff] [blame] | 376 | case ANDROID_POWER_SUPPLY_TYPE_DOCK: |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 377 | mHealthInfo->chargerDockOnline = true; |
Jack Wu | 06b9041 | 2021-12-15 20:40:21 +0800 | [diff] [blame] | 378 | break; |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 379 | default: |
Jack Wu | 06b9041 | 2021-12-15 20:40:21 +0800 | [diff] [blame] | 380 | path.clear(); |
| 381 | path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH, |
| 382 | mChargerNames[i].string()); |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 383 | if (access(path.string(), R_OK) == 0) |
| 384 | mHealthInfo->chargerDockOnline = true; |
| 385 | else |
Jack Wu | 06b9041 | 2021-12-15 20:40:21 +0800 | [diff] [blame] | 386 | KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", |
| 387 | mChargerNames[i].string()); |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 388 | } |
| 389 | path.clear(); |
| 390 | path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH, |
| 391 | mChargerNames[i].string()); |
Dmitry Shmidt | 9f6b80c | 2016-06-20 12:58:37 -0700 | [diff] [blame] | 392 | int ChargingCurrent = |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 393 | (access(path.string(), R_OK) == 0) ? getIntField(path) : 0; |
| 394 | |
Dmitry Shmidt | 9f6b80c | 2016-06-20 12:58:37 -0700 | [diff] [blame] | 395 | path.clear(); |
| 396 | path.appendFormat("%s/%s/voltage_max", POWER_SUPPLY_SYSFS_PATH, |
| 397 | mChargerNames[i].string()); |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 398 | |
Dmitry Shmidt | 9f6b80c | 2016-06-20 12:58:37 -0700 | [diff] [blame] | 399 | int ChargingVoltage = |
| 400 | (access(path.string(), R_OK) == 0) ? getIntField(path) : |
| 401 | DEFAULT_VBUS_VOLTAGE; |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 402 | |
Dmitry Shmidt | 9f6b80c | 2016-06-20 12:58:37 -0700 | [diff] [blame] | 403 | double power = ((double)ChargingCurrent / MILLION) * |
| 404 | ((double)ChargingVoltage / MILLION); |
| 405 | if (MaxPower < power) { |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 406 | mHealthInfo->maxChargingCurrentMicroamps = ChargingCurrent; |
| 407 | mHealthInfo->maxChargingVoltageMicrovolts = ChargingVoltage; |
Dmitry Shmidt | 9f6b80c | 2016-06-20 12:58:37 -0700 | [diff] [blame] | 408 | MaxPower = power; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | } |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 412 | } |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 413 | |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 414 | void BatteryMonitor::logValues(void) { |
Yifan Hong | 605e7d2 | 2021-02-08 15:14:48 -0800 | [diff] [blame] | 415 | logValues(*mHealthInfo, *mHealthdConfig); |
| 416 | } |
| 417 | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 418 | void BatteryMonitor::logValues(const HealthInfo_2_1& health_info, |
| 419 | const struct healthd_config& healthd_config) { |
| 420 | HealthInfo aidl_health_info; |
| 421 | (void)android::h2a::translate(health_info, &aidl_health_info); |
| 422 | logValues(aidl_health_info, healthd_config); |
| 423 | } |
| 424 | |
| 425 | void BatteryMonitor::logValues(const HealthInfo& props, |
Yifan Hong | 605e7d2 | 2021-02-08 15:14:48 -0800 | [diff] [blame] | 426 | const struct healthd_config& healthd_config) { |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 427 | char dmesgline[256]; |
| 428 | size_t len; |
| 429 | if (props.batteryPresent) { |
| 430 | snprintf(dmesgline, sizeof(dmesgline), "battery l=%d v=%d t=%s%d.%d h=%d st=%d", |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 431 | props.batteryLevel, props.batteryVoltageMillivolts, |
| 432 | props.batteryTemperatureTenthsCelsius < 0 ? "-" : "", |
| 433 | abs(props.batteryTemperatureTenthsCelsius / 10), |
| 434 | abs(props.batteryTemperatureTenthsCelsius % 10), props.batteryHealth, |
| 435 | props.batteryStatus); |
Todd Poynor | b45f1f5 | 2013-07-30 18:57:16 -0700 | [diff] [blame] | 436 | |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 437 | len = strlen(dmesgline); |
Yifan Hong | 605e7d2 | 2021-02-08 15:14:48 -0800 | [diff] [blame] | 438 | if (!healthd_config.batteryCurrentNowPath.isEmpty()) { |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 439 | len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " c=%d", |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 440 | props.batteryCurrentMicroamps); |
Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Yifan Hong | 605e7d2 | 2021-02-08 15:14:48 -0800 | [diff] [blame] | 443 | if (!healthd_config.batteryFullChargePath.isEmpty()) { |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 444 | len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " fc=%d", |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 445 | props.batteryFullChargeUah); |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 446 | } |
Mark Salyzyn | acb1ddf | 2015-07-23 09:22:50 -0700 | [diff] [blame] | 447 | |
Yifan Hong | 605e7d2 | 2021-02-08 15:14:48 -0800 | [diff] [blame] | 448 | if (!healthd_config.batteryCycleCountPath.isEmpty()) { |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 449 | len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " cc=%d", |
| 450 | props.batteryCycleCount); |
| 451 | } |
| 452 | } else { |
| 453 | len = snprintf(dmesgline, sizeof(dmesgline), "battery none"); |
Todd Poynor | b45f1f5 | 2013-07-30 18:57:16 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 456 | snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s%s", |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 457 | props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "", |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 458 | props.chargerWirelessOnline ? "w" : "", props.chargerDockOnline ? "d" : ""); |
Yifan Hong | 1353e70 | 2019-10-07 10:41:30 -0700 | [diff] [blame] | 459 | |
| 460 | KLOG_WARNING(LOG_TAG, "%s\n", dmesgline); |
| 461 | } |
| 462 | |
| 463 | bool BatteryMonitor::isChargerOnline() { |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 464 | const HealthInfo& props = *mHealthInfo; |
Jack Wu | 06b9041 | 2021-12-15 20:40:21 +0800 | [diff] [blame] | 465 | return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline | |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 466 | props.chargerDockOnline; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Yabin Cui | aedf603 | 2016-02-19 18:03:23 -0800 | [diff] [blame] | 469 | int BatteryMonitor::getChargeStatus() { |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 470 | BatteryStatus result = BatteryStatus::UNKNOWN; |
Yabin Cui | aedf603 | 2016-02-19 18:03:23 -0800 | [diff] [blame] | 471 | if (!mHealthdConfig->batteryStatusPath.isEmpty()) { |
Michael Scott | 3217c5c | 2016-06-05 11:20:13 -0700 | [diff] [blame] | 472 | std::string buf; |
| 473 | if (readFromFile(mHealthdConfig->batteryStatusPath, &buf) > 0) |
| 474 | result = getBatteryStatus(buf.c_str()); |
Yabin Cui | aedf603 | 2016-02-19 18:03:23 -0800 | [diff] [blame] | 475 | } |
Yifan Hong | 1d4368b | 2019-10-07 11:18:04 -0700 | [diff] [blame] | 476 | return static_cast<int>(result); |
Yabin Cui | aedf603 | 2016-02-19 18:03:23 -0800 | [diff] [blame] | 477 | } |
| 478 | |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 479 | status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { |
| 480 | status_t ret = BAD_VALUE; |
Jin Qian | 72adf11 | 2017-02-02 17:31:13 -0800 | [diff] [blame] | 481 | std::string buf; |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 482 | |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 483 | val->valueInt64 = LONG_MIN; |
| 484 | |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 485 | switch(id) { |
| 486 | case BATTERY_PROP_CHARGE_COUNTER: |
| 487 | if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) { |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 488 | val->valueInt64 = |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 489 | getIntField(mHealthdConfig->batteryChargeCounterPath); |
Elliott Hughes | 643268f | 2018-10-08 11:10:11 -0700 | [diff] [blame] | 490 | ret = OK; |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 491 | } else { |
| 492 | ret = NAME_NOT_FOUND; |
| 493 | } |
| 494 | break; |
| 495 | |
| 496 | case BATTERY_PROP_CURRENT_NOW: |
| 497 | if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 498 | val->valueInt64 = |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 499 | getIntField(mHealthdConfig->batteryCurrentNowPath); |
Elliott Hughes | 643268f | 2018-10-08 11:10:11 -0700 | [diff] [blame] | 500 | ret = OK; |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 501 | } else { |
| 502 | ret = NAME_NOT_FOUND; |
| 503 | } |
| 504 | break; |
| 505 | |
Todd Poynor | bc10211 | 2013-08-27 18:11:49 -0700 | [diff] [blame] | 506 | case BATTERY_PROP_CURRENT_AVG: |
| 507 | if (!mHealthdConfig->batteryCurrentAvgPath.isEmpty()) { |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 508 | val->valueInt64 = |
Todd Poynor | bc10211 | 2013-08-27 18:11:49 -0700 | [diff] [blame] | 509 | getIntField(mHealthdConfig->batteryCurrentAvgPath); |
Elliott Hughes | 643268f | 2018-10-08 11:10:11 -0700 | [diff] [blame] | 510 | ret = OK; |
Todd Poynor | bc10211 | 2013-08-27 18:11:49 -0700 | [diff] [blame] | 511 | } else { |
| 512 | ret = NAME_NOT_FOUND; |
| 513 | } |
| 514 | break; |
| 515 | |
Paul Lawrence | 347c8de | 2014-03-19 15:04:40 -0700 | [diff] [blame] | 516 | case BATTERY_PROP_CAPACITY: |
| 517 | if (!mHealthdConfig->batteryCapacityPath.isEmpty()) { |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 518 | val->valueInt64 = |
Paul Lawrence | 347c8de | 2014-03-19 15:04:40 -0700 | [diff] [blame] | 519 | getIntField(mHealthdConfig->batteryCapacityPath); |
Elliott Hughes | 643268f | 2018-10-08 11:10:11 -0700 | [diff] [blame] | 520 | ret = OK; |
Paul Lawrence | 347c8de | 2014-03-19 15:04:40 -0700 | [diff] [blame] | 521 | } else { |
| 522 | ret = NAME_NOT_FOUND; |
| 523 | } |
| 524 | break; |
| 525 | |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 526 | case BATTERY_PROP_ENERGY_COUNTER: |
Todd Poynor | e14b37e | 2014-05-20 13:54:40 -0700 | [diff] [blame] | 527 | if (mHealthdConfig->energyCounter) { |
| 528 | ret = mHealthdConfig->energyCounter(&val->valueInt64); |
| 529 | } else { |
| 530 | ret = NAME_NOT_FOUND; |
| 531 | } |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 532 | break; |
| 533 | |
Jin Qian | 72adf11 | 2017-02-02 17:31:13 -0800 | [diff] [blame] | 534 | case BATTERY_PROP_BATTERY_STATUS: |
Todd Poynor | e030a10 | 2018-01-19 14:03:59 -0800 | [diff] [blame] | 535 | val->valueInt64 = getChargeStatus(); |
Elliott Hughes | 643268f | 2018-10-08 11:10:11 -0700 | [diff] [blame] | 536 | ret = OK; |
Jin Qian | 72adf11 | 2017-02-02 17:31:13 -0800 | [diff] [blame] | 537 | break; |
| 538 | |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 539 | default: |
| 540 | break; |
| 541 | } |
| 542 | |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 543 | return ret; |
| 544 | } |
| 545 | |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 546 | void BatteryMonitor::dumpState(int fd) { |
| 547 | int v; |
| 548 | char vs[128]; |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 549 | const HealthInfo& props = *mHealthInfo; |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 550 | |
Jack Wu | 06b9041 | 2021-12-15 20:40:21 +0800 | [diff] [blame] | 551 | snprintf(vs, sizeof(vs), |
| 552 | "ac: %d usb: %d wireless: %d dock: %d current_max: %d voltage_max: %d\n", |
| 553 | props.chargerAcOnline, props.chargerUsbOnline, props.chargerWirelessOnline, |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 554 | props.chargerDockOnline, props.maxChargingCurrentMicroamps, |
| 555 | props.maxChargingVoltageMicrovolts); |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 556 | write(fd, vs, strlen(vs)); |
| 557 | snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n", |
| 558 | props.batteryStatus, props.batteryHealth, props.batteryPresent); |
| 559 | write(fd, vs, strlen(vs)); |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 560 | snprintf(vs, sizeof(vs), "level: %d voltage: %d temp: %d\n", props.batteryLevel, |
| 561 | props.batteryVoltageMillivolts, props.batteryTemperatureTenthsCelsius); |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 562 | write(fd, vs, strlen(vs)); |
| 563 | |
| 564 | if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { |
| 565 | v = getIntField(mHealthdConfig->batteryCurrentNowPath); |
| 566 | snprintf(vs, sizeof(vs), "current now: %d\n", v); |
| 567 | write(fd, vs, strlen(vs)); |
| 568 | } |
| 569 | |
| 570 | if (!mHealthdConfig->batteryCurrentAvgPath.isEmpty()) { |
| 571 | v = getIntField(mHealthdConfig->batteryCurrentAvgPath); |
| 572 | snprintf(vs, sizeof(vs), "current avg: %d\n", v); |
| 573 | write(fd, vs, strlen(vs)); |
| 574 | } |
| 575 | |
| 576 | if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) { |
| 577 | v = getIntField(mHealthdConfig->batteryChargeCounterPath); |
| 578 | snprintf(vs, sizeof(vs), "charge counter: %d\n", v); |
| 579 | write(fd, vs, strlen(vs)); |
| 580 | } |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 581 | |
| 582 | if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 583 | snprintf(vs, sizeof(vs), "current now: %d\n", props.batteryCurrentMicroamps); |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 584 | write(fd, vs, strlen(vs)); |
| 585 | } |
| 586 | |
| 587 | if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) { |
| 588 | snprintf(vs, sizeof(vs), "cycle count: %d\n", props.batteryCycleCount); |
| 589 | write(fd, vs, strlen(vs)); |
| 590 | } |
| 591 | |
| 592 | if (!mHealthdConfig->batteryFullChargePath.isEmpty()) { |
Yifan Hong | b99d15c | 2022-03-01 12:12:34 -0800 | [diff] [blame] | 593 | snprintf(vs, sizeof(vs), "Full charge: %d\n", props.batteryFullChargeUah); |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 594 | write(fd, vs, strlen(vs)); |
| 595 | } |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Todd Poynor | c7464c9 | 2013-09-10 12:40:00 -0700 | [diff] [blame] | 598 | void BatteryMonitor::init(struct healthd_config *hc) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 599 | String8 path; |
Todd Poynor | 3db03a5 | 2014-05-21 16:28:13 -0700 | [diff] [blame] | 600 | char pval[PROPERTY_VALUE_MAX]; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 601 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 602 | mHealthdConfig = hc; |
James Hawkins | 588a2ca | 2016-02-18 14:52:46 -0800 | [diff] [blame] | 603 | std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(POWER_SUPPLY_SYSFS_PATH), closedir); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 604 | if (dir == NULL) { |
| 605 | KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH); |
| 606 | } else { |
| 607 | struct dirent* entry; |
| 608 | |
James Hawkins | 588a2ca | 2016-02-18 14:52:46 -0800 | [diff] [blame] | 609 | while ((entry = readdir(dir.get()))) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 610 | const char* name = entry->d_name; |
| 611 | |
| 612 | if (!strcmp(name, ".") || !strcmp(name, "..")) |
| 613 | continue; |
| 614 | |
Bart Van Assche | 25b2a8d | 2022-02-24 21:51:34 +0000 | [diff] [blame^] | 615 | std::vector<String8>::iterator itIgnoreName = |
| 616 | find(hc->ignorePowerSupplyNames.begin(), hc->ignorePowerSupplyNames.end(), |
| 617 | String8(name)); |
Thierry Strudel | f73de6f | 2019-01-11 17:09:20 -0800 | [diff] [blame] | 618 | if (itIgnoreName != hc->ignorePowerSupplyNames.end()) |
| 619 | continue; |
| 620 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 621 | // Look for "type" file in each subdirectory |
| 622 | path.clear(); |
| 623 | path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name); |
| 624 | switch(readPowerSupplyType(path)) { |
| 625 | case ANDROID_POWER_SUPPLY_TYPE_AC: |
| 626 | case ANDROID_POWER_SUPPLY_TYPE_USB: |
| 627 | case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: |
Jack Wu | 06b9041 | 2021-12-15 20:40:21 +0800 | [diff] [blame] | 628 | case ANDROID_POWER_SUPPLY_TYPE_DOCK: |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 629 | path.clear(); |
| 630 | path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name); |
| 631 | if (access(path.string(), R_OK) == 0) |
| 632 | mChargerNames.add(String8(name)); |
| 633 | break; |
| 634 | |
| 635 | case ANDROID_POWER_SUPPLY_TYPE_BATTERY: |
Kazuhiro Inaba | 8e4d982 | 2019-06-12 13:46:08 +0900 | [diff] [blame] | 636 | // Some devices expose the battery status of sub-component like |
| 637 | // stylus. Such a device-scoped battery info needs to be skipped |
| 638 | // in BatteryMonitor, which is intended to report the status of |
| 639 | // the battery supplying the power to the whole system. |
| 640 | if (isScopedPowerSupply(name)) continue; |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 641 | mBatteryDevicePresent = true; |
| 642 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 643 | if (mHealthdConfig->batteryStatusPath.isEmpty()) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 644 | path.clear(); |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 645 | path.appendFormat("%s/%s/status", POWER_SUPPLY_SYSFS_PATH, |
| 646 | name); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 647 | if (access(path, R_OK) == 0) |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 648 | mHealthdConfig->batteryStatusPath = path; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 651 | if (mHealthdConfig->batteryHealthPath.isEmpty()) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 652 | path.clear(); |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 653 | path.appendFormat("%s/%s/health", POWER_SUPPLY_SYSFS_PATH, |
| 654 | name); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 655 | if (access(path, R_OK) == 0) |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 656 | mHealthdConfig->batteryHealthPath = path; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 659 | if (mHealthdConfig->batteryPresentPath.isEmpty()) { |
| 660 | path.clear(); |
| 661 | path.appendFormat("%s/%s/present", POWER_SUPPLY_SYSFS_PATH, |
| 662 | name); |
| 663 | if (access(path, R_OK) == 0) |
| 664 | mHealthdConfig->batteryPresentPath = path; |
| 665 | } |
| 666 | |
| 667 | if (mHealthdConfig->batteryCapacityPath.isEmpty()) { |
| 668 | path.clear(); |
| 669 | path.appendFormat("%s/%s/capacity", POWER_SUPPLY_SYSFS_PATH, |
| 670 | name); |
| 671 | if (access(path, R_OK) == 0) |
| 672 | mHealthdConfig->batteryCapacityPath = path; |
| 673 | } |
| 674 | |
| 675 | if (mHealthdConfig->batteryVoltagePath.isEmpty()) { |
| 676 | path.clear(); |
| 677 | path.appendFormat("%s/%s/voltage_now", |
| 678 | POWER_SUPPLY_SYSFS_PATH, name); |
| 679 | if (access(path, R_OK) == 0) { |
| 680 | mHealthdConfig->batteryVoltagePath = path; |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 684 | if (mHealthdConfig->batteryFullChargePath.isEmpty()) { |
| 685 | path.clear(); |
| 686 | path.appendFormat("%s/%s/charge_full", |
| 687 | POWER_SUPPLY_SYSFS_PATH, name); |
| 688 | if (access(path, R_OK) == 0) |
| 689 | mHealthdConfig->batteryFullChargePath = path; |
| 690 | } |
| 691 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 692 | if (mHealthdConfig->batteryCurrentNowPath.isEmpty()) { |
| 693 | path.clear(); |
| 694 | path.appendFormat("%s/%s/current_now", |
| 695 | POWER_SUPPLY_SYSFS_PATH, name); |
| 696 | if (access(path, R_OK) == 0) |
| 697 | mHealthdConfig->batteryCurrentNowPath = path; |
| 698 | } |
| 699 | |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 700 | if (mHealthdConfig->batteryCycleCountPath.isEmpty()) { |
| 701 | path.clear(); |
| 702 | path.appendFormat("%s/%s/cycle_count", |
| 703 | POWER_SUPPLY_SYSFS_PATH, name); |
| 704 | if (access(path, R_OK) == 0) |
| 705 | mHealthdConfig->batteryCycleCountPath = path; |
| 706 | } |
| 707 | |
Stephane Lee | 86f9f6a | 2019-12-19 15:09:41 -0800 | [diff] [blame] | 708 | if (mHealthdConfig->batteryCapacityLevelPath.isEmpty()) { |
| 709 | path.clear(); |
| 710 | path.appendFormat("%s/%s/capacity_level", POWER_SUPPLY_SYSFS_PATH, name); |
| 711 | if (access(path, R_OK) == 0) mHealthdConfig->batteryCapacityLevelPath = path; |
| 712 | } |
| 713 | |
| 714 | if (mHealthdConfig->batteryChargeTimeToFullNowPath.isEmpty()) { |
| 715 | path.clear(); |
| 716 | path.appendFormat("%s/%s/time_to_full_now", POWER_SUPPLY_SYSFS_PATH, name); |
| 717 | if (access(path, R_OK) == 0) |
| 718 | mHealthdConfig->batteryChargeTimeToFullNowPath = path; |
| 719 | } |
| 720 | |
Stephane Lee | 1c108ed | 2020-02-10 18:23:57 -0800 | [diff] [blame] | 721 | if (mHealthdConfig->batteryFullChargeDesignCapacityUahPath.isEmpty()) { |
| 722 | path.clear(); |
| 723 | path.appendFormat("%s/%s/charge_full_design", POWER_SUPPLY_SYSFS_PATH, name); |
| 724 | if (access(path, R_OK) == 0) |
| 725 | mHealthdConfig->batteryFullChargeDesignCapacityUahPath = path; |
| 726 | } |
| 727 | |
Todd Poynor | bc10211 | 2013-08-27 18:11:49 -0700 | [diff] [blame] | 728 | if (mHealthdConfig->batteryCurrentAvgPath.isEmpty()) { |
| 729 | path.clear(); |
| 730 | path.appendFormat("%s/%s/current_avg", |
| 731 | POWER_SUPPLY_SYSFS_PATH, name); |
| 732 | if (access(path, R_OK) == 0) |
| 733 | mHealthdConfig->batteryCurrentAvgPath = path; |
| 734 | } |
| 735 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 736 | if (mHealthdConfig->batteryChargeCounterPath.isEmpty()) { |
| 737 | path.clear(); |
| 738 | path.appendFormat("%s/%s/charge_counter", |
| 739 | POWER_SUPPLY_SYSFS_PATH, name); |
| 740 | if (access(path, R_OK) == 0) |
| 741 | mHealthdConfig->batteryChargeCounterPath = path; |
| 742 | } |
| 743 | |
| 744 | if (mHealthdConfig->batteryTemperaturePath.isEmpty()) { |
| 745 | path.clear(); |
| 746 | path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH, |
| 747 | name); |
| 748 | if (access(path, R_OK) == 0) { |
| 749 | mHealthdConfig->batteryTemperaturePath = path; |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | |
| 753 | if (mHealthdConfig->batteryTechnologyPath.isEmpty()) { |
| 754 | path.clear(); |
| 755 | path.appendFormat("%s/%s/technology", |
| 756 | POWER_SUPPLY_SYSFS_PATH, name); |
| 757 | if (access(path, R_OK) == 0) |
| 758 | mHealthdConfig->batteryTechnologyPath = path; |
| 759 | } |
| 760 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 761 | break; |
| 762 | |
| 763 | case ANDROID_POWER_SUPPLY_TYPE_UNKNOWN: |
| 764 | break; |
| 765 | } |
Jack Wu | 06b9041 | 2021-12-15 20:40:21 +0800 | [diff] [blame] | 766 | |
| 767 | // Look for "is_dock" file |
| 768 | path.clear(); |
| 769 | path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH, name); |
| 770 | if (access(path.string(), R_OK) == 0) { |
| 771 | path.clear(); |
| 772 | path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name); |
| 773 | if (access(path.string(), R_OK) == 0) |
| 774 | mChargerNames.add(String8(name)); |
| 775 | |
| 776 | } |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 777 | } |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Ian Pedowitz | 585ab65 | 2015-10-12 19:01:00 -0700 | [diff] [blame] | 780 | // Typically the case for devices which do not have a battery and |
| 781 | // and are always plugged into AC mains. |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 782 | if (!mBatteryDevicePresent) { |
Todd Poynor | ebeb0c0 | 2014-09-23 14:54:24 -0700 | [diff] [blame] | 783 | KLOG_WARNING(LOG_TAG, "No battery devices found\n"); |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 784 | hc->periodic_chores_interval_fast = -1; |
| 785 | hc->periodic_chores_interval_slow = -1; |
| 786 | } else { |
| 787 | if (mHealthdConfig->batteryStatusPath.isEmpty()) |
| 788 | KLOG_WARNING(LOG_TAG, "BatteryStatusPath not found\n"); |
| 789 | if (mHealthdConfig->batteryHealthPath.isEmpty()) |
| 790 | KLOG_WARNING(LOG_TAG, "BatteryHealthPath not found\n"); |
| 791 | if (mHealthdConfig->batteryPresentPath.isEmpty()) |
| 792 | KLOG_WARNING(LOG_TAG, "BatteryPresentPath not found\n"); |
| 793 | if (mHealthdConfig->batteryCapacityPath.isEmpty()) |
| 794 | KLOG_WARNING(LOG_TAG, "BatteryCapacityPath not found\n"); |
| 795 | if (mHealthdConfig->batteryVoltagePath.isEmpty()) |
| 796 | KLOG_WARNING(LOG_TAG, "BatteryVoltagePath not found\n"); |
| 797 | if (mHealthdConfig->batteryTemperaturePath.isEmpty()) |
| 798 | KLOG_WARNING(LOG_TAG, "BatteryTemperaturePath not found\n"); |
| 799 | if (mHealthdConfig->batteryTechnologyPath.isEmpty()) |
| 800 | KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n"); |
Ruchi Kandoi | f18ec9f | 2015-09-28 13:35:59 -0700 | [diff] [blame] | 801 | if (mHealthdConfig->batteryCurrentNowPath.isEmpty()) |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 802 | KLOG_WARNING(LOG_TAG, "BatteryCurrentNowPath not found\n"); |
| 803 | if (mHealthdConfig->batteryFullChargePath.isEmpty()) |
| 804 | KLOG_WARNING(LOG_TAG, "BatteryFullChargePath not found\n"); |
| 805 | if (mHealthdConfig->batteryCycleCountPath.isEmpty()) |
| 806 | KLOG_WARNING(LOG_TAG, "BatteryCycleCountPath not found\n"); |
Stephane Lee | 86f9f6a | 2019-12-19 15:09:41 -0800 | [diff] [blame] | 807 | if (mHealthdConfig->batteryCapacityLevelPath.isEmpty()) |
| 808 | KLOG_WARNING(LOG_TAG, "batteryCapacityLevelPath not found\n"); |
| 809 | if (mHealthdConfig->batteryChargeTimeToFullNowPath.isEmpty()) |
| 810 | KLOG_WARNING(LOG_TAG, "batteryChargeTimeToFullNowPath. not found\n"); |
Stephane Lee | 1c108ed | 2020-02-10 18:23:57 -0800 | [diff] [blame] | 811 | if (mHealthdConfig->batteryFullChargeDesignCapacityUahPath.isEmpty()) |
| 812 | KLOG_WARNING(LOG_TAG, "batteryFullChargeDesignCapacityUahPath. not found\n"); |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 813 | } |
Todd Poynor | 3db03a5 | 2014-05-21 16:28:13 -0700 | [diff] [blame] | 814 | |
Ruchi Kandoi | a78fc23 | 2014-07-10 15:06:21 -0700 | [diff] [blame] | 815 | if (property_get("ro.boot.fake_battery", pval, NULL) > 0 |
| 816 | && strtol(pval, NULL, 10) != 0) { |
| 817 | mBatteryFixedCapacity = FAKE_BATTERY_CAPACITY; |
| 818 | mBatteryFixedTemperature = FAKE_BATTERY_TEMPERATURE; |
| 819 | } |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | }; // namespace android |