summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeYuan Wang <kamewang@google.com>2022-12-16 13:48:54 +0800
committerTeYuan Wang <kamewang@google.com>2022-12-19 14:05:58 +0800
commit673c3b9165a8c90f8cc1d638d0698bd9a5ccb788 (patch)
tree1b815e2eaf32556bb7d3fd2e76939c603f6e6711
parentd4fe1ba8b5cf5ac32282b98c4941bf4dcd6fadce (diff)
downloadpixel-673c3b9165a8c90f8cc1d638d0698bd9a5ccb788.tar.gz
thermal: reconnect to PowerHAL in case of failure
Bug: 262585499 Test: stop/start vendor.power-hal-aidl and verified thermal power hint by emul_temp Change-Id: I6dfc0a3d7f6ef0c39a464f5952bb447db73c20d8
-rw-r--r--thermal/utils/powerhal_helper.cpp21
-rw-r--r--thermal/utils/powerhal_helper.h3
2 files changed, 15 insertions, 9 deletions
diff --git a/thermal/utils/powerhal_helper.cpp b/thermal/utils/powerhal_helper.cpp
index 515fa2d9..e20f5182 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();
diff --git a/thermal/utils/powerhal_helper.h b/thermal/utils/powerhal_helper.h
index 761e315c..d629cefe 100644
--- a/thermal/utils/powerhal_helper.h
+++ b/thermal/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_;