summaryrefslogtreecommitdiff
path: root/health/include/pixelhealth/BatteryDefender.h
diff options
context:
space:
mode:
authorStephane Lee <stayfan@google.com>2022-03-28 16:49:56 -0700
committerStephane Lee <stayfan@google.com>2022-04-19 23:58:55 +0000
commit10e11f65c0bb8577879a585ef0701937751ea845 (patch)
treeb3693b9579dc9921f2e01ac861920c6d32e5cecb /health/include/pixelhealth/BatteryDefender.h
parentf9b8bf54a0533548a5825090ac2249b2de8cdf8e (diff)
downloadpixel-10e11f65c0bb8577879a585ef0701937751ea845.tar.gz
BatteryDefender: Use typec to verify for wired connectivity
Bug: 192828279 Bug: 180104512 Test: Verify that battery defender works as expected when USB is plugged Change-Id: I9eb8f54da5557db60551b08abe2ddf40502c7fb7 (cherry picked from commit 4a81fb745c4e6cfb9a0ccaabde590d0828d42cbc)
Diffstat (limited to 'health/include/pixelhealth/BatteryDefender.h')
-rw-r--r--health/include/pixelhealth/BatteryDefender.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/health/include/pixelhealth/BatteryDefender.h b/health/include/pixelhealth/BatteryDefender.h
index 48bf70a3..a9506832 100644
--- a/health/include/pixelhealth/BatteryDefender.h
+++ b/health/include/pixelhealth/BatteryDefender.h
@@ -44,17 +44,20 @@ const int DEFAULT_CAPACITY_LEVEL = 100;
const int WRITE_DELAY_SECS = 2 * ONE_MIN_IN_SECONDS;
const char *const PATH_NOT_SUPPORTED = "";
+const char *const DEFAULT_START_LEVEL_PATH =
+ "/sys/devices/platform/soc/soc:google,charger/charge_start_level";
+const char *const DEFAULT_STOP_LEVEL_PATH =
+ "/sys/devices/platform/soc/soc:google,charger/charge_stop_level";
class BatteryDefender {
public:
// Set default google charger paths - can be overridden for other devices
BatteryDefender(const std::string pathWirelessPresent = PATH_NOT_SUPPORTED,
- const std::string pathChargeLevelStart =
- "/sys/devices/platform/soc/soc:google,charger/charge_start_level",
- const std::string pathChargeLevelStop =
- "/sys/devices/platform/soc/soc:google,charger/charge_stop_level",
+ const std::string pathChargeLevelStart = DEFAULT_START_LEVEL_PATH,
+ const std::string pathChargeLevelStop = DEFAULT_STOP_LEVEL_PATH,
const int32_t timeToActivateSecs = DEFAULT_TIME_TO_ACTIVATE_SECONDS,
- const int32_t timeToClearTimerSecs = DEFAULT_TIME_TO_CLEAR_SECONDS);
+ const int32_t timeToClearTimerSecs = DEFAULT_TIME_TO_CLEAR_SECONDS,
+ const bool useTypeC = true);
// Either of the update() function shall be called periodically in HealthService
// Deprecated. Use update(HealthInfo*)
@@ -62,6 +65,7 @@ class BatteryDefender {
void update(aidl::android::hardware::health::HealthInfo *health_info);
// Set wireless not supported if this is not a device with a wireless charger
+ // (must be checked at runtime)
void setWirelessNotSupported(void);
private:
@@ -81,14 +85,17 @@ class BatteryDefender {
[STATE_ACTIVE] = "ACTIVE",
};
+ // Constructor
std::string mPathWirelessPresent;
const std::string kPathChargeLevelStart;
const std::string kPathChargeLevelStop;
const int32_t kTimeToActivateSecs;
const int32_t kTimeToClearTimerSecs;
+ const bool kUseTypeC;
// Sysfs
const std::string kPathUSBChargerPresent = "/sys/class/power_supply/usb/present";
+ const std::string kTypeCPath = "/sys/class/typec/";
const std::string kPathPersistChargerPresentTime =
"/mnt/vendor/persist/battery/defender_charger_time";
const std::string kPathPersistDefenderActiveTime =
@@ -127,7 +134,7 @@ class BatteryDefender {
// Inputs
int64_t mTimeBetweenUpdateCalls = 0;
int64_t mTimePreviousSecs;
- bool mIsUsbPresent = false;
+ bool mIsWiredPresent = false;
bool mIsWirelessPresent = false;
bool mIsPowerAvailable = false;
bool mIsDefenderDisabled = false;
@@ -167,6 +174,8 @@ class BatteryDefender {
bool writeIntToFile(const std::string &path, const int value);
void writeTimeToFile(const std::string &path, const int value, int64_t *previous);
void writeChargeLevelsToFile(const int vendorStart, const int vendorStop);
+ bool isTypeCSink(const std::string &path);
+ bool isWiredPresent(void);
bool isChargePowerAvailable(void);
bool isDefaultChargeLevel(const int start, const int stop);
bool isBatteryDefenderDisabled(const int vendorStart, const int vendorStop);