diff --git a/healthd/Android.bp b/healthd/Android.bp index 020a74487..15f009e93 100644 --- a/healthd/Android.bp +++ b/healthd/Android.bp @@ -167,6 +167,7 @@ cc_library_static { static_libs: [ "android.hardware.health@1.0-convert", + "libcharger_sysprop", "libhealth2impl", "libhealthd_charger_ui", ], diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 645ac412d..aac719bab 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -254,15 +254,18 @@ out: LOGW("************* END LAST KMSG *************\n"); } -static int request_suspend(bool enable) { - if (!android::sysprop::ChargerProperties::enable_suspend().value_or(false)) { +int Charger::RequestEnableSuspend() { + if (!configuration_->ChargerEnableSuspend()) { return 0; } + return autosuspend_enable(); +} - if (enable) - return autosuspend_enable(); - else - return autosuspend_disable(); +int Charger::RequestDisableSuspend() { + if (!configuration_->ChargerEnableSuspend()) { + return 0; + } + return autosuspend_disable(); } static void kick_animation(animation* anim) { @@ -302,7 +305,7 @@ void Charger::UpdateScreenState(int64_t now) { batt_anim_.run = false; next_screen_transition_ = -1; if (configuration_->ChargerIsOnline()) { - request_suspend(true); + RequestEnableSuspend(); } return; } @@ -325,7 +328,7 @@ void Charger::UpdateScreenState(int64_t now) { screen_blanked_ = true; LOGV("[%" PRId64 "] animation done\n", now); if (configuration_->ChargerIsOnline()) { - request_suspend(true); + RequestEnableSuspend(); } return; } @@ -481,13 +484,13 @@ void Charger::ProcessKey(int code, int64_t now) { * rather than on key release */ kick_animation(&batt_anim_); - request_suspend(false); + RequestDisableSuspend(); } } else { /* if the power key got released, force screen state cycle */ if (key->pending) { kick_animation(&batt_anim_); - request_suspend(false); + RequestDisableSuspend(); } } } @@ -506,7 +509,7 @@ void Charger::HandlePowerSupplyState(int64_t now) { if (!have_battery_state_) return; if (!configuration_->ChargerIsOnline()) { - request_suspend(false); + RequestDisableSuspend(); if (next_pwr_check_ == -1) { /* Last cycle would have stopped at the extreme top of battery-icon * Need to show the correct level corresponding to capacity. @@ -536,7 +539,7 @@ void Charger::HandlePowerSupplyState(int64_t now) { * Reset & kick animation to show complete animation cycles * when charger connected again. */ - request_suspend(false); + RequestDisableSuspend(); next_screen_transition_ = now - 1; reset_animation(&batt_anim_); kick_animation(&batt_anim_); @@ -563,7 +566,7 @@ void Charger::OnHealthInfoChanged(const ChargerHealthInfo& health_info) { if (!have_battery_state_) { have_battery_state_ = true; next_screen_transition_ = curr_time_ms() - 1; - request_suspend(false); + RequestDisableSuspend(); reset_animation(&batt_anim_); kick_animation(&batt_anim_); } diff --git a/healthd/healthd_mode_charger_hidl.cpp b/healthd/healthd_mode_charger_hidl.cpp index ae46b23e2..3a33c02c5 100644 --- a/healthd/healthd_mode_charger_hidl.cpp +++ b/healthd/healthd_mode_charger_hidl.cpp @@ -17,6 +17,7 @@ #include "healthd_mode_charger_hidl.h" #include +#include #include #include "charger_utils.h" @@ -51,6 +52,10 @@ std::optional ChargerHidl::ChargerShouldKeepScreenOn() { return out_screen_on; } +bool ChargerHidl::ChargerEnableSuspend() { + return android::sysprop::ChargerProperties::enable_suspend().value_or(false); +} + } // namespace android int healthd_charger_main(int argc, char** argv) { diff --git a/healthd/healthd_mode_charger_hidl.h b/healthd/healthd_mode_charger_hidl.h index 9e70c5a92..0149d0713 100644 --- a/healthd/healthd_mode_charger_hidl.h +++ b/healthd/healthd_mode_charger_hidl.h @@ -37,6 +37,7 @@ class ChargerHidl : public ::android::ChargerConfigurationInterface, int ChargerRegisterEvent(int fd, BoundFunction func, EventWakeup wakeup) override { return HalHealthLoop::RegisterEvent(fd, func, wakeup); } + bool ChargerEnableSuspend() override; // HealthLoop overrides void Heartbeat() override { charger_->OnHeartbeat(); } int PrepareToWait() override { return charger_->OnPrepareToWait(); } diff --git a/healthd/include_charger/charger/healthd_mode_charger.h b/healthd/include_charger/charger/healthd_mode_charger.h index a555b0a10..216e5ad3c 100644 --- a/healthd/include_charger/charger/healthd_mode_charger.h +++ b/healthd/include_charger/charger/healthd_mode_charger.h @@ -59,6 +59,7 @@ class ChargerConfigurationInterface { virtual int ChargerRegisterEvent(int fd, BoundFunction func, EventWakeup wakeup) = 0; // Other configuration values + virtual bool ChargerEnableSuspend() = 0; }; // charger UI @@ -91,6 +92,8 @@ class Charger { void HandlePowerSupplyState(int64_t now); int InputCallback(int fd, unsigned int epevents); void InitAnimation(); + int RequestEnableSuspend(); + int RequestDisableSuspend(); bool have_battery_state_ = false; bool screen_blanked_ = false;