summaryrefslogtreecommitdiff
path: root/health/include/pixelhealth/BatteryDefender.h
diff options
context:
space:
mode:
authorStephane Lee <stayfan@google.com>2020-10-13 20:04:03 -0700
committerStephane Lee <stayfan@google.com>2020-10-15 16:32:28 -0700
commit8a3eade1ca387d8fa54680b87774ed64b84c1cde (patch)
tree25e26bc6329badbe28c21aa7d7517b05c6f7dd77 /health/include/pixelhealth/BatteryDefender.h
parente7ea64063708c806cba5cac0bc85f52c522edf7e (diff)
downloadpixel-8a3eade1ca387d8fa54680b87774ed64b84c1cde.tar.gz
Override the 'online' status for AC/USB for battery defender
Conditions: - The USB is connected - The Battery Defender is active Bug: 170787442 Test: 'atest HealthTestCases' Change-Id: I3e72a6a4be71df27c2b7965533810f8981c36e37
Diffstat (limited to 'health/include/pixelhealth/BatteryDefender.h')
-rw-r--r--health/include/pixelhealth/BatteryDefender.h24
1 files changed, 16 insertions, 8 deletions
diff --git a/health/include/pixelhealth/BatteryDefender.h b/health/include/pixelhealth/BatteryDefender.h
index 3f9bb1ce..31b410d4 100644
--- a/health/include/pixelhealth/BatteryDefender.h
+++ b/health/include/pixelhealth/BatteryDefender.h
@@ -17,6 +17,8 @@
#ifndef HARDWARE_GOOGLE_PIXEL_HEALTH_BATTERYDEFENDER_H
#define HARDWARE_GOOGLE_PIXEL_HEALTH_BATTERYDEFENDER_H
+#include <batteryservice/BatteryService.h>
+
#include <stdbool.h>
#include <time.h>
#include <string>
@@ -50,7 +52,7 @@ class BatteryDefender {
const int32_t timeToClearTimerSecs = DEFAULT_TIME_TO_CLEAR_SECONDS);
// This function shall be called periodically in HealthService
- void update(void);
+ void update(struct android::BatteryProperties *props);
private:
enum state_E {
@@ -75,9 +77,7 @@ class BatteryDefender {
const int32_t kTimeToClearTimerSecs;
// Sysfs
- const char *const kPathWirelessChargerOnline = "/sys/class/power_supply/wireless/online";
- const char *const kPathWiredChargerPresent = "/sys/class/power_supply/usb/present";
- const char *const kPathBatteryCapacity = "/sys/class/power_supply/battery/capacity";
+ const char *const kPathUSBChargerPresent = "/sys/class/power_supply/usb/present";
const char *const kPathPersistChargerPresentTime =
"/mnt/vendor/persist/battery/defender_charger_time";
const char *const kPathPersistDefenderActiveTime =
@@ -101,6 +101,7 @@ class BatteryDefender {
// Inputs
int64_t mTimeBetweenUpdateCalls = 0;
int64_t mTimePreviousSecs;
+ bool mIsUsbPresent = false;
bool mIsPowerAvailable = false;
bool mIsDefenderDisabled = false;
int32_t mTimeToActivateSecsModified;
@@ -115,10 +116,17 @@ class BatteryDefender {
int mChargeLevelStartPrevious = DEFAULT_CHARGE_LEVEL_START;
int mChargeLevelStopPrevious = DEFAULT_CHARGE_LEVEL_STOP;
bool mHasReachedHighCapacityLevel = false;
+ bool mWasAcOnline = false;
+ bool mWasUsbOnline = false;
+
+ // Process state actions
+ void stateMachine_runAction(const state_E state, struct android::BatteryProperties *props);
+
+ // Check state transitions
+ state_E stateMachine_getNextState(const state_E state);
- void stateMachine_runAction(const state_E state); // Process state actions
- state_E stateMachine_getNextState(const state_E state); // Check transitions
- void stateMachine_firstAction(const state_E state); // Process entry actions
+ // Process state entry actions
+ void stateMachine_firstAction(const state_E state);
void clearStateData(void);
void loadPersistentStorage(void);
@@ -130,7 +138,7 @@ class BatteryDefender {
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);
- bool isChargePowerAvailable(void);
+ bool isChargePowerAvailable(const bool chargerWirelessOnline);
bool isDefaultChargeLevel(const int start, const int stop);
bool isBatteryDefenderDisabled(const int vendorStart, const int vendorStop);
void addTimeToChargeTimers(void);