HealthService: Write battery level to wireless capacity

Bug: 150355652
Signed-off-by: YiHsiang Peng <yihsiangpeng@google.com>
Change-Id: I311bfb87e7f706d1b8e8ed33b19a4936b6b9628a
This commit is contained in:
YiHsiang Peng
2020-02-27 17:20:58 +08:00
committed by Cyan_Hsieh
parent 5a8d125afc
commit 082d0eb587

View File

@@ -60,6 +60,10 @@ constexpr char kUFSName[]{"UFS0"};
constexpr char kTCPMPSYName[]{"tcpm-source-psy-usbpd0"};
#define WLC_DIR "/sys/class/power_supply/wireless"
static bool needs_wlc_updates = false;
constexpr char kWlcCapacity[]{WLC_DIR "/capacity"};
std::ifstream assert_open(const std::string &path) {
std::ifstream stream(path);
if (!stream.is_open()) {
@@ -83,14 +87,26 @@ void fill_ufs_storage_attribute(StorageAttribute *attr) {
} // anonymous namespace
static bool FileExists(const std::string &filename) {
struct stat buffer;
return stat(filename.c_str(), &buffer) == 0;
}
void healthd_board_init(struct healthd_config *hc) {
hc->ignorePowerSupplyNames.push_back(android::String8(kTCPMPSYName));
needs_wlc_updates = FileExists(kWlcCapacity);
}
int healthd_board_battery_update(struct android::BatteryProperties *props) {
deviceHealth.update(props);
battMetricsLogger.logBatteryProperties(props);
shutdownMetrics.logShutdownVoltage(props);
if (needs_wlc_updates &&
!android::base::WriteStringToFile(std::to_string(props->batteryLevel), kWlcCapacity))
LOG(INFO) << "Unable to write battery level to wireless capacity";
return 0;
}