blob: 1ee33a18752c2b9faff6e3d3087a383a8280b3e1 [file] [log] [blame]
Todd Poynor752faf22013-06-12 13:25:59 -07001/*
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
Todd Poynor10b235e2013-08-07 15:25:14 -070019#include "healthd.h"
Todd Poynor752faf22013-06-12 13:25:59 -070020#include "BatteryMonitor.h"
Todd Poynor752faf22013-06-12 13:25:59 -070021
22#include <dirent.h>
23#include <errno.h>
24#include <fcntl.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <unistd.h>
28#include <batteryservice/BatteryService.h>
29#include <cutils/klog.h>
Todd Poynor3db03a52014-05-21 16:28:13 -070030#include <cutils/properties.h>
Todd Poynore14b37e2014-05-20 13:54:40 -070031#include <sys/types.h>
Todd Poynorc133b712013-08-14 17:39:13 -070032#include <utils/Errors.h>
Todd Poynor752faf22013-06-12 13:25:59 -070033#include <utils/String8.h>
34#include <utils/Vector.h>
35
36#define POWER_SUPPLY_SUBSYSTEM "power_supply"
37#define POWER_SUPPLY_SYSFS_PATH "/sys/class/" POWER_SUPPLY_SUBSYSTEM
38
39namespace android {
40
41struct sysfsStringEnumMap {
Mark Salyzyn6f5b47f2014-05-15 15:00:59 -070042 const char* s;
Todd Poynor752faf22013-06-12 13:25:59 -070043 int val;
44};
45
46static int mapSysfsString(const char* str,
47 struct sysfsStringEnumMap map[]) {
48 for (int i = 0; map[i].s; i++)
49 if (!strcmp(str, map[i].s))
50 return map[i].val;
51
52 return -1;
53}
54
55int BatteryMonitor::getBatteryStatus(const char* status) {
56 int ret;
57 struct sysfsStringEnumMap batteryStatusMap[] = {
58 { "Unknown", BATTERY_STATUS_UNKNOWN },
59 { "Charging", BATTERY_STATUS_CHARGING },
60 { "Discharging", BATTERY_STATUS_DISCHARGING },
61 { "Not charging", BATTERY_STATUS_NOT_CHARGING },
62 { "Full", BATTERY_STATUS_FULL },
63 { NULL, 0 },
64 };
65
66 ret = mapSysfsString(status, batteryStatusMap);
67 if (ret < 0) {
68 KLOG_WARNING(LOG_TAG, "Unknown battery status '%s'\n", status);
69 ret = BATTERY_STATUS_UNKNOWN;
70 }
71
72 return ret;
73}
74
75int BatteryMonitor::getBatteryHealth(const char* status) {
76 int ret;
77 struct sysfsStringEnumMap batteryHealthMap[] = {
78 { "Unknown", BATTERY_HEALTH_UNKNOWN },
79 { "Good", BATTERY_HEALTH_GOOD },
80 { "Overheat", BATTERY_HEALTH_OVERHEAT },
81 { "Dead", BATTERY_HEALTH_DEAD },
82 { "Over voltage", BATTERY_HEALTH_OVER_VOLTAGE },
83 { "Unspecified failure", BATTERY_HEALTH_UNSPECIFIED_FAILURE },
84 { "Cold", BATTERY_HEALTH_COLD },
85 { NULL, 0 },
86 };
87
88 ret = mapSysfsString(status, batteryHealthMap);
89 if (ret < 0) {
90 KLOG_WARNING(LOG_TAG, "Unknown battery health '%s'\n", status);
91 ret = BATTERY_HEALTH_UNKNOWN;
92 }
93
94 return ret;
95}
96
97int BatteryMonitor::readFromFile(const String8& path, char* buf, size_t size) {
98 char *cp = NULL;
99
100 if (path.isEmpty())
101 return -1;
102 int fd = open(path.string(), O_RDONLY, 0);
103 if (fd == -1) {
104 KLOG_ERROR(LOG_TAG, "Could not open '%s'\n", path.string());
105 return -1;
106 }
107
108 ssize_t count = TEMP_FAILURE_RETRY(read(fd, buf, size));
109 if (count > 0)
110 cp = (char *)memrchr(buf, '\n', count);
111
112 if (cp)
113 *cp = '\0';
114 else
115 buf[0] = '\0';
116
117 close(fd);
118 return count;
119}
120
121BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String8& path) {
122 const int SIZE = 128;
123 char buf[SIZE];
124 int length = readFromFile(path, buf, SIZE);
125 BatteryMonitor::PowerSupplyType ret;
126 struct sysfsStringEnumMap supplyTypeMap[] = {
127 { "Unknown", ANDROID_POWER_SUPPLY_TYPE_UNKNOWN },
128 { "Battery", ANDROID_POWER_SUPPLY_TYPE_BATTERY },
129 { "UPS", ANDROID_POWER_SUPPLY_TYPE_AC },
130 { "Mains", ANDROID_POWER_SUPPLY_TYPE_AC },
131 { "USB", ANDROID_POWER_SUPPLY_TYPE_USB },
132 { "USB_DCP", ANDROID_POWER_SUPPLY_TYPE_AC },
133 { "USB_CDP", ANDROID_POWER_SUPPLY_TYPE_AC },
134 { "USB_ACA", ANDROID_POWER_SUPPLY_TYPE_AC },
135 { "Wireless", ANDROID_POWER_SUPPLY_TYPE_WIRELESS },
136 { NULL, 0 },
137 };
138
139 if (length <= 0)
140 return ANDROID_POWER_SUPPLY_TYPE_UNKNOWN;
141
142 ret = (BatteryMonitor::PowerSupplyType)mapSysfsString(buf, supplyTypeMap);
143 if (ret < 0)
144 ret = ANDROID_POWER_SUPPLY_TYPE_UNKNOWN;
145
146 return ret;
147}
148
149bool BatteryMonitor::getBooleanField(const String8& path) {
150 const int SIZE = 16;
151 char buf[SIZE];
152
153 bool value = false;
154 if (readFromFile(path, buf, SIZE) > 0) {
155 if (buf[0] != '0') {
156 value = true;
157 }
158 }
159
160 return value;
161}
162
163int BatteryMonitor::getIntField(const String8& path) {
164 const int SIZE = 128;
165 char buf[SIZE];
166
167 int value = 0;
168 if (readFromFile(path, buf, SIZE) > 0) {
169 value = strtol(buf, NULL, 0);
170 }
171 return value;
172}
173
174bool BatteryMonitor::update(void) {
Todd Poynor10b235e2013-08-07 15:25:14 -0700175 bool logthis;
Todd Poynor752faf22013-06-12 13:25:59 -0700176
177 props.chargerAcOnline = false;
178 props.chargerUsbOnline = false;
179 props.chargerWirelessOnline = false;
180 props.batteryStatus = BATTERY_STATUS_UNKNOWN;
181 props.batteryHealth = BATTERY_HEALTH_UNKNOWN;
182
Todd Poynorf5d30122013-08-12 17:03:35 -0700183 if (!mHealthdConfig->batteryPresentPath.isEmpty())
184 props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath);
Todd Poynor752faf22013-06-12 13:25:59 -0700185 else
Todd Poynor6dcc45e2013-10-21 20:26:25 -0700186 props.batteryPresent = mBatteryDevicePresent;
Todd Poynor752faf22013-06-12 13:25:59 -0700187
Todd Poynor3db03a52014-05-21 16:28:13 -0700188 props.batteryLevel = mBatteryFixedCapacity ?
189 mBatteryFixedCapacity :
190 getIntField(mHealthdConfig->batteryCapacityPath);
Todd Poynorf5d30122013-08-12 17:03:35 -0700191 props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000;
Todd Poynorb45f1f52013-07-30 18:57:16 -0700192
Todd Poynor3db03a52014-05-21 16:28:13 -0700193 props.batteryTemperature = mBatteryFixedTemperature ?
194 mBatteryFixedTemperature :
195 getIntField(mHealthdConfig->batteryTemperaturePath);
Todd Poynor752faf22013-06-12 13:25:59 -0700196
197 const int SIZE = 128;
198 char buf[SIZE];
199 String8 btech;
200
Todd Poynorf5d30122013-08-12 17:03:35 -0700201 if (readFromFile(mHealthdConfig->batteryStatusPath, buf, SIZE) > 0)
Todd Poynor752faf22013-06-12 13:25:59 -0700202 props.batteryStatus = getBatteryStatus(buf);
203
Todd Poynorf5d30122013-08-12 17:03:35 -0700204 if (readFromFile(mHealthdConfig->batteryHealthPath, buf, SIZE) > 0)
Todd Poynor752faf22013-06-12 13:25:59 -0700205 props.batteryHealth = getBatteryHealth(buf);
206
Todd Poynorf5d30122013-08-12 17:03:35 -0700207 if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0)
Todd Poynor752faf22013-06-12 13:25:59 -0700208 props.batteryTechnology = String8(buf);
209
210 unsigned int i;
211
212 for (i = 0; i < mChargerNames.size(); i++) {
213 String8 path;
214 path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH,
215 mChargerNames[i].string());
216
217 if (readFromFile(path, buf, SIZE) > 0) {
218 if (buf[0] != '0') {
219 path.clear();
220 path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH,
221 mChargerNames[i].string());
222 switch(readPowerSupplyType(path)) {
223 case ANDROID_POWER_SUPPLY_TYPE_AC:
224 props.chargerAcOnline = true;
225 break;
226 case ANDROID_POWER_SUPPLY_TYPE_USB:
227 props.chargerUsbOnline = true;
228 break;
229 case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
230 props.chargerWirelessOnline = true;
231 break;
232 default:
233 KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n",
234 mChargerNames[i].string());
235 }
236 }
237 }
238 }
239
Todd Poynor10b235e2013-08-07 15:25:14 -0700240 logthis = !healthd_board_battery_update(&props);
Todd Poynorb45f1f52013-07-30 18:57:16 -0700241
Todd Poynor10b235e2013-08-07 15:25:14 -0700242 if (logthis) {
243 char dmesgline[256];
Todd Poynor6dcc45e2013-10-21 20:26:25 -0700244
Todd Poynorc15e9932013-10-22 18:21:27 -0700245 if (props.batteryPresent) {
Todd Poynor6dcc45e2013-10-21 20:26:25 -0700246 snprintf(dmesgline, sizeof(dmesgline),
Todd Poynor10b235e2013-08-07 15:25:14 -0700247 "battery l=%d v=%d t=%s%d.%d h=%d st=%d",
248 props.batteryLevel, props.batteryVoltage,
249 props.batteryTemperature < 0 ? "-" : "",
250 abs(props.batteryTemperature / 10),
251 abs(props.batteryTemperature % 10), props.batteryHealth,
252 props.batteryStatus);
Todd Poynorc15e9932013-10-22 18:21:27 -0700253
254 if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
255 int c = getIntField(mHealthdConfig->batteryCurrentNowPath);
256 char b[20];
257
258 snprintf(b, sizeof(b), " c=%d", c / 1000);
259 strlcat(dmesgline, b, sizeof(dmesgline));
260 }
261 } else {
Todd Poynor6dcc45e2013-10-21 20:26:25 -0700262 snprintf(dmesgline, sizeof(dmesgline),
263 "battery none");
Todd Poynor10b235e2013-08-07 15:25:14 -0700264 }
265
266 KLOG_INFO(LOG_TAG, "%s chg=%s%s%s\n", dmesgline,
267 props.chargerAcOnline ? "a" : "",
268 props.chargerUsbOnline ? "u" : "",
269 props.chargerWirelessOnline ? "w" : "");
Todd Poynorb45f1f52013-07-30 18:57:16 -0700270 }
271
Todd Poynorc7464c92013-09-10 12:40:00 -0700272 healthd_mode_ops->battery_update(&props);
Todd Poynor752faf22013-06-12 13:25:59 -0700273 return props.chargerAcOnline | props.chargerUsbOnline |
274 props.chargerWirelessOnline;
275}
276
Todd Poynorc133b712013-08-14 17:39:13 -0700277status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) {
278 status_t ret = BAD_VALUE;
279
Todd Poynor8f132af2014-05-08 17:15:45 -0700280 val->valueInt64 = LONG_MIN;
281
Todd Poynorc133b712013-08-14 17:39:13 -0700282 switch(id) {
283 case BATTERY_PROP_CHARGE_COUNTER:
284 if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) {
Todd Poynor8f132af2014-05-08 17:15:45 -0700285 val->valueInt64 =
Todd Poynorc133b712013-08-14 17:39:13 -0700286 getIntField(mHealthdConfig->batteryChargeCounterPath);
287 ret = NO_ERROR;
288 } else {
289 ret = NAME_NOT_FOUND;
290 }
291 break;
292
293 case BATTERY_PROP_CURRENT_NOW:
294 if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
Todd Poynor8f132af2014-05-08 17:15:45 -0700295 val->valueInt64 =
Todd Poynorc133b712013-08-14 17:39:13 -0700296 getIntField(mHealthdConfig->batteryCurrentNowPath);
297 ret = NO_ERROR;
298 } else {
299 ret = NAME_NOT_FOUND;
300 }
301 break;
302
Todd Poynorbc102112013-08-27 18:11:49 -0700303 case BATTERY_PROP_CURRENT_AVG:
304 if (!mHealthdConfig->batteryCurrentAvgPath.isEmpty()) {
Todd Poynor8f132af2014-05-08 17:15:45 -0700305 val->valueInt64 =
Todd Poynorbc102112013-08-27 18:11:49 -0700306 getIntField(mHealthdConfig->batteryCurrentAvgPath);
307 ret = NO_ERROR;
308 } else {
309 ret = NAME_NOT_FOUND;
310 }
311 break;
312
Paul Lawrence347c8de2014-03-19 15:04:40 -0700313 case BATTERY_PROP_CAPACITY:
314 if (!mHealthdConfig->batteryCapacityPath.isEmpty()) {
Todd Poynor8f132af2014-05-08 17:15:45 -0700315 val->valueInt64 =
Paul Lawrence347c8de2014-03-19 15:04:40 -0700316 getIntField(mHealthdConfig->batteryCapacityPath);
317 ret = NO_ERROR;
318 } else {
319 ret = NAME_NOT_FOUND;
320 }
321 break;
322
Todd Poynor8f132af2014-05-08 17:15:45 -0700323 case BATTERY_PROP_ENERGY_COUNTER:
Todd Poynore14b37e2014-05-20 13:54:40 -0700324 if (mHealthdConfig->energyCounter) {
325 ret = mHealthdConfig->energyCounter(&val->valueInt64);
326 } else {
327 ret = NAME_NOT_FOUND;
328 }
Todd Poynor8f132af2014-05-08 17:15:45 -0700329 break;
330
Todd Poynorc133b712013-08-14 17:39:13 -0700331 default:
332 break;
333 }
334
Todd Poynorc133b712013-08-14 17:39:13 -0700335 return ret;
336}
337
Todd Poynor020369d2013-09-18 20:09:33 -0700338void BatteryMonitor::dumpState(int fd) {
339 int v;
340 char vs[128];
341
342 snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d\n",
343 props.chargerAcOnline, props.chargerUsbOnline,
344 props.chargerWirelessOnline);
345 write(fd, vs, strlen(vs));
346 snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n",
347 props.batteryStatus, props.batteryHealth, props.batteryPresent);
348 write(fd, vs, strlen(vs));
349 snprintf(vs, sizeof(vs), "level: %d voltage: %d temp: %d\n",
350 props.batteryLevel, props.batteryVoltage,
351 props.batteryTemperature);
352 write(fd, vs, strlen(vs));
353
354 if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
355 v = getIntField(mHealthdConfig->batteryCurrentNowPath);
356 snprintf(vs, sizeof(vs), "current now: %d\n", v);
357 write(fd, vs, strlen(vs));
358 }
359
360 if (!mHealthdConfig->batteryCurrentAvgPath.isEmpty()) {
361 v = getIntField(mHealthdConfig->batteryCurrentAvgPath);
362 snprintf(vs, sizeof(vs), "current avg: %d\n", v);
363 write(fd, vs, strlen(vs));
364 }
365
366 if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) {
367 v = getIntField(mHealthdConfig->batteryChargeCounterPath);
368 snprintf(vs, sizeof(vs), "charge counter: %d\n", v);
369 write(fd, vs, strlen(vs));
370 }
371}
372
Todd Poynorc7464c92013-09-10 12:40:00 -0700373void BatteryMonitor::init(struct healthd_config *hc) {
Todd Poynor752faf22013-06-12 13:25:59 -0700374 String8 path;
Todd Poynor3db03a52014-05-21 16:28:13 -0700375 char pval[PROPERTY_VALUE_MAX];
Todd Poynor752faf22013-06-12 13:25:59 -0700376
Todd Poynorf5d30122013-08-12 17:03:35 -0700377 mHealthdConfig = hc;
Todd Poynor752faf22013-06-12 13:25:59 -0700378 DIR* dir = opendir(POWER_SUPPLY_SYSFS_PATH);
379 if (dir == NULL) {
380 KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH);
381 } else {
382 struct dirent* entry;
383
384 while ((entry = readdir(dir))) {
385 const char* name = entry->d_name;
386
387 if (!strcmp(name, ".") || !strcmp(name, ".."))
388 continue;
389
390 char buf[20];
391 // Look for "type" file in each subdirectory
392 path.clear();
393 path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name);
394 switch(readPowerSupplyType(path)) {
395 case ANDROID_POWER_SUPPLY_TYPE_AC:
396 case ANDROID_POWER_SUPPLY_TYPE_USB:
397 case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
398 path.clear();
399 path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
400 if (access(path.string(), R_OK) == 0)
401 mChargerNames.add(String8(name));
402 break;
403
404 case ANDROID_POWER_SUPPLY_TYPE_BATTERY:
Todd Poynor6dcc45e2013-10-21 20:26:25 -0700405 mBatteryDevicePresent = true;
406
Todd Poynorf5d30122013-08-12 17:03:35 -0700407 if (mHealthdConfig->batteryStatusPath.isEmpty()) {
Todd Poynor752faf22013-06-12 13:25:59 -0700408 path.clear();
Todd Poynorf5d30122013-08-12 17:03:35 -0700409 path.appendFormat("%s/%s/status", POWER_SUPPLY_SYSFS_PATH,
410 name);
Todd Poynor752faf22013-06-12 13:25:59 -0700411 if (access(path, R_OK) == 0)
Todd Poynorf5d30122013-08-12 17:03:35 -0700412 mHealthdConfig->batteryStatusPath = path;
Todd Poynor752faf22013-06-12 13:25:59 -0700413 }
414
Todd Poynorf5d30122013-08-12 17:03:35 -0700415 if (mHealthdConfig->batteryHealthPath.isEmpty()) {
Todd Poynor752faf22013-06-12 13:25:59 -0700416 path.clear();
Todd Poynorf5d30122013-08-12 17:03:35 -0700417 path.appendFormat("%s/%s/health", POWER_SUPPLY_SYSFS_PATH,
418 name);
Todd Poynor752faf22013-06-12 13:25:59 -0700419 if (access(path, R_OK) == 0)
Todd Poynorf5d30122013-08-12 17:03:35 -0700420 mHealthdConfig->batteryHealthPath = path;
Todd Poynor752faf22013-06-12 13:25:59 -0700421 }
422
Todd Poynorf5d30122013-08-12 17:03:35 -0700423 if (mHealthdConfig->batteryPresentPath.isEmpty()) {
424 path.clear();
425 path.appendFormat("%s/%s/present", POWER_SUPPLY_SYSFS_PATH,
426 name);
427 if (access(path, R_OK) == 0)
428 mHealthdConfig->batteryPresentPath = path;
429 }
430
431 if (mHealthdConfig->batteryCapacityPath.isEmpty()) {
432 path.clear();
433 path.appendFormat("%s/%s/capacity", POWER_SUPPLY_SYSFS_PATH,
434 name);
435 if (access(path, R_OK) == 0)
436 mHealthdConfig->batteryCapacityPath = path;
437 }
438
439 if (mHealthdConfig->batteryVoltagePath.isEmpty()) {
440 path.clear();
441 path.appendFormat("%s/%s/voltage_now",
442 POWER_SUPPLY_SYSFS_PATH, name);
443 if (access(path, R_OK) == 0) {
444 mHealthdConfig->batteryVoltagePath = path;
445 } else {
446 path.clear();
447 path.appendFormat("%s/%s/batt_vol",
448 POWER_SUPPLY_SYSFS_PATH, name);
449 if (access(path, R_OK) == 0)
450 mHealthdConfig->batteryVoltagePath = path;
451 }
452 }
453
454 if (mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
455 path.clear();
456 path.appendFormat("%s/%s/current_now",
457 POWER_SUPPLY_SYSFS_PATH, name);
458 if (access(path, R_OK) == 0)
459 mHealthdConfig->batteryCurrentNowPath = path;
460 }
461
Todd Poynorbc102112013-08-27 18:11:49 -0700462 if (mHealthdConfig->batteryCurrentAvgPath.isEmpty()) {
463 path.clear();
464 path.appendFormat("%s/%s/current_avg",
465 POWER_SUPPLY_SYSFS_PATH, name);
466 if (access(path, R_OK) == 0)
467 mHealthdConfig->batteryCurrentAvgPath = path;
468 }
469
Todd Poynorf5d30122013-08-12 17:03:35 -0700470 if (mHealthdConfig->batteryChargeCounterPath.isEmpty()) {
471 path.clear();
472 path.appendFormat("%s/%s/charge_counter",
473 POWER_SUPPLY_SYSFS_PATH, name);
474 if (access(path, R_OK) == 0)
475 mHealthdConfig->batteryChargeCounterPath = path;
476 }
477
478 if (mHealthdConfig->batteryTemperaturePath.isEmpty()) {
479 path.clear();
480 path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH,
481 name);
482 if (access(path, R_OK) == 0) {
483 mHealthdConfig->batteryTemperaturePath = path;
484 } else {
485 path.clear();
486 path.appendFormat("%s/%s/batt_temp",
487 POWER_SUPPLY_SYSFS_PATH, name);
488 if (access(path, R_OK) == 0)
489 mHealthdConfig->batteryTemperaturePath = path;
490 }
491 }
492
493 if (mHealthdConfig->batteryTechnologyPath.isEmpty()) {
494 path.clear();
495 path.appendFormat("%s/%s/technology",
496 POWER_SUPPLY_SYSFS_PATH, name);
497 if (access(path, R_OK) == 0)
498 mHealthdConfig->batteryTechnologyPath = path;
499 }
500
Todd Poynor752faf22013-06-12 13:25:59 -0700501 break;
502
503 case ANDROID_POWER_SUPPLY_TYPE_UNKNOWN:
504 break;
505 }
506 }
507 closedir(dir);
508 }
509
510 if (!mChargerNames.size())
511 KLOG_ERROR(LOG_TAG, "No charger supplies found\n");
Todd Poynor6dcc45e2013-10-21 20:26:25 -0700512 if (!mBatteryDevicePresent) {
513 KLOG_INFO(LOG_TAG, "No battery devices found\n");
514 hc->periodic_chores_interval_fast = -1;
515 hc->periodic_chores_interval_slow = -1;
516 } else {
517 if (mHealthdConfig->batteryStatusPath.isEmpty())
518 KLOG_WARNING(LOG_TAG, "BatteryStatusPath not found\n");
519 if (mHealthdConfig->batteryHealthPath.isEmpty())
520 KLOG_WARNING(LOG_TAG, "BatteryHealthPath not found\n");
521 if (mHealthdConfig->batteryPresentPath.isEmpty())
522 KLOG_WARNING(LOG_TAG, "BatteryPresentPath not found\n");
523 if (mHealthdConfig->batteryCapacityPath.isEmpty())
524 KLOG_WARNING(LOG_TAG, "BatteryCapacityPath not found\n");
525 if (mHealthdConfig->batteryVoltagePath.isEmpty())
526 KLOG_WARNING(LOG_TAG, "BatteryVoltagePath not found\n");
527 if (mHealthdConfig->batteryTemperaturePath.isEmpty())
528 KLOG_WARNING(LOG_TAG, "BatteryTemperaturePath not found\n");
529 if (mHealthdConfig->batteryTechnologyPath.isEmpty())
530 KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n");
531 }
Todd Poynor3db03a52014-05-21 16:28:13 -0700532
533 if (property_get("persist.sys.battery.capacity", pval, NULL) > 0)
534 mBatteryFixedCapacity = (int) strtol(pval, NULL, 10);
535
536 if (property_get("persist.sys.battery.temperature", pval, NULL) > 0)
537 mBatteryFixedTemperature = (int) strtol(pval, NULL, 10);
Todd Poynor752faf22013-06-12 13:25:59 -0700538}
539
540}; // namespace android