twrp: use health services for battery capacity
Change-Id: I99dfb82238e2b3ae90932af0c7fd74822d971232
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
(cherry picked from commit d4df003b90f38a740c15c5023e61edafd75081ea)
diff --git a/data.cpp b/data.cpp
old mode 100755
new mode 100644
index b0ee763..f08c8db
--- a/data.cpp
+++ b/data.cpp
@@ -36,6 +36,7 @@
#include "set_metadata.h"
#include "gui/gui.hpp"
#include "infomanager.hpp"
+#include "recovery_utils/battery_utils.h"
#define DEVID_MAX 64
#define HWID_MAX 32
@@ -1042,37 +1043,14 @@
gettimeofday(&curTime, NULL);
if (curTime.tv_sec > nextSecCheck)
{
- char cap_s[4];
-#ifdef TW_CUSTOM_BATTERY_PATH
- string capacity_file = EXPAND(TW_CUSTOM_BATTERY_PATH);
- capacity_file += "/capacity";
- FILE * cap = fopen(capacity_file.c_str(),"rt");
-#else
- FILE * cap = fopen("/sys/class/power_supply/battery/capacity","rt");
-#endif
- if (cap) {
- fgets(cap_s, 4, cap);
- fclose(cap);
- lastVal = atoi(cap_s);
- if (lastVal > 100) lastVal = 101;
- if (lastVal < 0) lastVal = 0;
+ auto battery_info = GetBatteryInfo();
+ if (battery_info.charging) {
+ charging = '+';
+ } else {
+ charging = ' ';
}
-#ifdef TW_CUSTOM_BATTERY_PATH
- string status_file = EXPAND(TW_CUSTOM_BATTERY_PATH);
- status_file += "/status";
- cap = fopen(status_file.c_str(),"rt");
-#else
- cap = fopen("/sys/class/power_supply/battery/status","rt");
-#endif
- if (cap) {
- fgets(cap_s, 2, cap);
- fclose(cap);
- if (cap_s[0] == 'C')
- charging = '+';
- else
- charging = ' ';
- }
- nextSecCheck = curTime.tv_sec + 60;
+ lastVal = battery_info.capacity;
+ nextSecCheck = curTime.tv_sec + 1;
}
sprintf(tmp, "%i%%%c", lastVal, charging);