From be567bcb6363b4f99a32cfa8509b229ac15e5a42 Mon Sep 17 00:00:00 2001 From: Stephane Lee Date: Mon, 21 Dec 2020 17:29:19 -0800 Subject: BatteryDefender: Disable continuous error log for wireless files Test: atest HealthTestCases Bug: 171434500 Change-Id: I72aea9e8add5947bf74e98ac3fb5dfe333c1d6d6 --- health/BatteryDefender.cpp | 12 +++++++++--- health/include/pixelhealth/BatteryDefender.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'health') 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); -- cgit v1.2.3