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 | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 82 | const char* EmptyHalWrapper::getUnsupportedMessage() { |
| 83 | return "Power HAL is not supported"; |
| 84 | } |
| 85 | |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 86 | // ------------------------------------------------------------------------------------------------- |
| 87 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 88 | HalResult<void> HidlHalWrapperV1_0::setBoost(Aidl::Boost boost, int32_t durationMs) { |
| 89 | if (boost == Aidl::Boost::INTERACTION) { |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 90 | return sendPowerHint(V1_3::PowerHint::INTERACTION, durationMs); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 91 | } else { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 92 | return EmptyHalWrapper::setBoost(boost, durationMs); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 96 | HalResult<void> HidlHalWrapperV1_0::setMode(Aidl::Mode mode, bool enabled) { |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 97 | uint32_t data = enabled ? 1 : 0; |
| 98 | switch (mode) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 99 | case Aidl::Mode::LAUNCH: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 100 | return sendPowerHint(V1_3::PowerHint::LAUNCH, data); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 101 | case Aidl::Mode::LOW_POWER: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 102 | return sendPowerHint(V1_3::PowerHint::LOW_POWER, data); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 103 | case Aidl::Mode::SUSTAINED_PERFORMANCE: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 104 | return sendPowerHint(V1_3::PowerHint::SUSTAINED_PERFORMANCE, data); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 105 | case Aidl::Mode::VR: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 106 | return sendPowerHint(V1_3::PowerHint::VR_MODE, data); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 107 | case Aidl::Mode::INTERACTIVE: |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 108 | return setInteractive(enabled); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 109 | case Aidl::Mode::DOUBLE_TAP_TO_WAKE: |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 110 | return setFeature(V1_0::Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE, enabled); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 111 | default: |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 112 | return EmptyHalWrapper::setMode(mode, enabled); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 116 | HalResult<void> HidlHalWrapperV1_0::sendPowerHint(V1_3::PowerHint hintId, uint32_t data) { |
| 117 | auto ret = mHandleV1_0->powerHint(static_cast<V1_0::PowerHint>(hintId), data); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 118 | return HalResult<void>::fromReturn(ret); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 121 | HalResult<void> HidlHalWrapperV1_0::setInteractive(bool enabled) { |
| 122 | auto ret = mHandleV1_0->setInteractive(enabled); |
| 123 | return HalResult<void>::fromReturn(ret); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 126 | HalResult<void> HidlHalWrapperV1_0::setFeature(V1_0::Feature feature, bool enabled) { |
| 127 | auto ret = mHandleV1_0->setFeature(feature, enabled); |
| 128 | return HalResult<void>::fromReturn(ret); |
| 129 | } |
| 130 | |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 131 | const char* HidlHalWrapperV1_0::getUnsupportedMessage() { |
| 132 | return "Power HAL AIDL is not supported"; |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | // ------------------------------------------------------------------------------------------------- |
| 136 | |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 137 | HalResult<void> HidlHalWrapperV1_1::sendPowerHint(V1_3::PowerHint hintId, uint32_t data) { |
| 138 | auto handle = static_cast<V1_1::IPower*>(mHandleV1_0.get()); |
| 139 | auto ret = handle->powerHintAsync(static_cast<V1_0::PowerHint>(hintId), data); |
| 140 | return HalResult<void>::fromReturn(ret); |
| 141 | } |
| 142 | |
| 143 | // ------------------------------------------------------------------------------------------------- |
| 144 | |
| 145 | HalResult<void> HidlHalWrapperV1_2::sendPowerHint(V1_3::PowerHint hintId, uint32_t data) { |
| 146 | auto handle = static_cast<V1_2::IPower*>(mHandleV1_0.get()); |
| 147 | auto ret = handle->powerHintAsync_1_2(static_cast<V1_2::PowerHint>(hintId), data); |
| 148 | return HalResult<void>::fromReturn(ret); |
| 149 | } |
| 150 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 151 | HalResult<void> HidlHalWrapperV1_2::setBoost(Aidl::Boost boost, int32_t durationMs) { |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 152 | switch (boost) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 153 | case Aidl::Boost::CAMERA_SHOT: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 154 | return sendPowerHint(V1_3::PowerHint::CAMERA_SHOT, durationMs); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 155 | case Aidl::Boost::CAMERA_LAUNCH: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 156 | return sendPowerHint(V1_3::PowerHint::CAMERA_LAUNCH, durationMs); |
| 157 | default: |
| 158 | return HidlHalWrapperV1_1::setBoost(boost, durationMs); |
| 159 | } |
| 160 | } |
| 161 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 162 | HalResult<void> HidlHalWrapperV1_2::setMode(Aidl::Mode mode, bool enabled) { |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 163 | uint32_t data = enabled ? 1 : 0; |
| 164 | switch (mode) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 165 | case Aidl::Mode::CAMERA_STREAMING_SECURE: |
| 166 | case Aidl::Mode::CAMERA_STREAMING_LOW: |
| 167 | case Aidl::Mode::CAMERA_STREAMING_MID: |
| 168 | case Aidl::Mode::CAMERA_STREAMING_HIGH: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 169 | return sendPowerHint(V1_3::PowerHint::CAMERA_STREAMING, data); |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 170 | case Aidl::Mode::AUDIO_STREAMING_LOW_LATENCY: |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 171 | return sendPowerHint(V1_3::PowerHint::AUDIO_LOW_LATENCY, data); |
| 172 | default: |
| 173 | return HidlHalWrapperV1_1::setMode(mode, enabled); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // ------------------------------------------------------------------------------------------------- |
| 178 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 179 | HalResult<void> HidlHalWrapperV1_3::setMode(Aidl::Mode mode, bool enabled) { |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 180 | uint32_t data = enabled ? 1 : 0; |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 181 | if (mode == Aidl::Mode::EXPENSIVE_RENDERING) { |
Matt Buckley | c3894a4 | 2022-09-01 21:17:15 +0000 | [diff] [blame] | 182 | return sendPowerHint(V1_3::PowerHint::EXPENSIVE_RENDERING, data); |
| 183 | } |
| 184 | return HidlHalWrapperV1_2::setMode(mode, enabled); |
| 185 | } |
| 186 | |
| 187 | HalResult<void> HidlHalWrapperV1_3::sendPowerHint(V1_3::PowerHint hintId, uint32_t data) { |
| 188 | auto handle = static_cast<V1_3::IPower*>(mHandleV1_0.get()); |
| 189 | auto ret = handle->powerHintAsync_1_3(hintId, data); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 190 | return HalResult<void>::fromReturn(ret); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | // ------------------------------------------------------------------------------------------------- |
| 194 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 195 | HalResult<void> AidlHalWrapper::setBoost(Aidl::Boost boost, int32_t durationMs) { |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 196 | std::unique_lock<std::mutex> lock(mBoostMutex); |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 197 | size_t idx = static_cast<size_t>(boost); |
| 198 | |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 199 | // Quick return if boost is not supported by HAL |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 200 | if (idx >= mBoostSupportedArray.size() || mBoostSupportedArray[idx] == HalSupport::OFF) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 201 | ALOGV("Skipped setBoost %s because %s", toString(boost).c_str(), getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 202 | return HalResult<void>::unsupported(); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 205 | if (mBoostSupportedArray[idx] == HalSupport::UNKNOWN) { |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 206 | bool isSupported = false; |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 207 | auto isSupportedRet = mHandle->isBoostSupported(boost, &isSupported); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 208 | if (!isSupportedRet.isOk()) { |
Lais Andrade | 14e97b7 | 2020-07-14 12:27:44 +0000 | [diff] [blame] | 209 | ALOGE("Skipped setBoost %s because check support failed with: %s", |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 210 | toString(boost).c_str(), isSupportedRet.getDescription().c_str()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 211 | // return HalResult::FAILED; |
| 212 | return HalResult<void>::fromStatus(isSupportedRet); |
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 | mBoostSupportedArray[idx] = isSupported ? HalSupport::ON : HalSupport::OFF; |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 216 | if (!isSupported) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 217 | ALOGV("Skipped setBoost %s because %s", toString(boost).c_str(), |
| 218 | getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 219 | return HalResult<void>::unsupported(); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | lock.unlock(); |
| 223 | |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 224 | return HalResult<void>::fromStatus(mHandle->setBoost(boost, durationMs)); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 227 | HalResult<void> AidlHalWrapper::setMode(Aidl::Mode mode, bool enabled) { |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 228 | std::unique_lock<std::mutex> lock(mModeMutex); |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 229 | size_t idx = static_cast<size_t>(mode); |
| 230 | |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 231 | // Quick return if mode is not supported by HAL |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 232 | if (idx >= mModeSupportedArray.size() || mModeSupportedArray[idx] == HalSupport::OFF) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 233 | ALOGV("Skipped setMode %s because %s", toString(mode).c_str(), getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 234 | return HalResult<void>::unsupported(); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 237 | if (mModeSupportedArray[idx] == HalSupport::UNKNOWN) { |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 238 | bool isSupported = false; |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 239 | auto isSupportedRet = mHandle->isModeSupported(mode, &isSupported); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 240 | if (!isSupportedRet.isOk()) { |
Xiang Wang | 99f6f3c | 2023-05-22 13:12:16 -0700 | [diff] [blame] | 241 | return HalResult<void>::failed(isSupportedRet.getDescription()); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Lais Andrade | 7b632a5 | 2020-12-03 21:07:48 +0000 | [diff] [blame] | 244 | mModeSupportedArray[idx] = isSupported ? HalSupport::ON : HalSupport::OFF; |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 245 | if (!isSupported) { |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 246 | ALOGV("Skipped setMode %s because %s", toString(mode).c_str(), getUnsupportedMessage()); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 247 | return HalResult<void>::unsupported(); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | lock.unlock(); |
| 251 | |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 252 | return HalResult<void>::fromStatus(mHandle->setMode(mode, enabled)); |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 255 | HalResult<std::shared_ptr<PowerHintSessionWrapper>> AidlHalWrapper::createHintSession( |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 256 | 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] | 257 | std::shared_ptr<Aidl::IPowerHintSession> appSession; |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 258 | return HalResult<std::shared_ptr<PowerHintSessionWrapper>>:: |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 259 | fromStatus(mHandle->createHintSession(tgid, uid, threadIds, durationNanos, &appSession), |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 260 | std::make_shared<PowerHintSessionWrapper>(std::move(appSession))); |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 263 | HalResult<std::shared_ptr<PowerHintSessionWrapper>> AidlHalWrapper::createHintSessionWithConfig( |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 264 | int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds, int64_t durationNanos, |
| 265 | Aidl::SessionTag tag, Aidl::SessionConfig* config) { |
| 266 | std::shared_ptr<Aidl::IPowerHintSession> appSession; |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 267 | return HalResult<std::shared_ptr<PowerHintSessionWrapper>>:: |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 268 | fromStatus(mHandle->createHintSessionWithConfig(tgid, uid, threadIds, durationNanos, |
| 269 | tag, config, &appSession), |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 270 | std::make_shared<PowerHintSessionWrapper>(std::move(appSession))); |
Jimmy Shiu | 0b264bb | 2021-03-03 00:30:50 +0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | HalResult<int64_t> AidlHalWrapper::getHintSessionPreferredRate() { |
| 274 | int64_t rate = -1; |
| 275 | auto result = mHandle->getHintSessionPreferredRate(&rate); |
| 276 | return HalResult<int64_t>::fromStatus(result, rate); |
| 277 | } |
| 278 | |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 279 | HalResult<Aidl::ChannelConfig> AidlHalWrapper::getSessionChannel(int tgid, int uid) { |
| 280 | Aidl::ChannelConfig config; |
| 281 | auto result = mHandle->getSessionChannel(tgid, uid, &config); |
| 282 | return HalResult<Aidl::ChannelConfig>::fromStatus(result, std::move(config)); |
| 283 | } |
| 284 | |
| 285 | HalResult<void> AidlHalWrapper::closeSessionChannel(int tgid, int uid) { |
Matt Buckley | 6c18e6d | 2024-02-07 23:39:50 +0000 | [diff] [blame] | 286 | return HalResult<void>::fromStatus(mHandle->closeSessionChannel(tgid, uid)); |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Matt Buckley | 8f997cb | 2024-11-16 19:26:34 -0800 | [diff] [blame] | 289 | HalResult<Aidl::SupportInfo> AidlHalWrapper::getSupportInfo() { |
| 290 | Aidl::SupportInfo support; |
| 291 | auto result = mHandle->getSupportInfo(&support); |
| 292 | return HalResult<Aidl::SupportInfo>::fromStatus(result, std::move(support)); |
| 293 | } |
| 294 | |
Matt Buckley | db4192a | 2023-12-21 20:00:32 +0000 | [diff] [blame] | 295 | const char* AidlHalWrapper::getUnsupportedMessage() { |
| 296 | return "Power HAL doesn't support it"; |
| 297 | } |
| 298 | |
Lais Andrade | 4d51f6c | 2020-03-25 10:58:31 +0000 | [diff] [blame] | 299 | // ------------------------------------------------------------------------------------------------- |
| 300 | |
Lais Andrade | b59a9b5 | 2020-05-07 17:23:42 +0100 | [diff] [blame] | 301 | } // namespace power |
| 302 | |
| 303 | } // namespace android |