From 5851c3aa252d8708bfc9e079c3b07fed7bc8b16d Mon Sep 17 00:00:00 2001 From: Peiyong Lin Date: Tue, 18 Oct 2022 20:47:56 +0000 Subject: [PATCH] Align default implementation with latest VSR. VSR requires to support power HAL V2 and beyond, this patch changes the default implementation to reflect that. Bug: b/253516147 Test: atest VtsHalPowerTargetTest Change-Id: I56f6f847f4c47775db6350b8a3fcd7ee9c9cdf17 --- power/aidl/default/Android.bp | 1 + power/aidl/default/Power.cpp | 42 ++++++++++++------- power/aidl/default/Power.h | 4 ++ power/aidl/default/PowerHintSession.cpp | 54 +++++++++++++++++++++++++ power/aidl/default/PowerHintSession.h | 37 +++++++++++++++++ 5 files changed, 123 insertions(+), 15 deletions(-) create mode 100644 power/aidl/default/PowerHintSession.cpp create mode 100644 power/aidl/default/PowerHintSession.h diff --git a/power/aidl/default/Android.bp b/power/aidl/default/Android.bp index d1257f336a..da91ee6690 100644 --- a/power/aidl/default/Android.bp +++ b/power/aidl/default/Android.bp @@ -35,6 +35,7 @@ cc_binary { srcs: [ "main.cpp", "Power.cpp", + "PowerHintSession.cpp", ], } diff --git a/power/aidl/default/Power.cpp b/power/aidl/default/Power.cpp index 7f08f44926..8fe370c3e4 100644 --- a/power/aidl/default/Power.cpp +++ b/power/aidl/default/Power.cpp @@ -15,6 +15,7 @@ */ #include "Power.h" +#include "PowerHintSession.h" #include @@ -25,42 +26,53 @@ namespace power { namespace impl { namespace example { +using namespace std::chrono_literals; + +using ndk::ScopedAStatus; + const std::vector BOOST_RANGE{ndk::enum_range().begin(), ndk::enum_range().end()}; const std::vector MODE_RANGE{ndk::enum_range().begin(), ndk::enum_range().end()}; -ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) { +ScopedAStatus Power::setMode(Mode type, bool enabled) { LOG(VERBOSE) << "Power setMode: " << static_cast(type) << " to: " << enabled; - return ndk::ScopedAStatus::ok(); + return ScopedAStatus::ok(); } -ndk::ScopedAStatus Power::isModeSupported(Mode type, bool* _aidl_return) { +ScopedAStatus Power::isModeSupported(Mode type, bool* _aidl_return) { LOG(INFO) << "Power isModeSupported: " << static_cast(type); *_aidl_return = type >= MODE_RANGE.front() && type <= MODE_RANGE.back(); - return ndk::ScopedAStatus::ok(); + return ScopedAStatus::ok(); } -ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) { +ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) { LOG(VERBOSE) << "Power setBoost: " << static_cast(type) << ", duration: " << durationMs; - return ndk::ScopedAStatus::ok(); + return ScopedAStatus::ok(); } -ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool* _aidl_return) { +ScopedAStatus Power::isBoostSupported(Boost type, bool* _aidl_return) { LOG(INFO) << "Power isBoostSupported: " << static_cast(type); *_aidl_return = type >= BOOST_RANGE.front() && type <= BOOST_RANGE.back(); - return ndk::ScopedAStatus::ok(); + return ScopedAStatus::ok(); } -ndk::ScopedAStatus Power::createHintSession(int32_t, int32_t, const std::vector&, int64_t, - std::shared_ptr* _aidl_return) { - *_aidl_return = nullptr; - return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); +ScopedAStatus Power::createHintSession(int32_t, int32_t, const std::vector& tids, int64_t, + std::shared_ptr* _aidl_return) { + if (tids.size() == 0) { + *_aidl_return = nullptr; + return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + } + std::shared_ptr powerHintSession = + ndk::SharedRefBase::make(); + mPowerHintSessions.push_back(powerHintSession); + *_aidl_return = powerHintSession; + return ScopedAStatus::ok(); } -ndk::ScopedAStatus Power::getHintSessionPreferredRate(int64_t* outNanoseconds) { - *outNanoseconds = -1; - return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); +ScopedAStatus Power::getHintSessionPreferredRate(int64_t* outNanoseconds) { + *outNanoseconds = std::chrono::nanoseconds(1ms).count(); + return ScopedAStatus::ok(); } } // namespace example diff --git a/power/aidl/default/Power.h b/power/aidl/default/Power.h index ef6439dde6..7f8405eff3 100644 --- a/power/aidl/default/Power.h +++ b/power/aidl/default/Power.h @@ -26,6 +26,7 @@ namespace impl { namespace example { class Power : public BnPower { + public: ndk::ScopedAStatus setMode(Mode type, bool enabled) override; ndk::ScopedAStatus isModeSupported(Mode type, bool* _aidl_return) override; ndk::ScopedAStatus setBoost(Boost type, int32_t durationMs) override; @@ -35,6 +36,9 @@ class Power : public BnPower { int64_t durationNanos, std::shared_ptr* _aidl_return) override; ndk::ScopedAStatus getHintSessionPreferredRate(int64_t* outNanoseconds) override; + + private: + std::vector> mPowerHintSessions; }; } // namespace example diff --git a/power/aidl/default/PowerHintSession.cpp b/power/aidl/default/PowerHintSession.cpp new file mode 100644 index 0000000000..aa95be451b --- /dev/null +++ b/power/aidl/default/PowerHintSession.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2022 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. + */ + +#include "PowerHintSession.h" + +#include + +namespace aidl::android::hardware::power::impl::example { + +using ndk::ScopedAStatus; + +PowerHintSession::PowerHintSession() {} + +ScopedAStatus PowerHintSession::updateTargetWorkDuration(int64_t targetDurationNanos) { + LOG(VERBOSE) << __func__ << "target duration in nanoseconds: " << targetDurationNanos; + return ScopedAStatus::ok(); +} + +ScopedAStatus PowerHintSession::reportActualWorkDuration( + const std::vector& /* durations */) { + LOG(VERBOSE) << __func__; + return ScopedAStatus::ok(); +} + +ScopedAStatus PowerHintSession::pause() { + return ScopedAStatus::ok(); +} + +ScopedAStatus PowerHintSession::resume() { + return ScopedAStatus::ok(); +} + +ScopedAStatus PowerHintSession::close() { + return ScopedAStatus::ok(); +} + +ScopedAStatus PowerHintSession::sendHint(SessionHint /* hint */) { + return ScopedAStatus::ok(); +} + +} // namespace aidl::android::hardware::power::impl::example diff --git a/power/aidl/default/PowerHintSession.h b/power/aidl/default/PowerHintSession.h new file mode 100644 index 0000000000..6a7627a730 --- /dev/null +++ b/power/aidl/default/PowerHintSession.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 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. + */ + +#pragma once + +#include +#include +#include + +namespace aidl::android::hardware::power::impl::example { + +class PowerHintSession : public BnPowerHintSession { + public: + explicit PowerHintSession(); + ndk::ScopedAStatus updateTargetWorkDuration(int64_t targetDurationNanos) override; + ndk::ScopedAStatus reportActualWorkDuration( + const std::vector& durations) override; + ndk::ScopedAStatus pause() override; + ndk::ScopedAStatus resume() override; + ndk::ScopedAStatus close() override; + ndk::ScopedAStatus sendHint(SessionHint hint) override; +}; + +} // namespace aidl::android::hardware::power::impl::example