BatteryDefender: Disable continuous error log for wireless files

Test: atest HealthTestCases
Bug: 175614345
Change-Id: I72aea9e8add5947bf74e98ac3fb5dfe333c1d6d6
(cherry picked from commit be567bcb6363b4f99a32cfa8509b229ac15e5a42)
diff --git a/health/BatteryDefender.cpp b/health/BatteryDefender.cpp
index 542caff..4d93741 100644
--- a/health/BatteryDefender.cpp
+++ b/health/BatteryDefender.cpp
@@ -77,11 +77,13 @@
     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 @@
 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 7819147..4a16bcc 100644
--- a/health/include/pixelhealth/BatteryDefender.h
+++ b/health/include/pixelhealth/BatteryDefender.h
@@ -133,6 +133,7 @@
     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 @@
     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);