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
17 #define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
18 #define LOG_TAG "android.hardware.power-service.pixel.ext-libperfmgr"
19
20 #include "PowerExt.h"
21
22 #include <mutex>
23
24 #include <android-base/file.h>
25 #include <android-base/logging.h>
26 #include <android-base/properties.h>
27 #include <android-base/stringprintf.h>
28 #include <android-base/strings.h>
29
30 #include <utils/Log.h>
31 #include <utils/Trace.h>
32
33 namespace aidl {
34 namespace google {
35 namespace hardware {
36 namespace power {
37 namespace impl {
38 namespace pixel {
39
setMode(const std::string & mode,bool enabled)40 ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) {
41 LOG(DEBUG) << "PowerExt setMode: " << mode << " to: " << enabled;
42 ATRACE_INT(mode.c_str(), enabled);
43
44 if (enabled) {
45 mHintManager->DoHint(mode);
46 } else {
47 mHintManager->EndHint(mode);
48 }
49
50 return ndk::ScopedAStatus::ok();
51 }
52
isModeSupported(const std::string & mode,bool * _aidl_return)53 ndk::ScopedAStatus PowerExt::isModeSupported(const std::string &mode, bool *_aidl_return) {
54 bool supported = mHintManager->IsHintSupported(mode);
55 LOG(INFO) << "PowerExt mode " << mode << " isModeSupported: " << supported;
56 *_aidl_return = supported;
57 return ndk::ScopedAStatus::ok();
58 }
59
setBoost(const std::string & boost,int32_t durationMs)60 ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) {
61 LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs;
62 ATRACE_INT(boost.c_str(), durationMs);
63
64 if (durationMs > 0) {
65 mHintManager->DoHint(boost, std::chrono::milliseconds(durationMs));
66 } else if (durationMs == 0) {
67 mHintManager->DoHint(boost);
68 } else {
69 mHintManager->EndHint(boost);
70 }
71
72 return ndk::ScopedAStatus::ok();
73 }
74
isBoostSupported(const std::string & boost,bool * _aidl_return)75 ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string &boost, bool *_aidl_return) {
76 bool supported = mHintManager->IsHintSupported(boost);
77 LOG(INFO) << "PowerExt boost " << boost << " isBoostSupported: " << supported;
78 *_aidl_return = supported;
79 return ndk::ScopedAStatus::ok();
80 }
81
82 } // namespace pixel
83 } // namespace impl
84 } // namespace power
85 } // namespace hardware
86 } // namespace google
87 } // namespace aidl
88