• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     LOG(INFO) << "PowerExt mode " << mode << " isModeSupported: " << supported;
61     *_aidl_return = supported;
62     return ndk::ScopedAStatus::ok();
63 }
64 
setBoost(const std::string & boost,int32_t durationMs)65 ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) {
66     LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs;
67     if (HintManager::GetInstance()->GetAdpfProfile() &&
68         HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
69         PowerSessionManager::getInstance()->updateHintBoost(boost, durationMs);
70     }
71 
72     if (durationMs > 0) {
73         HintManager::GetInstance()->DoHint(boost, std::chrono::milliseconds(durationMs));
74     } else if (durationMs == 0) {
75         HintManager::GetInstance()->DoHint(boost);
76     } else {
77         HintManager::GetInstance()->EndHint(boost);
78     }
79 
80     return ndk::ScopedAStatus::ok();
81 }
82 
isBoostSupported(const std::string & boost,bool * _aidl_return)83 ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string &boost, bool *_aidl_return) {
84     bool supported = HintManager::GetInstance()->IsHintSupported(boost);
85     LOG(INFO) << "PowerExt boost " << boost << " isBoostSupported: " << supported;
86     *_aidl_return = supported;
87     return ndk::ScopedAStatus::ok();
88 }
89 
90 }  // namespace pixel
91 }  // namespace impl
92 }  // namespace power
93 }  // namespace hardware
94 }  // namespace google
95 }  // namespace aidl
96