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