• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_SERVER_H
17 #define SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_SERVER_H
18 
19 #include "singleton.h"
20 #include "soc_perf_stub.h"
21 #include "socperf.h"
22 #include "system_ability.h"
23 #include "socperf_lru_cache.h"
24 #include "tokenid_kit.h"
25 #include "accesstoken_kit.h"
26 
27 namespace OHOS {
28 namespace SOCPERF {
29     using namespace OHOS::Security;
30 class SocPerfServer : public SystemAbility, public SocPerfStub,
31     public std::enable_shared_from_this<SocPerfServer> {
32 DISALLOW_COPY_AND_MOVE(SocPerfServer);
33 DECLARE_SYSTEM_ABILITY(SocPerfServer);
34 DECLARE_DELAYED_SINGLETON(SocPerfServer);
35 
36 public:
37     /**
38      * @brief Sending a performance request.
39      *
40      * @param cmdId Scene id defined in config file.
41      * @param msg Additional string info, which is used for other extensions.
42      */
43     virtual ErrCode PerfRequest(int32_t cmdId, const std::string& msg) override;
44 
45     /**
46      * @brief Sending a performance request.
47      *
48      * @param cmdId Scene id defined in config file.
49      * @param onOffTag Indicates the start of end of a long-term frequency increase event.
50      * @param msg Additional string info, which is used for other extensions.
51      */
52     virtual ErrCode PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg) override;
53 
54     /**
55      * @brief Sending a power limit boost request.
56      *
57      * @param onOffTag Indicates the start of end of a power limit boost event.
58      * @param msg Additional string info, which is used for other extensions.
59      */
60     virtual ErrCode PowerLimitBoost(bool onOffTag, const std::string& msg) override;
61 
62     /**
63      * @brief Sending a thermal limit boost request.
64      *
65      * @param onOffTag Indicates the start of end of a thermal limit boost event.
66      * @param msg Additional string info, which is used for other extensions.
67      */
68     virtual ErrCode ThermalLimitBoost(bool onOffTag, const std::string& msg) override;
69 
70     /**
71      * @brief Sending a limit request.
72      *
73      * @param clientId Used to indentify the caller of frequency limiting, such as
74      * the thermal module or power consumption module.
75      * @param configs Indicates the specific value to be limited.
76      * @param msg Additional string info, which is used for other extensions.
77      */
78     virtual ErrCode LimitRequest(int32_t clientId,
79         const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg) override;
80 
81     /**
82      * @brief set socperf server status, enable or disable
83      *
84      * @param status true means enable socperfserver, false means disable socperfserver
85      * @param msg the reason why we need change socperfserver status
86      */
87     virtual ErrCode SetRequestStatus(bool status, const std::string& msg) override;
88 
89     /**
90      * @brief set thermal level intermal for perfquest
91      *
92      * @param level thermal level
93      */
94     virtual ErrCode SetThermalLevel(int32_t level) override;
95 
96     /**
97      * @brief send the device mode, enable or disable
98      *
99      * @param mode the mode which will to be changed
100      * @param status true means socperfserver enter the device mode, false quit the device mode
101      */
102     virtual ErrCode RequestDeviceMode(const std::string& mode, bool status) override;
103 
104     /**
105      * @brief get cmd Id count, cmdID is trigger, its count++
106      * @param msg the reason
107      * @param funcResult return cmdId count, as 10000:xx,10001:xx
108      */
109     virtual ErrCode RequestCmdIdCount(const std::string& msg, std::string& funcResult) override;
110     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
111 
112 public:
113     SocPerfServer(int32_t systemAbilityId, bool runOnCreate);
114 
115 protected:
116     void OnStart() override;
117     void OnStop() override;
118 
119 private:
120     SocPerf socPerf;
121     std::mutex permissionCacheMutex_;
122     bool AllowDump();
123     bool HasPerfPermission();
124     SocPerfLRUCache<AccessToken::AccessTokenID, int32_t> permissionCache_;
125 };
126 } // namespace SOCPERF
127 } // namespace OHOS
128 
129 #endif // SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_SERVER_H
130