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