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     void ReportData(uint32_t resType, int64_t value, const nlohmann::json& payload) override;
30 
31     int32_t ReportSyncEvent(const uint32_t resType, const int64_t value, const nlohmann::json& payload,
32         nlohmann::json& reply) override;
33 
34     int32_t KillProcess(const nlohmann::json& payload) override;
35 
36     void RegisterSystemloadNotifier(const sptr<IRemoteObject>& notifier) override;
37 
38     void UnRegisterSystemloadNotifier() override;
39 
40     void RegisterEventListener(const sptr<IRemoteObject>& eventListener, uint32_t eventType,
41         uint32_t listenerGroup) override;
42 
43     void UnRegisterEventListener(uint32_t eventType, uint32_t listenerGroup) override;
44 
45     int32_t GetSystemloadLevel() override;
46 
47     void OnDeviceLevelChanged(int32_t type, int32_t level);
48 
49     bool IsAllowedAppPreload(const std::string& bundleName, int32_t preloadMode) override;
50 
51     void LoadAppPreloadPlugin();
52 
53     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
54 
55     void DumpProcessRunningLock(std::string& result);
56 
57     void DumpProcessWindowInfo(std::string &result);
58 
59     void DumpProcessEventState(std::string &result);
60 
61     void DumpSystemLoadInfo(std::string &result);
62 
63     void DumpAllPluginConfig(std::string &result);
64 
65 private:
66     DISALLOW_COPY_AND_MOVE(ResSchedService);
67 
68     void DumpAllInfo(std::string &result);
69     void DumpUsage(std::string &result);
70     void DumpExt(const std::vector<std::string>& argsInStr, std::string &result);
71     void DumpExecutorDebugCommand(const std::vector<std::string>& args, std::string& result);
72     bool AllowDump();
73 
74     OnIsAllowedAppPreloadFunc appPreloadFunc_ = nullptr;
75     bool isLoadAppPreloadPlugin_ = false;
76 };
77 } // namespace ResourceSchedule
78 } // namespace OHOS
79 
80 #endif // RESSCHED_SERVICES_RESSCHEDSERVICE_INCLUDE_RES_SCHED_SERVICE_H
81