diff options
Diffstat (limited to 'thermal/utils/powerhal_helper.cpp')
-rw-r--r-- | thermal/utils/powerhal_helper.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/thermal/utils/powerhal_helper.cpp b/thermal/utils/powerhal_helper.cpp index 515fa2d..e20f518 100644 --- a/thermal/utils/powerhal_helper.cpp +++ b/thermal/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(); |