d865b86327
[wight554] Enable DOUBLE_TAP_TO_WAKE mode explicitly and move dt2w mode on top of setMode switch: when LAUNCH hint is received, if mSustainedPerfModeOn is not true, it will not break, leading to the case switch going through all the next labels without interrupting until the end, also hitting DT2W one, leading to DT2W always toggling when you launch an app [SebaUbuntu] Don't break devices using hint manager for DT2W toggle Change-Id: Ib6e1e010834b1b16668d52db79b26804fe0e1671
217 lines
6.7 KiB
C++
217 lines
6.7 KiB
C++
/*
|
|
* Copyright (C) 2020 The Android Open Source 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.
|
|
*/
|
|
|
|
#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
|
|
#define LOG_TAG "android.hardware.power-service.xiaomi-libperfmgr"
|
|
|
|
#include "Power.h"
|
|
|
|
#include <mutex>
|
|
|
|
#include <android-base/file.h>
|
|
#include <android-base/logging.h>
|
|
#include <android-base/properties.h>
|
|
#include <android-base/stringprintf.h>
|
|
#include <android-base/strings.h>
|
|
|
|
#include <utils/Log.h>
|
|
#include <utils/Trace.h>
|
|
|
|
namespace aidl {
|
|
namespace google {
|
|
namespace hardware {
|
|
namespace power {
|
|
namespace impl {
|
|
namespace pixel {
|
|
|
|
#ifdef MODE_EXT
|
|
extern bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return);
|
|
extern bool setDeviceSpecificMode(Mode type, bool enabled);
|
|
#endif
|
|
|
|
constexpr char kPowerHalStateProp[] = "vendor.powerhal.state";
|
|
constexpr char kPowerHalAudioProp[] = "vendor.powerhal.audio";
|
|
constexpr char kPowerHalRenderingProp[] = "vendor.powerhal.rendering";
|
|
|
|
Power::Power(std::shared_ptr<HintManager> hm)
|
|
: mHintManager(hm),
|
|
mInteractionHandler(nullptr),
|
|
mSustainedPerfModeOn(false) {
|
|
mInteractionHandler = std::make_unique<InteractionHandler>(mHintManager);
|
|
mInteractionHandler->Init();
|
|
|
|
std::string state = ::android::base::GetProperty(kPowerHalStateProp, "");
|
|
if (state == "SUSTAINED_PERFORMANCE") {
|
|
ALOGI("Initialize with SUSTAINED_PERFORMANCE on");
|
|
mHintManager->DoHint("SUSTAINED_PERFORMANCE");
|
|
mSustainedPerfModeOn = true;
|
|
} else {
|
|
ALOGI("Initialize PowerHAL");
|
|
}
|
|
|
|
state = ::android::base::GetProperty(kPowerHalAudioProp, "");
|
|
if (state == "AUDIO_STREAMING_LOW_LATENCY") {
|
|
ALOGI("Initialize with AUDIO_LOW_LATENCY on");
|
|
mHintManager->DoHint(state);
|
|
}
|
|
|
|
state = ::android::base::GetProperty(kPowerHalRenderingProp, "");
|
|
if (state == "EXPENSIVE_RENDERING") {
|
|
ALOGI("Initialize with EXPENSIVE_RENDERING on");
|
|
mHintManager->DoHint("EXPENSIVE_RENDERING");
|
|
}
|
|
|
|
// Now start to take powerhint
|
|
ALOGI("PowerHAL ready to process hints");
|
|
}
|
|
|
|
ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) {
|
|
LOG(DEBUG) << "Power setMode: " << toString(type) << " to: " << enabled;
|
|
ATRACE_INT(toString(type).c_str(), enabled);
|
|
#ifdef MODE_EXT
|
|
if (setDeviceSpecificMode(type, enabled)) {
|
|
return ndk::ScopedAStatus::ok();
|
|
}
|
|
#endif
|
|
switch (type) {
|
|
#ifdef TAP_TO_WAKE_NODE
|
|
case Mode::DOUBLE_TAP_TO_WAKE:
|
|
::android::base::WriteStringToFile(enabled ? "1" : "0", TAP_TO_WAKE_NODE, true);
|
|
break;
|
|
#endif
|
|
case Mode::SUSTAINED_PERFORMANCE:
|
|
if (enabled) {
|
|
mHintManager->DoHint("SUSTAINED_PERFORMANCE");
|
|
}
|
|
mSustainedPerfModeOn = true;
|
|
break;
|
|
case Mode::LAUNCH:
|
|
if (mSustainedPerfModeOn) {
|
|
break;
|
|
}
|
|
[[fallthrough]];
|
|
#ifndef TAP_TO_WAKE_NODE
|
|
case Mode::DOUBLE_TAP_TO_WAKE:
|
|
[[fallthrough]];
|
|
#endif
|
|
case Mode::FIXED_PERFORMANCE:
|
|
[[fallthrough]];
|
|
case Mode::EXPENSIVE_RENDERING:
|
|
[[fallthrough]];
|
|
case Mode::INTERACTIVE:
|
|
[[fallthrough]];
|
|
case Mode::DEVICE_IDLE:
|
|
[[fallthrough]];
|
|
case Mode::DISPLAY_INACTIVE:
|
|
[[fallthrough]];
|
|
case Mode::AUDIO_STREAMING_LOW_LATENCY:
|
|
[[fallthrough]];
|
|
default:
|
|
if (enabled) {
|
|
mHintManager->DoHint(toString(type));
|
|
} else {
|
|
mHintManager->EndHint(toString(type));
|
|
}
|
|
break;
|
|
}
|
|
|
|
return ndk::ScopedAStatus::ok();
|
|
}
|
|
|
|
ndk::ScopedAStatus Power::isModeSupported(Mode type, bool *_aidl_return) {
|
|
#ifdef MODE_EXT
|
|
if (isDeviceSpecificModeSupported(type, _aidl_return)) {
|
|
return ndk::ScopedAStatus::ok();
|
|
}
|
|
#endif
|
|
|
|
bool supported = mHintManager->IsHintSupported(toString(type));
|
|
#ifdef TAP_TO_WAKE_NODE
|
|
if (type == Mode::DOUBLE_TAP_TO_WAKE) {
|
|
supported = true;
|
|
}
|
|
#endif
|
|
LOG(INFO) << "Power mode " << toString(type) << " isModeSupported: " << supported;
|
|
*_aidl_return = supported;
|
|
return ndk::ScopedAStatus::ok();
|
|
}
|
|
|
|
ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
|
|
LOG(DEBUG) << "Power setBoost: " << toString(type) << " duration: " << durationMs;
|
|
ATRACE_INT(toString(type).c_str(), durationMs);
|
|
switch (type) {
|
|
case Boost::INTERACTION:
|
|
if (mSustainedPerfModeOn) {
|
|
break;
|
|
}
|
|
mInteractionHandler->Acquire(durationMs);
|
|
break;
|
|
case Boost::DISPLAY_UPDATE_IMMINENT:
|
|
[[fallthrough]];
|
|
case Boost::ML_ACC:
|
|
[[fallthrough]];
|
|
case Boost::AUDIO_LAUNCH:
|
|
[[fallthrough]];
|
|
default:
|
|
if (mSustainedPerfModeOn) {
|
|
break;
|
|
}
|
|
if (durationMs > 0) {
|
|
mHintManager->DoHint(toString(type), std::chrono::milliseconds(durationMs));
|
|
} else if (durationMs == 0) {
|
|
mHintManager->DoHint(toString(type));
|
|
} else {
|
|
mHintManager->EndHint(toString(type));
|
|
}
|
|
break;
|
|
}
|
|
|
|
return ndk::ScopedAStatus::ok();
|
|
}
|
|
|
|
ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool *_aidl_return) {
|
|
bool supported = mHintManager->IsHintSupported(toString(type));
|
|
LOG(INFO) << "Power boost " << toString(type) << " isBoostSupported: " << supported;
|
|
*_aidl_return = supported;
|
|
return ndk::ScopedAStatus::ok();
|
|
}
|
|
|
|
constexpr const char *boolToString(bool b) {
|
|
return b ? "true" : "false";
|
|
}
|
|
|
|
binder_status_t Power::dump(int fd, const char **, uint32_t) {
|
|
std::string buf(::android::base::StringPrintf(
|
|
"HintManager Running: %s\n"
|
|
"SustainedPerformanceMode: %s\n",
|
|
boolToString(mHintManager->IsRunning()),
|
|
boolToString(mSustainedPerfModeOn)));
|
|
// Dump nodes through libperfmgr
|
|
mHintManager->DumpToFd(fd);
|
|
if (!::android::base::WriteStringToFd(buf, fd)) {
|
|
PLOG(ERROR) << "Failed to dump state to fd";
|
|
}
|
|
fsync(fd);
|
|
return STATUS_OK;
|
|
}
|
|
|
|
} // namespace pixel
|
|
} // namespace impl
|
|
} // namespace power
|
|
} // namespace hardware
|
|
} // namespace google
|
|
} // namespace aidl
|