Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 17 | #define LOG_TAG "HalWrapper" |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 18 | #include <aidl/android/hardware/power/Boost.h> |
| 19 | #include <aidl/android/hardware/power/IPowerHintSession.h> |
| 20 | #include <aidl/android/hardware/power/Mode.h> |
Matt Buckley | 8f997cb | 2024-11-16 19:26:34 -0800 | [diff] [blame] | 21 | #include <aidl/android/hardware/power/SupportInfo.h> |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 22 | #include <powermanager/HalResult.h> |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 23 | #include <powermanager/PowerHalWrapper.h> |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 24 | #include <utils/Log.h> |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 25 | |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 26 | using namespace android::hardware::power; |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 27 | namespace Aidl = aidl::android::hardware::power; |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 31 | namespace power { |
| 32 | |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 33 | // ------------------------------------------------------------------------------------------------- |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 34 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 35 | HalResult<void> EmptyHalWrapper::setBoost(Aidl::Boost boost, int32_t durationMs) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 36 | ALOGV("Skipped setBoost %s with duration %dms because %s", toString(boost).c_str(), durationMs, |
| 37 | getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 38 | return HalResult<void>::unsupported(); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 41 | HalResult<void> EmptyHalWrapper::setMode(Aidl::Mode mode, bool enabled) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 42 | ALOGV("Skipped setMode %s to %s because %s", toString(mode).c_str(), enabled ? "true" : "false", |
| 43 | getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 44 | return HalResult<void>::unsupported(); |
| 45 | } |
| 46 | |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 47 | HalResult<std::shared_ptr<PowerHintSessionWrapper>> EmptyHalWrapper::createHintSession( |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 48 | int32_t, int32_t, const std::vector<int32_t>& threadIds, int64_t) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 49 | ALOGV("Skipped createHintSession(task num=%zu) because %s", threadIds.size(), |
| 50 | getUnsupportedMessage()); |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 51 | return HalResult<std::shared_ptr<PowerHintSessionWrapper>>::unsupported(); |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 54 | HalResult<std::shared_ptr<PowerHintSessionWrapper>> EmptyHalWrapper::createHintSessionWithConfig( |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 55 | int32_t, int32_t, const std::vector<int32_t>& threadIds, int64_t, Aidl::SessionTag, |
| 56 | Aidl::SessionConfig*) { |
| 57 | ALOGV("Skipped createHintSessionWithConfig(task num=%zu) because %s", threadIds.size(), |
| 58 | getUnsupportedMessage()); |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 59 | return HalResult<std::shared_ptr<PowerHintSessionWrapper>>::unsupported(); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | HalResult<int64_t> EmptyHalWrapper::getHintSessionPreferredRate() { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 63 | ALOGV("Skipped getHintSessionPreferredRate because %s", getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 64 | return HalResult<int64_t>::unsupported(); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 67 | HalResult<Aidl::ChannelConfig> EmptyHalWrapper::getSessionChannel(int, int) { |
| 68 | ALOGV("Skipped getSessionChannel because %s", getUnsupportedMessage()); |
| 69 | return HalResult<Aidl::ChannelConfig>::unsupported(); |
| 70 | } |
| 71 | |
| 72 | HalResult<void> EmptyHalWrapper::closeSessionChannel(int, int) { |
| 73 | ALOGV("Skipped closeSessionChannel because %s", getUnsupportedMessage()); |
| 74 | return HalResult<void>::unsupported(); |
| 75 | } |
| 76 | |
Matt Buckley | 8f997cb | 2024-11-16 19:26:34 -0800 | [diff] [blame] | 77 | HalResult<Aidl::SupportInfo> EmptyHalWrapper::getSupportInfo() { |
| 78 | ALOGV("Skipped getSupportInfo because %s", getUnsupportedMessage()); |
| 79 | return HalResult<Aidl::SupportInfo>::unsupported(); |
| 80 | } |
| 81 | |
Matt Buckley | 038a896 | 2025-03-07 14:52:30 -0800 | [diff] [blame] | 82 | HalResult<void> EmptyHalWrapper::sendCompositionData(const std::vector<hal::CompositionData>&) { |
| 83 | ALOGV("Skipped sendCompositionData because %s", getUnsupportedMessage()); |
| 84 | return HalResult<void>::unsupported(); |
| 85 | } |
| 86 | |
| 87 | HalResult<void> EmptyHalWrapper::sendCompositionUpdate(const hal::CompositionUpdate&) { |
| 88 | ALOGV("Skipped sendCompositionUpdate because %s", getUnsupportedMessage()); |
| 89 | return HalResult<void>::unsupported(); |
| 90 | } |
| 91 | |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 92 | const char* EmptyHalWrapper::getUnsupportedMessage() { |
| 93 | return "Power HAL is not supported"; |
| 94 | } |
| 95 | |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 96 | // ------------------------------------------------------------------------------------------------- |
| 97 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 98 | HalResult<void> HidlHalWrapperV1_0::setBoost(Aidl::Boost boost, int32_t durationMs) { |
| 99 | if (boost == Aidl::Boost::INTERACTION) { |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 100 | return sendPowerHint(V1_3::PowerHint::INTERACTION, durationMs); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 101 | } else { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 102 | return EmptyHalWrapper::setBoost(boost, durationMs); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 106 | HalResult<void> HidlHalWrapperV1_0::setMode(Aidl::Mode mode, bool enabled) { |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 107 | uint32_t data = enabled ? 1 : 0; |
| 108 | switch (mode) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 109 | case Aidl::Mode::LAUNCH: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 110 | return sendPowerHint(V1_3::PowerHint::LAUNCH, data); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 111 | case Aidl::Mode::LOW_POWER: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 112 | return sendPowerHint(V1_3::PowerHint::LOW_POWER, data); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 113 | case Aidl::Mode::SUSTAINED_PERFORMANCE: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 114 | return sendPowerHint(V1_3::PowerHint::SUSTAINED_PERFORMANCE, data); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 115 | case Aidl::Mode::VR: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 116 | return sendPowerHint(V1_3::PowerHint::VR_MODE, data); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 117 | case Aidl::Mode::INTERACTIVE: |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 118 | return setInteractive(enabled); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 119 | case Aidl::Mode::DOUBLE_TAP_TO_WAKE: |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 120 | return setFeature(V1_0::Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE, enabled); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 121 | default: |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 122 | return EmptyHalWrapper::setMode(mode, enabled); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 126 | HalResult<void> HidlHalWrapperV1_0::sendPowerHint(V1_3::PowerHint hintId, uint32_t data) { |
| 127 | auto ret = mHandleV1_0->powerHint(static_cast<V1_0::PowerHint>(hintId), data); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 128 | return HalResult<void>::fromReturn(ret); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 131 | HalResult<void> HidlHalWrapperV1_0::setInteractive(bool enabled) { |
| 132 | auto ret = mHandleV1_0->setInteractive(enabled); |
| 133 | return HalResult<void>::fromReturn(ret); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 136 | HalResult<void> HidlHalWrapperV1_0::setFeature(V1_0::Feature feature, bool enabled) { |
| 137 | auto ret = mHandleV1_0->setFeature(feature, enabled); |
| 138 | return HalResult<void>::fromReturn(ret); |
| 139 | } |
| 140 | |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 141 | const char* HidlHalWrapperV1_0::getUnsupportedMessage() { |
| 142 | return "Power HAL AIDL is not supported"; |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | // ------------------------------------------------------------------------------------------------- |
| 146 | |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 147 | HalResult<void> HidlHalWrapperV1_1::sendPowerHint(V1_3::PowerHint hintId, uint32_t data) { |
| 148 | auto handle = static_cast<V1_1::IPower*>(mHandleV1_0.get()); |
| 149 | auto ret = handle->powerHintAsync(static_cast<V1_0::PowerHint>(hintId), data); |
| 150 | return HalResult<void>::fromReturn(ret); |
| 151 | } |
| 152 | |
| 153 | // ------------------------------------------------------------------------------------------------- |
| 154 | |
| 155 | HalResult<void> HidlHalWrapperV1_2::sendPowerHint(V1_3::PowerHint hintId, uint32_t data) { |
| 156 | auto handle = static_cast<V1_2::IPower*>(mHandleV1_0.get()); |
| 157 | auto ret = handle->powerHintAsync_1_2(static_cast<V1_2::PowerHint>(hintId), data); |
| 158 | return HalResult<void>::fromReturn(ret); |
| 159 | } |
| 160 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 161 | HalResult<void> HidlHalWrapperV1_2::setBoost(Aidl::Boost boost, int32_t durationMs) { |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 162 | switch (boost) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 163 | case Aidl::Boost::CAMERA_SHOT: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 164 | return sendPowerHint(V1_3::PowerHint::CAMERA_SHOT, durationMs); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 165 | case Aidl::Boost::CAMERA_LAUNCH: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 166 | return sendPowerHint(V1_3::PowerHint::CAMERA_LAUNCH, durationMs); |
| 167 | default: |
| 168 | return HidlHalWrapperV1_1::setBoost(boost, durationMs); |
| 169 | } |
| 170 | } |
| 171 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 172 | HalResult<void> HidlHalWrapperV1_2::setMode(Aidl::Mode mode, bool enabled) { |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 173 | uint32_t data = enabled ? 1 : 0; |
| 174 | switch (mode) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 175 | case Aidl::Mode::CAMERA_STREAMING_SECURE: |
| 176 | case Aidl::Mode::CAMERA_STREAMING_LOW: |
| 177 | case Aidl::Mode::CAMERA_STREAMING_MID: |
| 178 | case Aidl::Mode::CAMERA_STREAMING_HIGH: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 179 | return sendPowerHint(V1_3::PowerHint::CAMERA_STREAMING, data); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 180 | case Aidl::Mode::AUDIO_STREAMING_LOW_LATENCY: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 181 | return sendPowerHint(V1_3::PowerHint::AUDIO_LOW_LATENCY, data); |
| 182 | default: |
| 183 | return HidlHalWrapperV1_1::setMode(mode, enabled); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | // ------------------------------------------------------------------------------------------------- |
| 188 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 189 | HalResult<void> HidlHalWrapperV1_3::setMode(Aidl::Mode mode, bool enabled) { |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 190 | uint32_t data = enabled ? 1 : 0; |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 191 | if (mode == Aidl::Mode::EXPENSIVE_RENDERING) { |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 192 | return sendPowerHint(V1_3::PowerHint::EXPENSIVE_RENDERING, data); |
| 193 | } |
| 194 | return HidlHalWrapperV1_2::setMode(mode, enabled); |
| 195 | } |
| 196 | |
| 197 | HalResult<void> HidlHalWrapperV1_3::sendPowerHint(V1_3::PowerHint hintId, uint32_t data) { |
| 198 | auto handle = static_cast<V1_3::IPower*>(mHandleV1_0.get()); |
| 199 | auto ret = handle->powerHintAsync_1_3(hintId, data); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 200 | return HalResult<void>::fromReturn(ret); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | // ------------------------------------------------------------------------------------------------- |
| 204 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 205 | HalResult<void> AidlHalWrapper::setBoost(Aidl::Boost boost, int32_t durationMs) { |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 206 | std::unique_lock<std::mutex> lock(mBoostMutex); |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 207 | size_t idx = static_cast<size_t>(boost); |
| 208 | |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 209 | // Quick return if boost is not supported by HAL |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 210 | if (idx >= mBoostSupportedArray.size() || mBoostSupportedArray[idx] == HalSupport::OFF) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 211 | ALOGV("Skipped setBoost %s because %s", toString(boost).c_str(), getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 212 | return HalResult<void>::unsupported(); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 215 | if (mBoostSupportedArray[idx] == HalSupport::UNKNOWN) { |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 216 | bool isSupported = false; |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 217 | auto isSupportedRet = mHandle->isBoostSupported(boost, &isSupported); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 218 | if (!isSupportedRet.isOk()) { |
Lais Andrade | 14e97b7 | 2020-07-14 12:27:44 +0000 | [diff] [blame] | 219 | ALOGE("Skipped setBoost %s because check support failed with: %s", |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 220 | toString(boost).c_str(), isSupportedRet.getDescription().c_str()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 221 | // return HalResult::FAILED; |
| 222 | return HalResult<void>::fromStatus(isSupportedRet); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 225 | mBoostSupportedArray[idx] = isSupported ? HalSupport::ON : HalSupport::OFF; |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 226 | if (!isSupported) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 227 | ALOGV("Skipped setBoost %s because %s", toString(boost).c_str(), |
| 228 | getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 229 | return HalResult<void>::unsupported(); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | lock.unlock(); |
| 233 | |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 234 | return HalResult<void>::fromStatus(mHandle->setBoost(boost, durationMs)); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 237 | HalResult<void> AidlHalWrapper::setMode(Aidl::Mode mode, bool enabled) { |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 238 | std::unique_lock<std::mutex> lock(mModeMutex); |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 239 | size_t idx = static_cast<size_t>(mode); |
| 240 | |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 241 | // Quick return if mode is not supported by HAL |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 242 | if (idx >= mModeSupportedArray.size() || mModeSupportedArray[idx] == HalSupport::OFF) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 243 | ALOGV("Skipped setMode %s because %s", toString(mode).c_str(), getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 244 | return HalResult<void>::unsupported(); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 247 | if (mModeSupportedArray[idx] == HalSupport::UNKNOWN) { |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 248 | bool isSupported = false; |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 249 | auto isSupportedRet = mHandle->isModeSupported(mode, &isSupported); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 250 | if (!isSupportedRet.isOk()) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 251 | return HalResult<void>::failed(isSupportedRet.getDescription()); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 254 | mModeSupportedArray[idx] = isSupported ? HalSupport::ON : HalSupport::OFF; |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 255 | if (!isSupported) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 256 | ALOGV("Skipped setMode %s because %s", toString(mode).c_str(), getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 257 | return HalResult<void>::unsupported(); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | lock.unlock(); |
| 261 | |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 262 | return HalResult<void>::fromStatus(mHandle->setMode(mode, enabled)); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 265 | HalResult<std::shared_ptr<PowerHintSessionWrapper>> AidlHalWrapper::createHintSession( |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 266 | int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds, int64_t durationNanos) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 267 | std::shared_ptr<Aidl::IPowerHintSession> appSession; |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 268 | return HalResult<std::shared_ptr<PowerHintSessionWrapper>>:: |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 269 | fromStatus(mHandle->createHintSession(tgid, uid, threadIds, durationNanos, &appSession), |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 270 | std::make_shared<PowerHintSessionWrapper>(std::move(appSession))); |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 273 | HalResult<std::shared_ptr<PowerHintSessionWrapper>> AidlHalWrapper::createHintSessionWithConfig( |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 274 | int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds, int64_t durationNanos, |
| 275 | Aidl::SessionTag tag, Aidl::SessionConfig* config) { |
| 276 | std::shared_ptr<Aidl::IPowerHintSession> appSession; |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 277 | return HalResult<std::shared_ptr<PowerHintSessionWrapper>>:: |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 278 | fromStatus(mHandle->createHintSessionWithConfig(tgid, uid, threadIds, durationNanos, |
| 279 | tag, config, &appSession), |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 280 | std::make_shared<PowerHintSessionWrapper>(std::move(appSession))); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | HalResult<int64_t> AidlHalWrapper::getHintSessionPreferredRate() { |
| 284 | int64_t rate = -1; |
| 285 | auto result = mHandle->getHintSessionPreferredRate(&rate); |
| 286 | return HalResult<int64_t>::fromStatus(result, rate); |
| 287 | } |
| 288 | |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 289 | HalResult<Aidl::ChannelConfig> AidlHalWrapper::getSessionChannel(int tgid, int uid) { |
| 290 | Aidl::ChannelConfig config; |
| 291 | auto result = mHandle->getSessionChannel(tgid, uid, &config); |
| 292 | return HalResult<Aidl::ChannelConfig>::fromStatus(result, std::move(config)); |
| 293 | } |
| 294 | |
| 295 | HalResult<void> AidlHalWrapper::closeSessionChannel(int tgid, int uid) { |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 296 | return HalResult<void>::fromStatus(mHandle->closeSessionChannel(tgid, uid)); |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Matt Buckley | 8f997cb | 2024-11-16 19:26:34 -0800 | [diff] [blame] | 299 | HalResult<Aidl::SupportInfo> AidlHalWrapper::getSupportInfo() { |
| 300 | Aidl::SupportInfo support; |
| 301 | auto result = mHandle->getSupportInfo(&support); |
| 302 | return HalResult<Aidl::SupportInfo>::fromStatus(result, std::move(support)); |
| 303 | } |
| 304 | |
Matt Buckley | 038a896 | 2025-03-07 14:52:30 -0800 | [diff] [blame] | 305 | HalResult<void> AidlHalWrapper::sendCompositionData(const std::vector<hal::CompositionData>& data) { |
| 306 | return HalResult<void>::fromStatus(mHandle->sendCompositionData(data)); |
| 307 | } |
| 308 | |
| 309 | HalResult<void> AidlHalWrapper::sendCompositionUpdate(const hal::CompositionUpdate& update) { |
| 310 | return HalResult<void>::fromStatus(mHandle->sendCompositionUpdate(update)); |
| 311 | } |
| 312 | |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 313 | const char* AidlHalWrapper::getUnsupportedMessage() { |
| 314 | return "Power HAL doesn't support it"; |
| 315 | } |
| 316 | |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 317 | // ------------------------------------------------------------------------------------------------- |
| 318 | |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 319 | } // namespace power |
| 320 | |
| 321 | } // namespace android |