diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index 125eccf7..0b10a4f3 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -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 diff --git a/power-libperfmgr/aidl/Power.cpp b/power-libperfmgr/aidl/Power.cpp index bff53b66..a1691d90 100644 --- a/power-libperfmgr/aidl/Power.cpp +++ b/power-libperfmgr/aidl/Power.cpp @@ -60,6 +60,7 @@ Power::Power(std::shared_ptr hm) : mHintManager(hm), mInteractionHandler(nullptr), mSustainedPerfModeOn(false), + mBatterySaverOn(false), mAdpfRateNs( ::android::base::GetIntProperty(kPowerHalAdpfRateProp, kPowerHalAdpfRateDefault)) { mInteractionHandler = std::make_unique(mHintManager); @@ -90,6 +91,12 @@ Power::Power(std::shared_ptr hm) LOG(INFO) << "PowerHAL ready to take hints, Adpf update rate: " << mAdpfRateNs; } +void endAllHints(std::shared_ptr 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) { diff --git a/power-libperfmgr/aidl/Power.h b/power-libperfmgr/aidl/Power.h index 9f973b73..04bda866 100644 --- a/power-libperfmgr/aidl/Power.h +++ b/power-libperfmgr/aidl/Power.h @@ -54,6 +54,7 @@ class Power : public ::aidl::android::hardware::power::BnPower { std::shared_ptr mHintManager; std::unique_ptr mInteractionHandler; std::atomic mSustainedPerfModeOn; + std::atomic mBatterySaverOn; const int64_t mAdpfRateNs; }; diff --git a/power-libperfmgr/power/power-mode.cpp b/power-libperfmgr/power/power-mode.cpp deleted file mode 100644 index 1fee8ef6..00000000 --- a/power-libperfmgr/power/power-mode.cpp +++ /dev/null @@ -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 -#include -#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