diff options
author | Stephane Lee <stayfan@google.com> | 2020-12-21 17:29:19 -0800 |
---|---|---|
committer | Stephane Lee <stayfan@google.com> | 2020-12-21 17:52:44 -0800 |
commit | be567bcb6363b4f99a32cfa8509b229ac15e5a42 (patch) | |
tree | b18baeb83068927fb55b433c48cd5e2cb4ce88a9 /health | |
parent | 9167ec71d5bd9544bd82026baac9f5e2d82446e0 (diff) | |
download | pixel-be567bcb6363b4f99a32cfa8509b229ac15e5a42.tar.gz |
BatteryDefender: Disable continuous error log for wireless files
Test: atest HealthTestCases
Bug: 171434500
Change-Id: I72aea9e8add5947bf74e98ac3fb5dfe333c1d6d6
Diffstat (limited to 'health')
-rw-r--r-- | health/BatteryDefender.cpp | 12 | ||||
-rw-r--r-- | health/include/pixelhealth/BatteryDefender.h | 3 |
2 files changed, 11 insertions, 4 deletions
diff --git a/health/BatteryDefender.cpp b/health/BatteryDefender.cpp index 542caff6..4d937415 100644 --- a/health/BatteryDefender.cpp +++ b/health/BatteryDefender.cpp @@ -77,11 +77,13 @@ void BatteryDefender::removeLineEndings(std::string *str) { str->erase(std::remove(str->begin(), str->end(), '\r'), str->end()); } -int BatteryDefender::readFileToInt(const char *path) { +int BatteryDefender::readFileToInt(const char *path, const bool optionalFile) { std::string buffer; int value = 0; // default if (!android::base::ReadFileToString(path, &buffer)) { - LOG(ERROR) << "Failed to read " << path; + if (optionalFile == false) { + LOG(ERROR) << "Failed to read " << path; + } } else { removeLineEndings(&buffer); if (!android::base::ParseInt(buffer.c_str(), &value)) { @@ -150,10 +152,14 @@ void BatteryDefender::writeChargeLevelsToFile(const int vendorStart, const int v bool BatteryDefender::isChargePowerAvailable(void) { // USB presence is an indicator of power availability const bool chargerPresentWired = readFileToInt(kPathUSBChargerPresent) != 0; - const bool chargerPresentWireless = readFileToInt(kPathWirelessPresent) != 0; + const bool chargerPresentWireless = + readFileToInt(kPathWirelessPresent, mIgnoreWirelessFileError) != 0; mIsUsbPresent = chargerPresentWired; mIsWirelessPresent = chargerPresentWireless; + // Report wireless read error only once; some devices may not have a wireless adapter + mIgnoreWirelessFileError = true; + return chargerPresentWired || chargerPresentWireless; } diff --git a/health/include/pixelhealth/BatteryDefender.h b/health/include/pixelhealth/BatteryDefender.h index 7819147e..4a16bcc6 100644 --- a/health/include/pixelhealth/BatteryDefender.h +++ b/health/include/pixelhealth/BatteryDefender.h @@ -133,6 +133,7 @@ class BatteryDefender { bool mHasReachedHighCapacityLevel = false; bool mWasAcOnline = false; bool mWasUsbOnline = true; /* Default; in case neither AC/USB online becomes 1 */ + bool mIgnoreWirelessFileError = false; // Process state actions void stateMachine_runAction(const state_E state, @@ -151,7 +152,7 @@ class BatteryDefender { int64_t getDeltaTimeSeconds(int64_t *timeStartSecs); int32_t getTimeToActivate(void); void removeLineEndings(std::string *str); - int readFileToInt(const char *path); + int readFileToInt(const char *path, const bool optionalFile = false); bool writeIntToFile(const char *path, const int value); void writeTimeToFile(const char *path, const int value, int64_t *previous); void writeChargeLevelsToFile(const int vendorStart, const int vendorStop); |