blob: 8f15663db9f81bcd4855c09d847fea79b83c7ca3 [file] [log] [blame]
Wei Wang61c2a332020-01-08 16:51:47 -08001/*
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
17#include "Power.h"
Peiyong Lin5851c3a2022-10-18 20:47:56 +000018#include "PowerHintSession.h"
Wei Wang61c2a332020-01-08 16:51:47 -080019
20#include <android-base/logging.h>
Matt Buckleycaac1472023-12-12 03:55:50 +000021#include <fmq/AidlMessageQueue.h>
22#include <fmq/EventFlag.h>
Wei Wang61c2a332020-01-08 16:51:47 -080023
24namespace aidl {
25namespace android {
26namespace hardware {
27namespace power {
28namespace impl {
29namespace example {
30
Peiyong Lin5851c3a2022-10-18 20:47:56 +000031using namespace std::chrono_literals;
Matt Buckleycaac1472023-12-12 03:55:50 +000032using ::aidl::android::hardware::common::fmq::MQDescriptor;
33using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
34using ::aidl::android::hardware::power::ChannelMessage;
35using ::android::AidlMessageQueue;
Peiyong Lin5851c3a2022-10-18 20:47:56 +000036
37using ndk::ScopedAStatus;
38
Wei Wang05003412021-04-01 10:44:29 -070039const std::vector<Boost> BOOST_RANGE{ndk::enum_range<Boost>().begin(),
40 ndk::enum_range<Boost>().end()};
41const std::vector<Mode> MODE_RANGE{ndk::enum_range<Mode>().begin(), ndk::enum_range<Mode>().end()};
42
Peiyong Lin5851c3a2022-10-18 20:47:56 +000043ScopedAStatus Power::setMode(Mode type, bool enabled) {
Wei Wang61c2a332020-01-08 16:51:47 -080044 LOG(VERBOSE) << "Power setMode: " << static_cast<int32_t>(type) << " to: " << enabled;
Peiyong Lin5851c3a2022-10-18 20:47:56 +000045 return ScopedAStatus::ok();
Wei Wang61c2a332020-01-08 16:51:47 -080046}
47
Peiyong Lin5851c3a2022-10-18 20:47:56 +000048ScopedAStatus Power::isModeSupported(Mode type, bool* _aidl_return) {
Wei Wang61c2a332020-01-08 16:51:47 -080049 LOG(INFO) << "Power isModeSupported: " << static_cast<int32_t>(type);
Wei Wang05003412021-04-01 10:44:29 -070050 *_aidl_return = type >= MODE_RANGE.front() && type <= MODE_RANGE.back();
Peiyong Lin5851c3a2022-10-18 20:47:56 +000051 return ScopedAStatus::ok();
Wei Wang61c2a332020-01-08 16:51:47 -080052}
53
Peiyong Lin5851c3a2022-10-18 20:47:56 +000054ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) {
Wei Wang61c2a332020-01-08 16:51:47 -080055 LOG(VERBOSE) << "Power setBoost: " << static_cast<int32_t>(type)
56 << ", duration: " << durationMs;
Peiyong Lin5851c3a2022-10-18 20:47:56 +000057 return ScopedAStatus::ok();
Wei Wang61c2a332020-01-08 16:51:47 -080058}
59
Peiyong Lin5851c3a2022-10-18 20:47:56 +000060ScopedAStatus Power::isBoostSupported(Boost type, bool* _aidl_return) {
Wei Wang61c2a332020-01-08 16:51:47 -080061 LOG(INFO) << "Power isBoostSupported: " << static_cast<int32_t>(type);
Wei Wang05003412021-04-01 10:44:29 -070062 *_aidl_return = type >= BOOST_RANGE.front() && type <= BOOST_RANGE.back();
Peiyong Lin5851c3a2022-10-18 20:47:56 +000063 return ScopedAStatus::ok();
Wei Wang61c2a332020-01-08 16:51:47 -080064}
65
Peiyong Lin5851c3a2022-10-18 20:47:56 +000066ScopedAStatus Power::createHintSession(int32_t, int32_t, const std::vector<int32_t>& tids, int64_t,
67 std::shared_ptr<IPowerHintSession>* _aidl_return) {
68 if (tids.size() == 0) {
69 *_aidl_return = nullptr;
70 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
71 }
72 std::shared_ptr<IPowerHintSession> powerHintSession =
73 ndk::SharedRefBase::make<PowerHintSession>();
74 mPowerHintSessions.push_back(powerHintSession);
75 *_aidl_return = powerHintSession;
76 return ScopedAStatus::ok();
Wei Wang05003412021-04-01 10:44:29 -070077}
78
Matt Buckleycaac1472023-12-12 03:55:50 +000079ndk::ScopedAStatus Power::createHintSessionWithConfig(
80 int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds, int64_t durationNanos,
81 SessionTag, SessionConfig* config, std::shared_ptr<IPowerHintSession>* _aidl_return) {
82 auto out = createHintSession(tgid, uid, threadIds, durationNanos, _aidl_return);
83 static_cast<PowerHintSession*>(_aidl_return->get())->getSessionConfig(config);
84 return out;
85}
86
87ndk::ScopedAStatus Power::getSessionChannel(int32_t, int32_t, ChannelConfig* _aidl_return) {
88 static AidlMessageQueue<ChannelMessage, SynchronizedReadWrite> stubQueue{1, true};
89 _aidl_return->channelDescriptor = stubQueue.dupeDesc();
90 _aidl_return->readFlagBitmask = 0;
91 _aidl_return->writeFlagBitmask = 0;
92 _aidl_return->eventFlagDescriptor = std::nullopt;
93 return ndk::ScopedAStatus::ok();
94}
95
96ndk::ScopedAStatus Power::closeSessionChannel(int32_t, int32_t) {
97 return ndk::ScopedAStatus::ok();
98}
99
Peiyong Lin5851c3a2022-10-18 20:47:56 +0000100ScopedAStatus Power::getHintSessionPreferredRate(int64_t* outNanoseconds) {
101 *outNanoseconds = std::chrono::nanoseconds(1ms).count();
102 return ScopedAStatus::ok();
Wei Wang05003412021-04-01 10:44:29 -0700103}
104
Wei Wang61c2a332020-01-08 16:51:47 -0800105} // namespace example
106} // namespace impl
107} // namespace power
108} // namespace hardware
109} // namespace android
110} // namespace aidl