• 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 RESSCHED_SERVICES_RESSCHEDSERVICE_INCLUDE_RES_SCHED_SERVICE_H
17 #define RESSCHED_SERVICES_RESSCHEDSERVICE_INCLUDE_RES_SCHED_SERVICE_H
18 
19 #include "plugin_mgr.h"
20 #include "res_sched_service_stub.h"
21 
22 namespace OHOS {
23 namespace ResourceSchedule {
24 class ResSchedService : public ResSchedServiceStub {
25 public:
26     ResSchedService() = default;
27     ~ResSchedService() override = default;
28 
29     ErrCode ReportData(uint32_t resType, int64_t value, const std::string& payload) override;
30 
31     ErrCode ReportSyncEvent(uint32_t resType, int64_t value, const std::string& payload,
32         std::string& reply, int32_t& resultValue) override;
33 
34     ErrCode KillProcess(const std::string& payload, int32_t& resultValue) override;
35 
36     ErrCode RegisterSystemloadNotifier(const sptr<IRemoteObject>& notifier) override;
37 
38     ErrCode UnRegisterSystemloadNotifier() override;
39 
40     ErrCode RegisterEventListener(const sptr<IRemoteObject>& eventListener, uint32_t eventType,
41         uint32_t listenerGroup) override;
42 
43     ErrCode UnRegisterEventListener(uint32_t eventType, uint32_t listenerGroup) override;
44 
45     ErrCode GetSystemloadLevel(int32_t& resultValue) override;
46 
47     void OnDeviceLevelChanged(int32_t type, int32_t level);
48 
49     ErrCode IsAllowedAppPreload(const std::string& bundleName, int32_t preloadMode, bool& resultValue) override;
50 
51     void LoadAppPreloadPlugin();
52 
53     ErrCode IsAllowedLinkJump(bool isAllowedLinkJump, int32_t& resultValue) override;
54 
55     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
56 
57     void DumpSystemLoadInfo(std::string &result);
58 
59     void DumpAllPluginConfig(std::string &result);
60 
61 private:
62     DISALLOW_COPY_AND_MOVE(ResSchedService);
63 
64     void DumpAllInfo(std::string &result);
65     void DumpUsage(std::string &result);
66     void DumpExt(const std::vector<std::string>& argsInStr, std::string &result);
67     void DumpExecutorDebugCommand(const std::vector<std::string>& args, std::string& result);
68     bool AllowDump();
69 
70     nlohmann::json StringToJsonObj(const std::string& str);
71     int32_t CheckReportDataParcel(const uint32_t& type, const int64_t& value, const std::string& payload);
72     bool IsLimitRequest(int32_t uid);
73     void CheckAndUpdateLimitData(int64_t nowTime);
74     void PrintLimitLog(int32_t uid);
75     void ReportBigData();
76     void InreaseBigDataCount();
77     int32_t RemoteRequestCheck();
78 
79     OnIsAllowedAppPreloadFunc appPreloadFunc_ = nullptr;
80     bool isLoadAppPreloadPlugin_ = false;
81     using RequestFuncType = std::function<int32_t (MessageParcel& data, MessageParcel& reply)>;
82     std::map<uint32_t, RequestFuncType> funcMap_;
83     std::map<int32_t, int32_t> appRequestCountMap_;
84     std::atomic<int32_t> allRequestCount_ {0};
85     std::atomic<int32_t> bigDataReportCount_ {0};
86     std::atomic<int64_t> nextCheckTime_ = {0};
87     std::atomic<int64_t> nextReportBigDataTime_ = {0};
88     std::atomic<bool> isReportBigData_ = {false};
89     std::atomic<bool> isPrintLimitLog_ = {true};
90     std::mutex mutex_;
91 };
92 } // namespace ResourceSchedule
93 } // namespace OHOS
94 
95 #endif // RESSCHED_SERVICES_RESSCHEDSERVICE_INCLUDE_RES_SCHED_SERVICE_H
96