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