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