mediatek: power: Do not perform boosts on LOW_POWER mode
* Also let's fix inproper naming scheme and make
mHandle and mLowPowerEnabled private while we're
at it.
Signed-off-by: bengris32 <bengris32@protonmail.ch>
Change-Id: I7d8dbd7d64a5f4197e6c0c01a47b6dfc9fe0d28a
diff --git a/power/Power.cpp b/power/Power.cpp
index a690606..b029c4b 100644
--- a/power/Power.cpp
+++ b/power/Power.cpp
@@ -61,13 +61,16 @@
#endif
case Mode::LAUNCH:
{
- if (this->handle != 0) {
- libpowerhal_LockRel(this->handle);
- this->handle = 0;
+ if (mLowPowerEnabled)
+ break;
+
+ if (mHandle != 0) {
+ libpowerhal_LockRel(mHandle);
+ mHandle = 0;
}
if (enabled)
- this->handle = libpowerhal_CusLockHint(11, 30000, getpid());
+ mHandle = libpowerhal_CusLockHint(11, 30000, getpid());
break;
}
@@ -83,6 +86,9 @@
libpowerhal_UserScnDisableAll();
break;
}
+ case Mode::LOW_POWER:
+ mLowPowerEnabled = enabled;
+ break;
default:
break;
}
@@ -103,6 +109,11 @@
}
ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
+ if (mLowPowerEnabled) {
+ LOG(INFO) << "Will not perform boosts in LOW_POWER";
+ return ndk::ScopedAStatus::ok();
+ }
+
int32_t intType = static_cast<int32_t>(type);
// Avoid boosts with 0 duration, as those will run indefinitely
diff --git a/power/Power.h b/power/Power.h
index 991c758..20ddeef 100644
--- a/power/Power.h
+++ b/power/Power.h
@@ -26,9 +26,9 @@
namespace mediatek {
class Power : public BnPower {
+public:
Power();
~Power();
- int handle;
ndk::ScopedAStatus setMode(Mode type, bool enabled) override;
ndk::ScopedAStatus isModeSupported(Mode type, bool* _aidl_return) override;
ndk::ScopedAStatus setBoost(Boost type, int32_t durationMs) override;
@@ -40,6 +40,9 @@
std::shared_ptr<IPowerHintSession>* _aidl_return) override;
ndk::ScopedAStatus getHintSessionPreferredRate(int64_t* outNanoseconds) override;
#endif
+private:
+ int mHandle;
+ bool mLowPowerEnabled;
};
} // namespace mediatek