sdm660-common: power-libperfmgr: Disable boosting when battery saver is on

* end all running boosts when battery saver is turned on,
   and block all boosts until its turned off

Change-Id: I888fe8f3d6779c22e26c24781c492d5576cb5610
Signed-off-by: chiru2000 <chiranth@m.ms.evolution-x.org>

[clarencelol]
* This one integrated into powerhal, much better

Signed-off-by: clarencelol <clarencekuiek@icloud.com>
Signed-off-by: pix106 <sbordenave@gmail.com>
This commit is contained in:
Adithya 2022-02-13 22:49:57 +08:00 committed by pix106
parent f74bfb8367
commit 3f57e8df24
4 changed files with 18 additions and 60 deletions

View file

@ -66,9 +66,6 @@ BOARD_USES_ALSA_AUDIO := true
BOARD_SUPPORTS_SOUND_TRIGGER := true
USE_CUSTOM_AUDIO_POLICY := 1
# Battery Saver
TARGET_POWERHAL_MODE_EXT := $(COMMON_PATH)/power-libperfmgr/power/power-mode.cpp
# Bluetooth
BOARD_HAVE_BLUETOOTH := true
BOARD_HAVE_BLUETOOTH_QCOM := true

View file

@ -60,6 +60,7 @@ Power::Power(std::shared_ptr<HintManager> hm)
: mHintManager(hm),
mInteractionHandler(nullptr),
mSustainedPerfModeOn(false),
mBatterySaverOn(false),
mAdpfRateNs(
::android::base::GetIntProperty(kPowerHalAdpfRateProp, kPowerHalAdpfRateDefault)) {
mInteractionHandler = std::make_unique<InteractionHandler>(mHintManager);
@ -90,6 +91,12 @@ Power::Power(std::shared_ptr<HintManager> hm)
LOG(INFO) << "PowerHAL ready to take hints, Adpf update rate: " << mAdpfRateNs;
}
void endAllHints(std::shared_ptr<HintManager> mHintManager) {
for (std::string hint: mHintManager->GetHints()) {
mHintManager->EndHint(hint);
}
}
ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
LOG(DEBUG) << "Power setMode: " << toString(type) << " to: " << enabled;
ATRACE_INT(toString(type).c_str(), enabled);
@ -102,6 +109,13 @@ ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
[[fallthrough]];
}
case Mode::LOW_POWER:
if (enabled) {
endAllHints(mHintManager);
mHintManager->DoHint("LOW_POWER");
} else {
mHintManager->EndHint("LOW_POWER");
}
mBatterySaverOn = enabled;
break;
case Mode::SUSTAINED_PERFORMANCE:
if (enabled) {
@ -127,6 +141,7 @@ ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
case Mode::AUDIO_STREAMING_LOW_LATENCY:
[[fallthrough]];
default:
if (mBatterySaverOn) break;
if (enabled) {
mHintManager->DoHint(toString(type));
} else {
@ -154,7 +169,7 @@ ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
ATRACE_INT(toString(type).c_str(), durationMs);
switch (type) {
case Boost::INTERACTION:
if (mSustainedPerfModeOn) {
if (mSustainedPerfModeOn || mBatterySaverOn) {
break;
}
mInteractionHandler->Acquire(durationMs);
@ -166,7 +181,7 @@ ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
case Boost::AUDIO_LAUNCH:
[[fallthrough]];
default:
if (mSustainedPerfModeOn) {
if (mSustainedPerfModeOn || mBatterySaverOn) {
break;
}
if (durationMs > 0) {

View file

@ -54,6 +54,7 @@ class Power : public ::aidl::android::hardware::power::BnPower {
std::shared_ptr<HintManager> mHintManager;
std::unique_ptr<InteractionHandler> mInteractionHandler;
std::atomic<bool> mSustainedPerfModeOn;
std::atomic<bool> mBatterySaverOn;
const int64_t mAdpfRateNs;
};

View file

@ -1,55 +0,0 @@
/*
* Copyright (C) 2020 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <aidl/android/hardware/power/BnPower.h>
#include <android-base/file.h>
#include "power-common.h"
#define BATTERY_SAVER_NODE "/sys/module/battery_saver/parameters/enabled"
namespace aidl {
namespace android {
namespace hardware {
namespace power {
namespace impl {
using ::aidl::android::hardware::power::Mode;
bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) {
switch (type) {
case Mode::LOW_POWER:
*_aidl_return = true;
return true;
default:
return false;
}
}
bool setDeviceSpecificMode(Mode type, bool enabled) {
switch (type) {
case Mode::LOW_POWER:
::android::base::WriteStringToFile(enabled ? "Y" : "N", BATTERY_SAVER_NODE, true);
return true;
default:
return false;
}
}
} // namespace impl
} // namespace power
} // namespace hardware
} // namespace android
} // namespace aidl