blob: 8fe370c3e4b1f551583a20826dd293c7205a1ab0 [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>
21
22namespace aidl {
23namespace android {
24namespace hardware {
25namespace power {
26namespace impl {
27namespace example {
28
Peiyong Lin5851c3a2022-10-18 20:47:56 +000029using namespace std::chrono_literals;
30
31using ndk::ScopedAStatus;
32
Wei Wang05003412021-04-01 10:44:29 -070033const std::vector<Boost> BOOST_RANGE{ndk::enum_range<Boost>().begin(),
34 ndk::enum_range<Boost>().end()};
35const std::vector<Mode> MODE_RANGE{ndk::enum_range<Mode>().begin(), ndk::enum_range<Mode>().end()};
36
Peiyong Lin5851c3a2022-10-18 20:47:56 +000037ScopedAStatus Power::setMode(Mode type, bool enabled) {
Wei Wang61c2a332020-01-08 16:51:47 -080038 LOG(VERBOSE) << "Power setMode: " << static_cast<int32_t>(type) << " to: " << enabled;
Peiyong Lin5851c3a2022-10-18 20:47:56 +000039 return ScopedAStatus::ok();
Wei Wang61c2a332020-01-08 16:51:47 -080040}
41
Peiyong Lin5851c3a2022-10-18 20:47:56 +000042ScopedAStatus Power::isModeSupported(Mode type, bool* _aidl_return) {
Wei Wang61c2a332020-01-08 16:51:47 -080043 LOG(INFO) << "Power isModeSupported: " << static_cast<int32_t>(type);
Wei Wang05003412021-04-01 10:44:29 -070044 *_aidl_return = type >= MODE_RANGE.front() && type <= MODE_RANGE.back();
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::setBoost(Boost type, int32_t durationMs) {
Wei Wang61c2a332020-01-08 16:51:47 -080049 LOG(VERBOSE) << "Power setBoost: " << static_cast<int32_t>(type)
50 << ", duration: " << durationMs;
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::isBoostSupported(Boost type, bool* _aidl_return) {
Wei Wang61c2a332020-01-08 16:51:47 -080055 LOG(INFO) << "Power isBoostSupported: " << static_cast<int32_t>(type);
Wei Wang05003412021-04-01 10:44:29 -070056 *_aidl_return = type >= BOOST_RANGE.front() && type <= BOOST_RANGE.back();
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::createHintSession(int32_t, int32_t, const std::vector<int32_t>& tids, int64_t,
61 std::shared_ptr<IPowerHintSession>* _aidl_return) {
62 if (tids.size() == 0) {
63 *_aidl_return = nullptr;
64 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
65 }
66 std::shared_ptr<IPowerHintSession> powerHintSession =
67 ndk::SharedRefBase::make<PowerHintSession>();
68 mPowerHintSessions.push_back(powerHintSession);
69 *_aidl_return = powerHintSession;
70 return ScopedAStatus::ok();
Wei Wang05003412021-04-01 10:44:29 -070071}
72
Peiyong Lin5851c3a2022-10-18 20:47:56 +000073ScopedAStatus Power::getHintSessionPreferredRate(int64_t* outNanoseconds) {
74 *outNanoseconds = std::chrono::nanoseconds(1ms).count();
75 return ScopedAStatus::ok();
Wei Wang05003412021-04-01 10:44:29 -070076}
77
Wei Wang61c2a332020-01-08 16:51:47 -080078} // namespace example
79} // namespace impl
80} // namespace power
81} // namespace hardware
82} // namespace android
83} // namespace aidl