summaryrefslogtreecommitdiff
path: root/services/powermanager/PowerHalWrapper.cpp
diff options
context:
space:
mode:
author Lais Andrade <lsandrade@google.com> 2020-03-25 10:58:31 +0000
committer Lais Andrade <lsandrade@google.com> 2020-04-17 21:47:13 +0100
commit4d51f6ce2a9028a68b3092aab6a528cb69b0c56c (patch)
treeff0c3a41d5010ac69a8557df41ac4cceb26e6ad7 /services/powermanager/PowerHalWrapper.cpp
parenteb9f16c66b50b2c51b6714b435149c771a17a401 (diff)
Create wrappers for Power HAL.
Create wrappers over existing HIDL Power HALs v1.0, v1.1, and AIDL Power HAL. All wrappers expose the same API that should be used by the PowerManagerService. Bug: 150878220 Test: atest powermanager_test Change-Id: I5edba6d51d3e18c5137c87b65bc9efa6c70ba7e8
Diffstat (limited to 'services/powermanager/PowerHalWrapper.cpp')
-rw-r--r--services/powermanager/PowerHalWrapper.cpp172
1 files changed, 172 insertions, 0 deletions
diff --git a/services/powermanager/PowerHalWrapper.cpp b/services/powermanager/PowerHalWrapper.cpp
new file mode 100644
index 0000000000..d959a2cc96
--- /dev/null
+++ b/services/powermanager/PowerHalWrapper.cpp
@@ -0,0 +1,172 @@
+/*
+ * 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 LOG_TAG "PowerHalWrapper"
+#include <utils/Log.h>
+
+#include <android/hardware/power/Boost.h>
+#include <android/hardware/power/Mode.h>
+
+#include <powermanager/PowerHalWrapper.h>
+
+using android::hardware::power::Boost;
+using android::hardware::power::Mode;
+using android::hardware::power::V1_0::Feature;
+using android::hardware::power::V1_0::PowerHint;
+
+namespace android {
+
+// -------------------------------------------------------------------------------------------------
+
+PowerHalResult EmptyPowerHalWrapper::setBoost(Boost boost, int32_t durationMs) {
+ ALOGV("Skipped setBoost %s with duration %dms because Power HAL not available",
+ toString(boost).c_str(), durationMs);
+ return PowerHalResult::UNSUPPORTED;
+}
+
+PowerHalResult EmptyPowerHalWrapper::setMode(Mode mode, bool enabled) {
+ ALOGV("Skipped setMode %s to %s because Power HAL not available",
+ toString(mode).c_str(), enabled ? "true" : "false");
+ return PowerHalResult::UNSUPPORTED;
+}
+
+// -------------------------------------------------------------------------------------------------
+
+PowerHalResult HidlPowerHalWrapperV1_0::setBoost(Boost boost, int32_t durationMs) {
+ if (boost == Boost::INTERACTION) {
+ return sendPowerHint(PowerHint::INTERACTION, durationMs);
+ } else {
+ ALOGV("Skipped setBoost %s because Power HAL AIDL not available",
+ toString(boost).c_str());
+ return PowerHalResult::UNSUPPORTED;
+ }
+}
+
+PowerHalResult HidlPowerHalWrapperV1_0::setMode(Mode mode, bool enabled) {
+ uint32_t data = enabled ? 1 : 0;
+ switch (mode) {
+ case Mode::LAUNCH:
+ return sendPowerHint(PowerHint::LAUNCH, data);
+ case Mode::LOW_POWER:
+ return sendPowerHint(PowerHint::LOW_POWER, data);
+ case Mode::SUSTAINED_PERFORMANCE:
+ return sendPowerHint(PowerHint::SUSTAINED_PERFORMANCE, data);
+ case Mode::VR:
+ return sendPowerHint(PowerHint::VR_MODE, data);
+ case Mode::INTERACTIVE:
+ return setInteractive(enabled);
+ case Mode::DOUBLE_TAP_TO_WAKE:
+ return setFeature(Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE, enabled);
+ default:
+ ALOGV("Skipped setMode %s because Power HAL AIDL not available",
+ toString(mode).c_str());
+ return PowerHalResult::UNSUPPORTED;
+ }
+}
+
+PowerHalResult HidlPowerHalWrapperV1_0::sendPowerHint(PowerHint hintId, uint32_t data) {
+ auto ret = handleV1_0->powerHint(hintId, data);
+ return ret.isOk() ? PowerHalResult::SUCCESSFUL : PowerHalResult::FAILED;
+}
+
+PowerHalResult HidlPowerHalWrapperV1_0::setInteractive(bool enabled) {
+ auto ret = handleV1_0->setInteractive(enabled);
+ return ret.isOk() ? PowerHalResult::SUCCESSFUL : PowerHalResult::FAILED;
+}
+
+PowerHalResult HidlPowerHalWrapperV1_0::setFeature(Feature feature, bool enabled) {
+ auto ret = handleV1_0->setFeature(feature, enabled);
+ return ret.isOk() ? PowerHalResult::SUCCESSFUL : PowerHalResult::FAILED;
+}
+
+// -------------------------------------------------------------------------------------------------
+
+PowerHalResult HidlPowerHalWrapperV1_1::sendPowerHint(PowerHint hintId, uint32_t data) {
+ auto ret = handleV1_1->powerHintAsync(hintId, data);
+ return ret.isOk() ? PowerHalResult::SUCCESSFUL : PowerHalResult::FAILED;
+}
+
+// -------------------------------------------------------------------------------------------------
+
+PowerHalResult AidlPowerHalWrapper::setBoost(Boost boost, int32_t durationMs) {
+ std::unique_lock<std::mutex> lock(mBoostMutex);
+ // Quick return if boost is not supported by HAL
+ if (boost > Boost::DISPLAY_UPDATE_IMMINENT ||
+ boostSupportedArray[static_cast<int32_t>(boost)] == PowerHalSupport::OFF) {
+ ALOGV("Skipped setBoost %s because Power HAL doesn't support it",
+ toString(boost).c_str());
+ return PowerHalResult::UNSUPPORTED;
+ }
+
+ if (boostSupportedArray[static_cast<int32_t>(boost)] == PowerHalSupport::UNKNOWN) {
+ bool isSupported = false;
+ auto isSupportedRet = handle->isBoostSupported(boost, &isSupported);
+ if (!isSupportedRet.isOk()) {
+ ALOGV("Skipped setBoost %s because Power HAL is not available to check support",
+ toString(boost).c_str());
+ return PowerHalResult::FAILED;
+ }
+
+ boostSupportedArray[static_cast<int32_t>(boost)] =
+ isSupported ? PowerHalSupport::ON : PowerHalSupport::OFF;
+ if (!isSupported) {
+ ALOGV("Skipped setBoost %s because Power HAL doesn't support it",
+ toString(boost).c_str());
+ return PowerHalResult::UNSUPPORTED;
+ }
+ }
+ lock.unlock();
+
+ auto ret = handle->setBoost(boost, durationMs);
+ return ret.isOk() ? PowerHalResult::SUCCESSFUL : PowerHalResult::FAILED;
+}
+
+PowerHalResult AidlPowerHalWrapper::setMode(Mode mode, bool enabled) {
+ std::unique_lock<std::mutex> lock(mModeMutex);
+ // Quick return if mode is not supported by HAL
+ if (mode > Mode::DISPLAY_INACTIVE ||
+ modeSupportedArray[static_cast<int32_t>(mode)] == PowerHalSupport::OFF) {
+ ALOGV("Skipped setMode %s because Power HAL doesn't support it",
+ toString(mode).c_str());
+ return PowerHalResult::UNSUPPORTED;
+ }
+
+ if (modeSupportedArray[static_cast<int32_t>(mode)] == PowerHalSupport::UNKNOWN) {
+ bool isSupported = false;
+ auto isSupportedRet = handle->isModeSupported(mode, &isSupported);
+ if (!isSupportedRet.isOk()) {
+ ALOGV("Skipped setMode %s because Power HAL is not available to check support",
+ toString(mode).c_str());
+ return PowerHalResult::FAILED;
+ }
+
+ modeSupportedArray[static_cast<int32_t>(mode)] =
+ isSupported ? PowerHalSupport::ON : PowerHalSupport::OFF;
+ if (!isSupported) {
+ ALOGV("Skipped setMode %s because Power HAL doesn't support it",
+ toString(mode).c_str());
+ return PowerHalResult::UNSUPPORTED;
+ }
+ }
+ lock.unlock();
+
+ auto ret = handle->setMode(mode, enabled);
+ return ret.isOk() ? PowerHalResult::SUCCESSFUL : PowerHalResult::FAILED;
+}
+
+// -------------------------------------------------------------------------------------------------
+
+}; // namespace android