constexpr char kPowerHalAudioProp[] = "vendor.powerhal.audio";
constexpr char kPowerHalInitProp[] = "vendor.powerhal.init";
constexpr char kPowerHalRenderingProp[] = "vendor.powerhal.rendering";
+constexpr char kPowerHalProfileNumProp[] = "vendor.powerhal.perf_profiles";
+constexpr char kPowerHalProfileProp[] = "vendor.powerhal.perf_profile";
constexpr char kPowerHalConfigPath[] = "/vendor/etc/powerhint.json";
Power::Power()
mVRModeOn(false),
mSustainedPerfModeOn(false),
mCameraStreamingMode(false),
- mReady(false) {
+ mReady(false),
+ mNumPerfProfiles(0),
+ mCurrentPerfProfile(PowerProfile::BALANCED) {
mInitThread = std::thread([this]() {
android::base::WaitForProperty(kPowerHalInitProp, "1");
mHintManager = HintManager::GetFromJSON(kPowerHalConfigPath);
ALOGI("Initialize with EXPENSIVE_RENDERING on");
mHintManager->DoHint("EXPENSIVE_RENDERING");
}
+
+ state = android::base::GetProperty(kPowerHalProfileProp, "");
+ if (state == "POWER_SAVE") {
+ ALOGI("Initialize with POWER_SAVE profile");
+ setProfile(PowerProfile::POWER_SAVE);
+ mCurrentPerfProfile = PowerProfile::POWER_SAVE;
+ } else if (state == "BIAS_POWER_SAVE") {
+ ALOGI("Initialize with BIAS_POWER_SAVE profile");
+ setProfile(PowerProfile::BIAS_POWER_SAVE);
+ mCurrentPerfProfile = PowerProfile::BIAS_POWER_SAVE;
+ } else if (state == "BIAS_PERFORMANCE") {
+ ALOGI("Initialize with BIAS_PERFORMANCE profile");
+ setProfile(PowerProfile::BIAS_PERFORMANCE);
+ mCurrentPerfProfile = PowerProfile::BIAS_PERFORMANCE;
+ } else if (state == "HIGH_PERFORMANCE") {
+ ALOGI("Initialize with HIGH_PERFORMANCE profile");
+ setProfile(PowerProfile::HIGH_PERFORMANCE);
+ mCurrentPerfProfile = PowerProfile::HIGH_PERFORMANCE;
+ }
// Now start to take powerhint
mReady.store(true);
ALOGI("PowerHAL ready to process hints");
});
+ mNumPerfProfiles = android::base::GetIntProperty(kPowerHalProfileNumProp, 0);
mInitThread.detach();
}
return Void();
}
+Return<void> Power::setProfile(PowerProfile profile) {
+ if (mCurrentPerfProfile == profile) {
+ return Void();
+ }
+
+ // End previous perf profile hints
+ switch (mCurrentPerfProfile) {
+ case PowerProfile::POWER_SAVE:
+ mHintManager->EndHint("PROFILE_POWER_SAVE");
+ break;
+ case PowerProfile::BIAS_POWER_SAVE:
+ mHintManager->EndHint("PROFILE_BIAS_POWER_SAVE");
+ break;
+ case PowerProfile::BIAS_PERFORMANCE:
+ mHintManager->EndHint("PROFILE_BIAS_PERFORMANCE");
+ break;
+ case PowerProfile::HIGH_PERFORMANCE:
+ mHintManager->EndHint("PROFILE_HIGH_PERFORMANCE");
+ break;
+ default:
+ break;
+ }
+
+ // Apply perf profile hints
+ switch (profile) {
+ case PowerProfile::POWER_SAVE:
+ mHintManager->DoHint("PROFILE_POWER_SAVE");
+ break;
+ case PowerProfile::BIAS_POWER_SAVE:
+ mHintManager->DoHint("PROFILE_BIAS_POWER_SAVE");
+ break;
+ case PowerProfile::BIAS_PERFORMANCE:
+ mHintManager->DoHint("PROFILE_BIAS_PERFORMANCE");
+ break;
+ case PowerProfile::HIGH_PERFORMANCE:
+ mHintManager->DoHint("PROFILE_HIGH_PERFORMANCE");
+ break;
+ default:
+ break;
+ }
+
+ return Void();
+}
+
// Methods from ::android::hardware::power::V1_0::IPower follow.
Return<void> Power::setInteractive(bool interactive) {
return updateHint("NOT_INTERACTIVE", !interactive);
return Void();
}
+ switch (static_cast<LineagePowerHint>(hint)) {
+ case LineagePowerHint::SET_PROFILE:
+ setProfile(static_cast<PowerProfile>(data));
+ mCurrentPerfProfile = static_cast<PowerProfile>(data);
+ return Void();
+ default:
+ break;
+ }
+
if (hint == PowerHint_1_3::EXPENSIVE_RENDERING) {
ATRACE_INT(android::hardware::power::V1_3::toString(hint).c_str(), data);
if (mVRModeOn || mSustainedPerfModeOn) {
return Void();
}
+// Methods from ::vendor::lineage::power::V1_0::ILineagePower follow.
+Return<int32_t> Power::getFeature(LineageFeature feature) {
+ switch (feature) {
+ case LineageFeature::SUPPORTED_PROFILES:
+ return mNumPerfProfiles;
+ default:
+ return -1;
+ }
+}
+
constexpr const char *boolToString(bool b) {
return b ? "true" : "false";
}
#include "InteractionHandler.h"
+#include <vendor/lineage/power/1.0/ILineagePower.h>
+
namespace android {
namespace hardware {
namespace power {
using PowerHint_1_3 = ::android::hardware::power::V1_3::PowerHint;
using ::android::perfmgr::HintManager;
-class Power : public IPower {
+using ::vendor::lineage::power::V1_0::ILineagePower;
+using ::vendor::lineage::power::V1_0::LineageFeature;
+using ::vendor::lineage::power::V1_0::LineagePowerHint;
+
+enum PowerProfile {
+ POWER_SAVE = 0,
+ BALANCED,
+ HIGH_PERFORMANCE,
+ BIAS_POWER_SAVE,
+ BIAS_PERFORMANCE,
+ MAX
+};
+
+class Power : public IPower, public ILineagePower {
public:
// Methods from ::android::hardware::power::V1_0::IPower follow.
// Methods from ::android::hardware::power::V1_3::IPower follow.
Return<void> powerHintAsync_1_3(PowerHint_1_3 hint, int32_t data) override;
+ // Methods from ::vendor::lineage::power::V1_0::ILineagePower follow.
+ Return<int32_t> getFeature(LineageFeature feature) override;
+
// Methods from ::android::hidl::base::V1_0::IBase follow.
Return<void> debug(const hidl_handle &fd, const hidl_vec<hidl_string> &args) override;
std::atomic<bool> mReady;
std::thread mInitThread;
+ int32_t mNumPerfProfiles;
+ std::atomic<PowerProfile> mCurrentPerfProfile;
+
Return<void> updateHint(const char *hint, bool enable);
+ Return<void> setProfile(PowerProfile profile);
};
} // namespace implementation