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 | f6dbc6d | 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> |
Mark Salyzyn | acb1ddf | 2015-07-23 09:22:50 -0700 | [diff] [blame] | 29 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 30 | #include <batteryservice/BatteryService.h> |
| 31 | #include <cutils/klog.h> |
Todd Poynor | 3db03a5 | 2014-05-21 16:28:13 -0700 | [diff] [blame] | 32 | #include <cutils/properties.h> |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 33 | #include <utils/Errors.h> |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 34 | #include <utils/String8.h> |
| 35 | #include <utils/Vector.h> |
| 36 | |
| 37 | #define POWER_SUPPLY_SUBSYSTEM "power_supply" |
| 38 | #define POWER_SUPPLY_SYSFS_PATH "/sys/class/" POWER_SUPPLY_SUBSYSTEM |
Ruchi Kandoi | a78fc23 | 2014-07-10 15:06:21 -0700 | [diff] [blame] | 39 | #define FAKE_BATTERY_CAPACITY 42 |
| 40 | #define FAKE_BATTERY_TEMPERATURE 424 |
Ruchi Kandoi | f18ec9f | 2015-09-28 13:35:59 -0700 | [diff] [blame] | 41 | #define ALWAYS_PLUGGED_CAPACITY 100 |
Ruchi Kandoi | 5c09ec1 | 2016-02-25 16:19:30 -0800 | [diff] [blame] | 42 | #define MILLION 1.0e6 |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 43 | #define DEFAULT_VBUS_VOLTAGE 5000000 |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 44 | |
| 45 | namespace android { |
| 46 | |
| 47 | struct sysfsStringEnumMap { |
Mark Salyzyn | 6f5b47f | 2014-05-15 15:00:59 -0700 | [diff] [blame] | 48 | const char* s; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 49 | int val; |
| 50 | }; |
| 51 | |
| 52 | static int mapSysfsString(const char* str, |
| 53 | struct sysfsStringEnumMap map[]) { |
| 54 | for (int i = 0; map[i].s; i++) |
| 55 | if (!strcmp(str, map[i].s)) |
| 56 | return map[i].val; |
| 57 | |
| 58 | return -1; |
| 59 | } |
| 60 | |
Yabin Cui | ac3387b | 2016-02-16 17:19:23 -0800 | [diff] [blame] | 61 | static void initBatteryProperties(BatteryProperties* props) { |
| 62 | props->chargerAcOnline = false; |
| 63 | props->chargerUsbOnline = false; |
| 64 | props->chargerWirelessOnline = false; |
| 65 | props->maxChargingCurrent = 0; |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 66 | props->maxChargingVoltage = 0; |
Yabin Cui | ac3387b | 2016-02-16 17:19:23 -0800 | [diff] [blame] | 67 | props->batteryStatus = BATTERY_STATUS_UNKNOWN; |
| 68 | props->batteryHealth = BATTERY_HEALTH_UNKNOWN; |
| 69 | props->batteryPresent = false; |
| 70 | props->batteryLevel = 0; |
| 71 | props->batteryVoltage = 0; |
| 72 | props->batteryTemperature = 0; |
| 73 | props->batteryCurrent = 0; |
| 74 | props->batteryCycleCount = 0; |
| 75 | props->batteryFullCharge = 0; |
Ruchi Kandoi | 3f9886b | 2016-04-07 12:34:40 -0700 | [diff] [blame^] | 76 | props->batteryChargeCounter = 0; |
Yabin Cui | ac3387b | 2016-02-16 17:19:23 -0800 | [diff] [blame] | 77 | props->batteryTechnology.clear(); |
| 78 | } |
| 79 | |
| 80 | BatteryMonitor::BatteryMonitor() : mHealthdConfig(nullptr), mBatteryDevicePresent(false), |
| 81 | mAlwaysPluggedDevice(false), mBatteryFixedCapacity(0), mBatteryFixedTemperature(0) { |
| 82 | initBatteryProperties(&props); |
| 83 | } |
| 84 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 85 | int BatteryMonitor::getBatteryStatus(const char* status) { |
| 86 | int ret; |
| 87 | struct sysfsStringEnumMap batteryStatusMap[] = { |
| 88 | { "Unknown", BATTERY_STATUS_UNKNOWN }, |
| 89 | { "Charging", BATTERY_STATUS_CHARGING }, |
| 90 | { "Discharging", BATTERY_STATUS_DISCHARGING }, |
| 91 | { "Not charging", BATTERY_STATUS_NOT_CHARGING }, |
| 92 | { "Full", BATTERY_STATUS_FULL }, |
| 93 | { NULL, 0 }, |
| 94 | }; |
| 95 | |
| 96 | ret = mapSysfsString(status, batteryStatusMap); |
| 97 | if (ret < 0) { |
| 98 | KLOG_WARNING(LOG_TAG, "Unknown battery status '%s'\n", status); |
| 99 | ret = BATTERY_STATUS_UNKNOWN; |
| 100 | } |
| 101 | |
| 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | int BatteryMonitor::getBatteryHealth(const char* status) { |
| 106 | int ret; |
| 107 | struct sysfsStringEnumMap batteryHealthMap[] = { |
| 108 | { "Unknown", BATTERY_HEALTH_UNKNOWN }, |
| 109 | { "Good", BATTERY_HEALTH_GOOD }, |
| 110 | { "Overheat", BATTERY_HEALTH_OVERHEAT }, |
| 111 | { "Dead", BATTERY_HEALTH_DEAD }, |
| 112 | { "Over voltage", BATTERY_HEALTH_OVER_VOLTAGE }, |
| 113 | { "Unspecified failure", BATTERY_HEALTH_UNSPECIFIED_FAILURE }, |
| 114 | { "Cold", BATTERY_HEALTH_COLD }, |
| 115 | { NULL, 0 }, |
| 116 | }; |
| 117 | |
| 118 | ret = mapSysfsString(status, batteryHealthMap); |
| 119 | if (ret < 0) { |
| 120 | KLOG_WARNING(LOG_TAG, "Unknown battery health '%s'\n", status); |
| 121 | ret = BATTERY_HEALTH_UNKNOWN; |
| 122 | } |
| 123 | |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | int BatteryMonitor::readFromFile(const String8& path, char* buf, size_t size) { |
| 128 | char *cp = NULL; |
| 129 | |
| 130 | if (path.isEmpty()) |
| 131 | return -1; |
| 132 | int fd = open(path.string(), O_RDONLY, 0); |
| 133 | if (fd == -1) { |
| 134 | KLOG_ERROR(LOG_TAG, "Could not open '%s'\n", path.string()); |
| 135 | return -1; |
| 136 | } |
| 137 | |
| 138 | ssize_t count = TEMP_FAILURE_RETRY(read(fd, buf, size)); |
| 139 | if (count > 0) |
| 140 | cp = (char *)memrchr(buf, '\n', count); |
| 141 | |
| 142 | if (cp) |
| 143 | *cp = '\0'; |
| 144 | else |
| 145 | buf[0] = '\0'; |
| 146 | |
| 147 | close(fd); |
| 148 | return count; |
| 149 | } |
| 150 | |
| 151 | BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String8& path) { |
| 152 | const int SIZE = 128; |
| 153 | char buf[SIZE]; |
| 154 | int length = readFromFile(path, buf, SIZE); |
| 155 | BatteryMonitor::PowerSupplyType ret; |
| 156 | struct sysfsStringEnumMap supplyTypeMap[] = { |
| 157 | { "Unknown", ANDROID_POWER_SUPPLY_TYPE_UNKNOWN }, |
| 158 | { "Battery", ANDROID_POWER_SUPPLY_TYPE_BATTERY }, |
| 159 | { "UPS", ANDROID_POWER_SUPPLY_TYPE_AC }, |
| 160 | { "Mains", ANDROID_POWER_SUPPLY_TYPE_AC }, |
| 161 | { "USB", ANDROID_POWER_SUPPLY_TYPE_USB }, |
| 162 | { "USB_DCP", ANDROID_POWER_SUPPLY_TYPE_AC }, |
Johan Redestig | 3282861 | 2016-02-03 13:45:54 +0100 | [diff] [blame] | 163 | { "USB_HVDCP", ANDROID_POWER_SUPPLY_TYPE_AC }, |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 164 | { "USB_CDP", ANDROID_POWER_SUPPLY_TYPE_AC }, |
| 165 | { "USB_ACA", ANDROID_POWER_SUPPLY_TYPE_AC }, |
Benson Leung | 8a4eef6 | 2015-10-07 16:12:04 -0700 | [diff] [blame] | 166 | { "USB_C", ANDROID_POWER_SUPPLY_TYPE_AC }, |
| 167 | { "USB_PD", ANDROID_POWER_SUPPLY_TYPE_AC }, |
| 168 | { "USB_PD_DRP", ANDROID_POWER_SUPPLY_TYPE_USB }, |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 169 | { "Wireless", ANDROID_POWER_SUPPLY_TYPE_WIRELESS }, |
| 170 | { NULL, 0 }, |
| 171 | }; |
| 172 | |
| 173 | if (length <= 0) |
| 174 | return ANDROID_POWER_SUPPLY_TYPE_UNKNOWN; |
| 175 | |
| 176 | ret = (BatteryMonitor::PowerSupplyType)mapSysfsString(buf, supplyTypeMap); |
Johan Redestig | 3282861 | 2016-02-03 13:45:54 +0100 | [diff] [blame] | 177 | if (ret < 0) { |
| 178 | KLOG_WARNING(LOG_TAG, "Unknown power supply type '%s'\n", buf); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 179 | ret = ANDROID_POWER_SUPPLY_TYPE_UNKNOWN; |
Johan Redestig | 3282861 | 2016-02-03 13:45:54 +0100 | [diff] [blame] | 180 | } |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 181 | |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | bool BatteryMonitor::getBooleanField(const String8& path) { |
| 186 | const int SIZE = 16; |
| 187 | char buf[SIZE]; |
| 188 | |
| 189 | bool value = false; |
| 190 | if (readFromFile(path, buf, SIZE) > 0) { |
| 191 | if (buf[0] != '0') { |
| 192 | value = true; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | return value; |
| 197 | } |
| 198 | |
| 199 | int BatteryMonitor::getIntField(const String8& path) { |
| 200 | const int SIZE = 128; |
| 201 | char buf[SIZE]; |
| 202 | |
| 203 | int value = 0; |
| 204 | if (readFromFile(path, buf, SIZE) > 0) { |
| 205 | value = strtol(buf, NULL, 0); |
| 206 | } |
| 207 | return value; |
| 208 | } |
| 209 | |
| 210 | bool BatteryMonitor::update(void) { |
Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 211 | bool logthis; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 212 | |
Yabin Cui | ac3387b | 2016-02-16 17:19:23 -0800 | [diff] [blame] | 213 | initBatteryProperties(&props); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 214 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 215 | if (!mHealthdConfig->batteryPresentPath.isEmpty()) |
| 216 | props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 217 | else |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 218 | props.batteryPresent = mBatteryDevicePresent; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 219 | |
Todd Poynor | 3db03a5 | 2014-05-21 16:28:13 -0700 | [diff] [blame] | 220 | props.batteryLevel = mBatteryFixedCapacity ? |
| 221 | mBatteryFixedCapacity : |
| 222 | getIntField(mHealthdConfig->batteryCapacityPath); |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 223 | props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; |
Todd Poynor | b45f1f5 | 2013-07-30 18:57:16 -0700 | [diff] [blame] | 224 | |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 225 | if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) |
| 226 | props.batteryCurrent = getIntField(mHealthdConfig->batteryCurrentNowPath) / 1000; |
| 227 | |
| 228 | if (!mHealthdConfig->batteryFullChargePath.isEmpty()) |
| 229 | props.batteryFullCharge = getIntField(mHealthdConfig->batteryFullChargePath); |
| 230 | |
| 231 | if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) |
| 232 | props.batteryCycleCount = getIntField(mHealthdConfig->batteryCycleCountPath); |
| 233 | |
Ruchi Kandoi | 3f9886b | 2016-04-07 12:34:40 -0700 | [diff] [blame^] | 234 | if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) |
| 235 | props.batteryChargeCounter = getIntField(mHealthdConfig->batteryChargeCounterPath); |
| 236 | |
Todd Poynor | 3db03a5 | 2014-05-21 16:28:13 -0700 | [diff] [blame] | 237 | props.batteryTemperature = mBatteryFixedTemperature ? |
| 238 | mBatteryFixedTemperature : |
| 239 | getIntField(mHealthdConfig->batteryTemperaturePath); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 240 | |
Ruchi Kandoi | f18ec9f | 2015-09-28 13:35:59 -0700 | [diff] [blame] | 241 | // For devices which do not have battery and are always plugged |
| 242 | // into power souce. |
| 243 | if (mAlwaysPluggedDevice) { |
| 244 | props.chargerAcOnline = true; |
| 245 | props.batteryPresent = true; |
| 246 | props.batteryStatus = BATTERY_STATUS_CHARGING; |
| 247 | props.batteryHealth = BATTERY_HEALTH_GOOD; |
| 248 | } |
| 249 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 250 | const int SIZE = 128; |
| 251 | char buf[SIZE]; |
| 252 | String8 btech; |
| 253 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 254 | if (readFromFile(mHealthdConfig->batteryStatusPath, buf, SIZE) > 0) |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 255 | props.batteryStatus = getBatteryStatus(buf); |
| 256 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 257 | if (readFromFile(mHealthdConfig->batteryHealthPath, buf, SIZE) > 0) |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 258 | props.batteryHealth = getBatteryHealth(buf); |
| 259 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 260 | if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 261 | props.batteryTechnology = String8(buf); |
| 262 | |
| 263 | unsigned int i; |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 264 | double MaxPower = 0; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 265 | |
| 266 | for (i = 0; i < mChargerNames.size(); i++) { |
| 267 | String8 path; |
| 268 | path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, |
| 269 | mChargerNames[i].string()); |
| 270 | |
| 271 | if (readFromFile(path, buf, SIZE) > 0) { |
| 272 | if (buf[0] != '0') { |
| 273 | path.clear(); |
| 274 | path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, |
| 275 | mChargerNames[i].string()); |
| 276 | switch(readPowerSupplyType(path)) { |
| 277 | case ANDROID_POWER_SUPPLY_TYPE_AC: |
| 278 | props.chargerAcOnline = true; |
| 279 | break; |
| 280 | case ANDROID_POWER_SUPPLY_TYPE_USB: |
| 281 | props.chargerUsbOnline = true; |
| 282 | break; |
| 283 | case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: |
| 284 | props.chargerWirelessOnline = true; |
| 285 | break; |
| 286 | default: |
| 287 | KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", |
| 288 | mChargerNames[i].string()); |
| 289 | } |
Adrian Roos | d5fe667 | 2015-07-10 13:11:01 -0700 | [diff] [blame] | 290 | path.clear(); |
| 291 | path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH, |
| 292 | mChargerNames[i].string()); |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 293 | int ChargingCurrent = |
| 294 | (access(path.string(), R_OK) == 0) ? getIntField(path) : 0; |
| 295 | |
| 296 | path.clear(); |
| 297 | path.appendFormat("%s/%s/voltage_max", POWER_SUPPLY_SYSFS_PATH, |
| 298 | mChargerNames[i].string()); |
| 299 | |
| 300 | int ChargingVoltage = |
| 301 | (access(path.string(), R_OK) == 0) ? getIntField(path) : |
| 302 | DEFAULT_VBUS_VOLTAGE; |
| 303 | |
| 304 | double power = ((double)ChargingCurrent / MILLION) * |
| 305 | ((double)ChargingVoltage / MILLION); |
| 306 | if (MaxPower < power) { |
| 307 | props.maxChargingCurrent = ChargingCurrent; |
| 308 | props.maxChargingVoltage = ChargingVoltage; |
| 309 | MaxPower = power; |
Adrian Roos | d5fe667 | 2015-07-10 13:11:01 -0700 | [diff] [blame] | 310 | } |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 315 | logthis = !healthd_board_battery_update(&props); |
Todd Poynor | b45f1f5 | 2013-07-30 18:57:16 -0700 | [diff] [blame] | 316 | |
Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 317 | if (logthis) { |
| 318 | char dmesgline[256]; |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 319 | size_t len; |
Todd Poynor | c15e993 | 2013-10-22 18:21:27 -0700 | [diff] [blame] | 320 | if (props.batteryPresent) { |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 321 | snprintf(dmesgline, sizeof(dmesgline), |
Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 322 | "battery l=%d v=%d t=%s%d.%d h=%d st=%d", |
| 323 | props.batteryLevel, props.batteryVoltage, |
| 324 | props.batteryTemperature < 0 ? "-" : "", |
| 325 | abs(props.batteryTemperature / 10), |
| 326 | abs(props.batteryTemperature % 10), props.batteryHealth, |
| 327 | props.batteryStatus); |
Todd Poynor | c15e993 | 2013-10-22 18:21:27 -0700 | [diff] [blame] | 328 | |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 329 | len = strlen(dmesgline); |
Todd Poynor | c15e993 | 2013-10-22 18:21:27 -0700 | [diff] [blame] | 330 | if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 331 | len += snprintf(dmesgline + len, sizeof(dmesgline) - len, |
| 332 | " c=%d", props.batteryCurrent); |
| 333 | } |
Todd Poynor | c15e993 | 2013-10-22 18:21:27 -0700 | [diff] [blame] | 334 | |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 335 | if (!mHealthdConfig->batteryFullChargePath.isEmpty()) { |
| 336 | len += snprintf(dmesgline + len, sizeof(dmesgline) - len, |
| 337 | " fc=%d", props.batteryFullCharge); |
| 338 | } |
| 339 | |
| 340 | if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) { |
| 341 | len += snprintf(dmesgline + len, sizeof(dmesgline) - len, |
| 342 | " cc=%d", props.batteryCycleCount); |
Todd Poynor | c15e993 | 2013-10-22 18:21:27 -0700 | [diff] [blame] | 343 | } |
| 344 | } else { |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 345 | snprintf(dmesgline, sizeof(dmesgline), |
| 346 | "battery none"); |
Todd Poynor | 10b235e | 2013-08-07 15:25:14 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 349 | len = strlen(dmesgline); |
Mark Salyzyn | acb1ddf | 2015-07-23 09:22:50 -0700 | [diff] [blame] | 350 | snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s", |
| 351 | props.chargerAcOnline ? "a" : "", |
| 352 | props.chargerUsbOnline ? "u" : "", |
| 353 | props.chargerWirelessOnline ? "w" : ""); |
| 354 | |
Mark Salyzyn | acb1ddf | 2015-07-23 09:22:50 -0700 | [diff] [blame] | 355 | KLOG_WARNING(LOG_TAG, "%s\n", dmesgline); |
Todd Poynor | b45f1f5 | 2013-07-30 18:57:16 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Todd Poynor | c7464c9 | 2013-09-10 12:40:00 -0700 | [diff] [blame] | 358 | healthd_mode_ops->battery_update(&props); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 359 | return props.chargerAcOnline | props.chargerUsbOnline | |
| 360 | props.chargerWirelessOnline; |
| 361 | } |
| 362 | |
Yabin Cui | b0580d7 | 2016-02-19 18:03:23 -0800 | [diff] [blame] | 363 | int BatteryMonitor::getChargeStatus() { |
| 364 | int result = BATTERY_STATUS_UNKNOWN; |
| 365 | if (!mHealthdConfig->batteryStatusPath.isEmpty()) { |
| 366 | char buf[128]; |
| 367 | if (readFromFile(mHealthdConfig->batteryStatusPath, buf, sizeof(buf)) > 0) { |
| 368 | result = getBatteryStatus(buf); |
| 369 | } |
| 370 | } |
| 371 | return result; |
| 372 | } |
| 373 | |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 374 | status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { |
| 375 | status_t ret = BAD_VALUE; |
| 376 | |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 377 | val->valueInt64 = LONG_MIN; |
| 378 | |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 379 | switch(id) { |
| 380 | case BATTERY_PROP_CHARGE_COUNTER: |
| 381 | if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) { |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 382 | val->valueInt64 = |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 383 | getIntField(mHealthdConfig->batteryChargeCounterPath); |
| 384 | ret = NO_ERROR; |
| 385 | } else { |
| 386 | ret = NAME_NOT_FOUND; |
| 387 | } |
| 388 | break; |
| 389 | |
| 390 | case BATTERY_PROP_CURRENT_NOW: |
| 391 | if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 392 | val->valueInt64 = |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 393 | getIntField(mHealthdConfig->batteryCurrentNowPath); |
| 394 | ret = NO_ERROR; |
| 395 | } else { |
| 396 | ret = NAME_NOT_FOUND; |
| 397 | } |
| 398 | break; |
| 399 | |
Todd Poynor | bc10211 | 2013-08-27 18:11:49 -0700 | [diff] [blame] | 400 | case BATTERY_PROP_CURRENT_AVG: |
| 401 | if (!mHealthdConfig->batteryCurrentAvgPath.isEmpty()) { |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 402 | val->valueInt64 = |
Todd Poynor | bc10211 | 2013-08-27 18:11:49 -0700 | [diff] [blame] | 403 | getIntField(mHealthdConfig->batteryCurrentAvgPath); |
| 404 | ret = NO_ERROR; |
| 405 | } else { |
| 406 | ret = NAME_NOT_FOUND; |
| 407 | } |
| 408 | break; |
| 409 | |
Paul Lawrence | 347c8de | 2014-03-19 15:04:40 -0700 | [diff] [blame] | 410 | case BATTERY_PROP_CAPACITY: |
| 411 | if (!mHealthdConfig->batteryCapacityPath.isEmpty()) { |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 412 | val->valueInt64 = |
Paul Lawrence | 347c8de | 2014-03-19 15:04:40 -0700 | [diff] [blame] | 413 | getIntField(mHealthdConfig->batteryCapacityPath); |
| 414 | ret = NO_ERROR; |
| 415 | } else { |
| 416 | ret = NAME_NOT_FOUND; |
| 417 | } |
| 418 | break; |
| 419 | |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 420 | case BATTERY_PROP_ENERGY_COUNTER: |
Todd Poynor | e14b37e | 2014-05-20 13:54:40 -0700 | [diff] [blame] | 421 | if (mHealthdConfig->energyCounter) { |
| 422 | ret = mHealthdConfig->energyCounter(&val->valueInt64); |
| 423 | } else { |
| 424 | ret = NAME_NOT_FOUND; |
| 425 | } |
Todd Poynor | 8f132af | 2014-05-08 17:15:45 -0700 | [diff] [blame] | 426 | break; |
| 427 | |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 428 | default: |
| 429 | break; |
| 430 | } |
| 431 | |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 432 | return ret; |
| 433 | } |
| 434 | |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 435 | void BatteryMonitor::dumpState(int fd) { |
| 436 | int v; |
| 437 | char vs[128]; |
| 438 | |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 439 | snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d current_max: %d voltage_max: %d\n", |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 440 | props.chargerAcOnline, props.chargerUsbOnline, |
Badhri Jagan Sridharan | 40e1df4 | 2015-10-27 10:43:53 -0700 | [diff] [blame] | 441 | props.chargerWirelessOnline, props.maxChargingCurrent, |
| 442 | props.maxChargingVoltage); |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 443 | write(fd, vs, strlen(vs)); |
| 444 | snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n", |
| 445 | props.batteryStatus, props.batteryHealth, props.batteryPresent); |
| 446 | write(fd, vs, strlen(vs)); |
| 447 | snprintf(vs, sizeof(vs), "level: %d voltage: %d temp: %d\n", |
| 448 | props.batteryLevel, props.batteryVoltage, |
| 449 | props.batteryTemperature); |
| 450 | write(fd, vs, strlen(vs)); |
| 451 | |
| 452 | if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { |
| 453 | v = getIntField(mHealthdConfig->batteryCurrentNowPath); |
| 454 | snprintf(vs, sizeof(vs), "current now: %d\n", v); |
| 455 | write(fd, vs, strlen(vs)); |
| 456 | } |
| 457 | |
| 458 | if (!mHealthdConfig->batteryCurrentAvgPath.isEmpty()) { |
| 459 | v = getIntField(mHealthdConfig->batteryCurrentAvgPath); |
| 460 | snprintf(vs, sizeof(vs), "current avg: %d\n", v); |
| 461 | write(fd, vs, strlen(vs)); |
| 462 | } |
| 463 | |
| 464 | if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) { |
| 465 | v = getIntField(mHealthdConfig->batteryChargeCounterPath); |
| 466 | snprintf(vs, sizeof(vs), "charge counter: %d\n", v); |
| 467 | write(fd, vs, strlen(vs)); |
| 468 | } |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 469 | |
| 470 | if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { |
| 471 | snprintf(vs, sizeof(vs), "current now: %d\n", props.batteryCurrent); |
| 472 | write(fd, vs, strlen(vs)); |
| 473 | } |
| 474 | |
| 475 | if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) { |
| 476 | snprintf(vs, sizeof(vs), "cycle count: %d\n", props.batteryCycleCount); |
| 477 | write(fd, vs, strlen(vs)); |
| 478 | } |
| 479 | |
| 480 | if (!mHealthdConfig->batteryFullChargePath.isEmpty()) { |
| 481 | snprintf(vs, sizeof(vs), "Full charge: %d\n", props.batteryFullCharge); |
| 482 | write(fd, vs, strlen(vs)); |
| 483 | } |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Todd Poynor | c7464c9 | 2013-09-10 12:40:00 -0700 | [diff] [blame] | 486 | void BatteryMonitor::init(struct healthd_config *hc) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 487 | String8 path; |
Todd Poynor | 3db03a5 | 2014-05-21 16:28:13 -0700 | [diff] [blame] | 488 | char pval[PROPERTY_VALUE_MAX]; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 489 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 490 | mHealthdConfig = hc; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 491 | DIR* dir = opendir(POWER_SUPPLY_SYSFS_PATH); |
| 492 | if (dir == NULL) { |
| 493 | KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH); |
| 494 | } else { |
| 495 | struct dirent* entry; |
| 496 | |
| 497 | while ((entry = readdir(dir))) { |
| 498 | const char* name = entry->d_name; |
| 499 | |
| 500 | if (!strcmp(name, ".") || !strcmp(name, "..")) |
| 501 | continue; |
| 502 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 503 | // Look for "type" file in each subdirectory |
| 504 | path.clear(); |
| 505 | path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name); |
| 506 | switch(readPowerSupplyType(path)) { |
| 507 | case ANDROID_POWER_SUPPLY_TYPE_AC: |
| 508 | case ANDROID_POWER_SUPPLY_TYPE_USB: |
| 509 | case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: |
| 510 | path.clear(); |
| 511 | path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name); |
| 512 | if (access(path.string(), R_OK) == 0) |
| 513 | mChargerNames.add(String8(name)); |
| 514 | break; |
| 515 | |
| 516 | case ANDROID_POWER_SUPPLY_TYPE_BATTERY: |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 517 | mBatteryDevicePresent = true; |
| 518 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 519 | if (mHealthdConfig->batteryStatusPath.isEmpty()) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 520 | path.clear(); |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 521 | path.appendFormat("%s/%s/status", POWER_SUPPLY_SYSFS_PATH, |
| 522 | name); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 523 | if (access(path, R_OK) == 0) |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 524 | mHealthdConfig->batteryStatusPath = path; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 527 | if (mHealthdConfig->batteryHealthPath.isEmpty()) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 528 | path.clear(); |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 529 | path.appendFormat("%s/%s/health", POWER_SUPPLY_SYSFS_PATH, |
| 530 | name); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 531 | if (access(path, R_OK) == 0) |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 532 | mHealthdConfig->batteryHealthPath = path; |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 535 | if (mHealthdConfig->batteryPresentPath.isEmpty()) { |
| 536 | path.clear(); |
| 537 | path.appendFormat("%s/%s/present", POWER_SUPPLY_SYSFS_PATH, |
| 538 | name); |
| 539 | if (access(path, R_OK) == 0) |
| 540 | mHealthdConfig->batteryPresentPath = path; |
| 541 | } |
| 542 | |
| 543 | if (mHealthdConfig->batteryCapacityPath.isEmpty()) { |
| 544 | path.clear(); |
| 545 | path.appendFormat("%s/%s/capacity", POWER_SUPPLY_SYSFS_PATH, |
| 546 | name); |
| 547 | if (access(path, R_OK) == 0) |
| 548 | mHealthdConfig->batteryCapacityPath = path; |
| 549 | } |
| 550 | |
| 551 | if (mHealthdConfig->batteryVoltagePath.isEmpty()) { |
| 552 | path.clear(); |
| 553 | path.appendFormat("%s/%s/voltage_now", |
| 554 | POWER_SUPPLY_SYSFS_PATH, name); |
| 555 | if (access(path, R_OK) == 0) { |
| 556 | mHealthdConfig->batteryVoltagePath = path; |
| 557 | } else { |
| 558 | path.clear(); |
| 559 | path.appendFormat("%s/%s/batt_vol", |
| 560 | POWER_SUPPLY_SYSFS_PATH, name); |
| 561 | if (access(path, R_OK) == 0) |
| 562 | mHealthdConfig->batteryVoltagePath = path; |
| 563 | } |
| 564 | } |
| 565 | |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 566 | if (mHealthdConfig->batteryFullChargePath.isEmpty()) { |
| 567 | path.clear(); |
| 568 | path.appendFormat("%s/%s/charge_full", |
| 569 | POWER_SUPPLY_SYSFS_PATH, name); |
| 570 | if (access(path, R_OK) == 0) |
| 571 | mHealthdConfig->batteryFullChargePath = path; |
| 572 | } |
| 573 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 574 | if (mHealthdConfig->batteryCurrentNowPath.isEmpty()) { |
| 575 | path.clear(); |
| 576 | path.appendFormat("%s/%s/current_now", |
| 577 | POWER_SUPPLY_SYSFS_PATH, name); |
| 578 | if (access(path, R_OK) == 0) |
| 579 | mHealthdConfig->batteryCurrentNowPath = path; |
| 580 | } |
| 581 | |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 582 | if (mHealthdConfig->batteryCycleCountPath.isEmpty()) { |
| 583 | path.clear(); |
| 584 | path.appendFormat("%s/%s/cycle_count", |
| 585 | POWER_SUPPLY_SYSFS_PATH, name); |
| 586 | if (access(path, R_OK) == 0) |
| 587 | mHealthdConfig->batteryCycleCountPath = path; |
| 588 | } |
| 589 | |
Todd Poynor | bc10211 | 2013-08-27 18:11:49 -0700 | [diff] [blame] | 590 | if (mHealthdConfig->batteryCurrentAvgPath.isEmpty()) { |
| 591 | path.clear(); |
| 592 | path.appendFormat("%s/%s/current_avg", |
| 593 | POWER_SUPPLY_SYSFS_PATH, name); |
| 594 | if (access(path, R_OK) == 0) |
| 595 | mHealthdConfig->batteryCurrentAvgPath = path; |
| 596 | } |
| 597 | |
Todd Poynor | f5d3012 | 2013-08-12 17:03:35 -0700 | [diff] [blame] | 598 | if (mHealthdConfig->batteryChargeCounterPath.isEmpty()) { |
| 599 | path.clear(); |
| 600 | path.appendFormat("%s/%s/charge_counter", |
| 601 | POWER_SUPPLY_SYSFS_PATH, name); |
| 602 | if (access(path, R_OK) == 0) |
| 603 | mHealthdConfig->batteryChargeCounterPath = path; |
| 604 | } |
| 605 | |
| 606 | if (mHealthdConfig->batteryTemperaturePath.isEmpty()) { |
| 607 | path.clear(); |
| 608 | path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH, |
| 609 | name); |
| 610 | if (access(path, R_OK) == 0) { |
| 611 | mHealthdConfig->batteryTemperaturePath = path; |
| 612 | } else { |
| 613 | path.clear(); |
| 614 | path.appendFormat("%s/%s/batt_temp", |
| 615 | POWER_SUPPLY_SYSFS_PATH, name); |
| 616 | if (access(path, R_OK) == 0) |
| 617 | mHealthdConfig->batteryTemperaturePath = path; |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | if (mHealthdConfig->batteryTechnologyPath.isEmpty()) { |
| 622 | path.clear(); |
| 623 | path.appendFormat("%s/%s/technology", |
| 624 | POWER_SUPPLY_SYSFS_PATH, name); |
| 625 | if (access(path, R_OK) == 0) |
| 626 | mHealthdConfig->batteryTechnologyPath = path; |
| 627 | } |
| 628 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 629 | break; |
| 630 | |
| 631 | case ANDROID_POWER_SUPPLY_TYPE_UNKNOWN: |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | closedir(dir); |
| 636 | } |
| 637 | |
Ian Pedowitz | 585ab65 | 2015-10-12 19:01:00 -0700 | [diff] [blame] | 638 | // This indicates that there is no charger driver registered. |
| 639 | // Typically the case for devices which do not have a battery and |
| 640 | // and are always plugged into AC mains. |
Ruchi Kandoi | f18ec9f | 2015-09-28 13:35:59 -0700 | [diff] [blame] | 641 | if (!mChargerNames.size()) { |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 642 | KLOG_ERROR(LOG_TAG, "No charger supplies found\n"); |
Ruchi Kandoi | f18ec9f | 2015-09-28 13:35:59 -0700 | [diff] [blame] | 643 | mBatteryFixedCapacity = ALWAYS_PLUGGED_CAPACITY; |
| 644 | mBatteryFixedTemperature = FAKE_BATTERY_TEMPERATURE; |
| 645 | mAlwaysPluggedDevice = true; |
| 646 | } |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 647 | if (!mBatteryDevicePresent) { |
Todd Poynor | ebeb0c0 | 2014-09-23 14:54:24 -0700 | [diff] [blame] | 648 | KLOG_WARNING(LOG_TAG, "No battery devices found\n"); |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 649 | hc->periodic_chores_interval_fast = -1; |
| 650 | hc->periodic_chores_interval_slow = -1; |
| 651 | } else { |
| 652 | if (mHealthdConfig->batteryStatusPath.isEmpty()) |
| 653 | KLOG_WARNING(LOG_TAG, "BatteryStatusPath not found\n"); |
| 654 | if (mHealthdConfig->batteryHealthPath.isEmpty()) |
| 655 | KLOG_WARNING(LOG_TAG, "BatteryHealthPath not found\n"); |
| 656 | if (mHealthdConfig->batteryPresentPath.isEmpty()) |
| 657 | KLOG_WARNING(LOG_TAG, "BatteryPresentPath not found\n"); |
| 658 | if (mHealthdConfig->batteryCapacityPath.isEmpty()) |
| 659 | KLOG_WARNING(LOG_TAG, "BatteryCapacityPath not found\n"); |
| 660 | if (mHealthdConfig->batteryVoltagePath.isEmpty()) |
| 661 | KLOG_WARNING(LOG_TAG, "BatteryVoltagePath not found\n"); |
| 662 | if (mHealthdConfig->batteryTemperaturePath.isEmpty()) |
| 663 | KLOG_WARNING(LOG_TAG, "BatteryTemperaturePath not found\n"); |
| 664 | if (mHealthdConfig->batteryTechnologyPath.isEmpty()) |
| 665 | KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n"); |
Ruchi Kandoi | f18ec9f | 2015-09-28 13:35:59 -0700 | [diff] [blame] | 666 | if (mHealthdConfig->batteryCurrentNowPath.isEmpty()) |
Ruchi Kandoi | cc33880 | 2015-08-24 13:01:16 -0700 | [diff] [blame] | 667 | KLOG_WARNING(LOG_TAG, "BatteryCurrentNowPath not found\n"); |
| 668 | if (mHealthdConfig->batteryFullChargePath.isEmpty()) |
| 669 | KLOG_WARNING(LOG_TAG, "BatteryFullChargePath not found\n"); |
| 670 | if (mHealthdConfig->batteryCycleCountPath.isEmpty()) |
| 671 | KLOG_WARNING(LOG_TAG, "BatteryCycleCountPath not found\n"); |
Todd Poynor | 6dcc45e | 2013-10-21 20:26:25 -0700 | [diff] [blame] | 672 | } |
Todd Poynor | 3db03a5 | 2014-05-21 16:28:13 -0700 | [diff] [blame] | 673 | |
Ruchi Kandoi | a78fc23 | 2014-07-10 15:06:21 -0700 | [diff] [blame] | 674 | if (property_get("ro.boot.fake_battery", pval, NULL) > 0 |
| 675 | && strtol(pval, NULL, 10) != 0) { |
| 676 | mBatteryFixedCapacity = FAKE_BATTERY_CAPACITY; |
| 677 | mBatteryFixedTemperature = FAKE_BATTERY_TEMPERATURE; |
| 678 | } |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | }; // namespace android |