Skip to content

Commit f8aa10a

Browse files
xyyxmracar07
authored andcommitted
core: Lockscreen Charging info (1/3)
Change-Id: I4b7c41f3e9360aa9ffe5330c3b193619ffaf894b
1 parent b91788b commit f8aa10a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

healthd/BatteryMonitor.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
#define POWER_SUPPLY_SUBSYSTEM "power_supply"
4444
#define POWER_SUPPLY_SYSFS_PATH "/sys/class/" POWER_SUPPLY_SUBSYSTEM
45+
#define SYSFS_BATTERY_CURRENT "/sys/class/power_supply/battery/current_now"
46+
#define SYSFS_BATTERY_VOLTAGE "/sys/class/power_supply/battery/voltage_now"
4547
#define FAKE_BATTERY_CAPACITY 42
4648
#define FAKE_BATTERY_TEMPERATURE 424
4749
#define MILLION 1.0e6
@@ -300,19 +302,13 @@ bool BatteryMonitor::update(void) {
300302
KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n",
301303
mChargerNames[i].string());
302304
}
303-
path.clear();
304-
path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH,
305-
mChargerNames[i].string());
306-
int ChargingCurrent =
307-
(access(path.string(), R_OK) == 0) ? getIntField(path) : 0;
308305

309-
path.clear();
310-
path.appendFormat("%s/%s/voltage_max", POWER_SUPPLY_SYSFS_PATH,
311-
mChargerNames[i].string());
306+
int ChargingCurrent =
307+
(access(SYSFS_BATTERY_CURRENT, R_OK) == 0) ? abs(getIntField(String8(SYSFS_BATTERY_CURRENT))) : 0;
312308

313309
int ChargingVoltage =
314-
(access(path.string(), R_OK) == 0) ? getIntField(path) :
315-
DEFAULT_VBUS_VOLTAGE;
310+
(access(SYSFS_BATTERY_VOLTAGE, R_OK) == 0) ? getIntField(String8(SYSFS_BATTERY_VOLTAGE)) :
311+
DEFAULT_VBUS_VOLTAGE;
316312

317313
double power = ((double)ChargingCurrent / MILLION) *
318314
((double)ChargingVoltage / MILLION);

0 commit comments

Comments
 (0)