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