diff options
author | TeYuan Wang <kamewang@google.com> | 2022-12-20 21:21:43 +0800 |
---|---|---|
committer | TeYuan Wang <kamewang@google.com> | 2022-12-20 21:32:18 +0800 |
commit | 44729dc510917b1ac1788c4ca0ff1918c6dc60e5 (patch) | |
tree | 7407cb5039746f52a43b5143143e61f8a5bea7d1 | |
parent | 673c3b9165a8c90f8cc1d638d0698bd9a5ccb788 (diff) | |
download | pixel-44729dc510917b1ac1788c4ca0ff1918c6dc60e5.tar.gz |
thermal: reconnect to PowerHAL in case of failure for legacy
Bug: 262585499
Test: Tested on Raven, stop/start vendor.power-hal-aidl and verified thermal power hint
by emul_temp
Change-Id: I1de70f05e0eb0ae4b0b2950273c437835c3fc4be
-rw-r--r-- | thermal/pid_1_0/utils/powerhal_helper.cpp | 21 | ||||
-rw-r--r-- | thermal/pid_1_0/utils/powerhal_helper.h | 3 |
2 files changed, 15 insertions, 9 deletions
diff --git a/thermal/pid_1_0/utils/powerhal_helper.cpp b/thermal/pid_1_0/utils/powerhal_helper.cpp index 515fa2d9..e20f5182 100644 --- a/thermal/pid_1_0/utils/powerhal_helper.cpp +++ b/thermal/pid_1_0/utils/powerhal_helper.cpp @@ -48,11 +48,14 @@ PowerHalService::PowerHalService() bool PowerHalService::connect() { std::lock_guard<std::mutex> lock(lock_); - if (!power_hal_aidl_exist_) + + if (!power_hal_aidl_exist_) { return false; + } - if (power_hal_aidl_ != nullptr) + if (power_hal_aidl_ && power_hal_ext_aidl_) { return true; + } const std::string kInstance = std::string(IPower::descriptor) + "/default"; ndk::SpAIBinder power_binder = ndk::SpAIBinder(AServiceManager_getService(kInstance.c_str())); @@ -90,14 +93,13 @@ bool PowerHalService::connect() { bool PowerHalService::isModeSupported(const std::string &type, const ThrottlingSeverity &t) { bool isSupported = false; - if (!isPowerHalConnected()) { + if (!connect()) { return false; } std::string power_hint = StringPrintf("THERMAL_%s_%s", type.c_str(), toString(t).c_str()); lock_.lock(); if (!power_hal_ext_aidl_->isModeSupported(power_hint, &isSupported).isOk()) { LOG(ERROR) << "Fail to check supported mode, Hint: " << power_hint; - power_hal_aidl_exist_ = false; power_hal_ext_aidl_ = nullptr; power_hal_aidl_ = nullptr; lock_.unlock(); @@ -108,20 +110,23 @@ bool PowerHalService::isModeSupported(const std::string &type, const ThrottlingS } void PowerHalService::setMode(const std::string &type, const ThrottlingSeverity &t, - const bool &enable) { - if (!isPowerHalConnected()) { + const bool &enable, const bool error_on_exit) { + if (!connect()) { return; } std::string power_hint = StringPrintf("THERMAL_%s_%s", type.c_str(), toString(t).c_str()); - LOG(INFO) << "Send Hint " << power_hint << " Enable: " << std::boolalpha << enable; + LOG(INFO) << (error_on_exit ? "Resend Hint " : "Send Hint ") << power_hint + << " Enable: " << std::boolalpha << enable; lock_.lock(); if (!power_hal_ext_aidl_->setMode(power_hint, enable).isOk()) { LOG(ERROR) << "Fail to set mode, Hint: " << power_hint; - power_hal_aidl_exist_ = false; power_hal_ext_aidl_ = nullptr; power_hal_aidl_ = nullptr; lock_.unlock(); + if (!error_on_exit) { + setMode(type, t, enable, true); + } return; } lock_.unlock(); diff --git a/thermal/pid_1_0/utils/powerhal_helper.h b/thermal/pid_1_0/utils/powerhal_helper.h index 761e315c..d629cefe 100644 --- a/thermal/pid_1_0/utils/powerhal_helper.h +++ b/thermal/pid_1_0/utils/powerhal_helper.h @@ -51,7 +51,8 @@ class PowerHalService { bool isModeSupported(const std::string &type, const ThrottlingSeverity &t); bool isPowerHalConnected() { return power_hal_aidl_ != nullptr; } bool isPowerHalExtConnected() { return power_hal_ext_aidl_ != nullptr; } - void setMode(const std::string &type, const ThrottlingSeverity &t, const bool &enable); + void setMode(const std::string &type, const ThrottlingSeverity &t, const bool &enable, + const bool error_on_exit = false); private: bool power_hal_aidl_exist_; |