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