• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_CGROUP_EVENT_HANDLER_H_
17 #define CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_CGROUP_EVENT_HANDLER_H_
18 
19 #include <sys/types.h>
20 #include "ffrt.h"
21 #include "ffrt_inner.h"
22 #include "nlohmann/json.hpp"
23 #include "supervisor.h"
24 
25 namespace OHOS {
26 namespace ResourceSchedule {
27 using OHOS::AppExecFwk::ProcessData;
28 
29 class CgroupEventHandler {
30 public:
31     explicit CgroupEventHandler(const std::string &queueName);
32     ~CgroupEventHandler();
33     void ProcessEvent(uint32_t eventId, int64_t eventParam);
34     void SetSupervisor(std::shared_ptr<Supervisor> supervisor);
35     void HandleAbilityAdded(int32_t saId, const std::string& deviceId);
36     void HandleAbilityRemoved(int32_t saId, const std::string& deviceId);
37     void HandleApplicationStateChanged(uint32_t resType, int64_t value, const nlohmann::json& payload);
38     void HandleProcessStateChangedEx(uint32_t resType, int64_t value, const nlohmann::json& payload);
39     void HandleProcessStateChanged(uint32_t resType, int64_t value, const nlohmann::json& payload);
40     void HandleAbilityStateChanged(uint32_t resType, int64_t value, const nlohmann::json& payload);
41     void HandleExtensionStateChanged(uint32_t resType, int64_t value, const nlohmann::json& payload);
42     void HandleProcessCreated(uint32_t resType, int64_t value, const nlohmann::json& payload);
43     void HandleProcessDied(uint32_t resType, int64_t value, const nlohmann::json& payload);
44     void HandleTransientTaskStatus(uint32_t resType, int64_t value, const nlohmann::json& payload);
45     void HandleTransientTaskStart(uid_t uid, pid_t pid, const std::string& packageName);
46     void HandleTransientTaskEnd(uid_t uid, pid_t pid, const std::string& packageName);
47     void HandleContinuousTaskStatus(uint32_t resType, int64_t value, const nlohmann::json& payload);
48     void HandleContinuousTaskCancel(uid_t uid, pid_t pid, int32_t abilityId);
49     void HandleContinuousTaskUpdate(
50         uid_t uid, pid_t pid, const std::vector<uint32_t>& typeIds, int32_t abilityId);
51     void HandleFocusStateChange(uint32_t resType, int64_t value, const nlohmann::json& payload);
52     void HandleFocusedWindow(uint32_t windowId, uint32_t windowType, uint64_t displayId,
53         int32_t pid, int32_t uid);
54     void HandleUnfocusedWindow(uint32_t windowId, uint32_t windowType, uint64_t displayId,
55         int32_t pid, int32_t uid);
56     void HandleWindowVisibilityChanged(uint32_t resType, int64_t value, const nlohmann::json& payload);
57     void HandleDrawingContentChangeWindow(uint32_t resType, int64_t value, const nlohmann::json& payload);
58     void HandleReportMMIProcess(uint32_t resType, int64_t value, const nlohmann::json& payload);
59     void HandleReportRenderThread(uint32_t resType, int64_t value, const nlohmann::json& payload);
60     void HandleReportKeyThread(uint32_t resType, int64_t value, const nlohmann::json& payload);
61     void HandleReportWindowState(uint32_t resType, int64_t value, const nlohmann::json& payload);
62     void HandleReportAudioState(uint32_t resType, int64_t value, const nlohmann::json& payload);
63     void HandleReportWebviewAudioState(uint32_t resType, int64_t value, const nlohmann::json& payload);
64     void HandleReportBluetoothConnectState(uint32_t resType, int64_t value, const nlohmann::json& payload);
65     void HandleMmiInputState(uint32_t resType, int64_t value, const nlohmann::json& payload);
66     void HandleReportRunningLockEvent(uint32_t resType, int64_t value, const nlohmann::json& payload);
67     void HandleReportHisysEvent(uint32_t resType, int64_t value, const nlohmann::json& payload);
68     void HandleReportAvCodecEvent(uint32_t resType, int64_t value, const nlohmann::json& payload);
69     void HandleSceneBoardState(uint32_t resType, int64_t value, const nlohmann::json& payload);
70     void HandleWebviewScreenCapture(uint32_t resType, int64_t value, const nlohmann::json& payload);
71     void HandleReportWebviewVideoState(uint32_t resType, int64_t value, const nlohmann::json& payload);
72     void HandleReportScreenCaptureEvent(uint32_t resType, int64_t value, const nlohmann::json& payload);
73     void PostTask(const std::function<void()> task);
74     void PostTask(const std::function<void()> task, const std::string &taskName, const int32_t delayTime);
75     void PostTaskAndWait(const std::function<void()> task);
76     void RemoveTask(const std::string &taskName);
77     void ReportAbilityStatus(uint32_t resType, int64_t value, const nlohmann::json& payload);
78     void UpdateMmiStatus(uint32_t resType, int64_t value, const nlohmann::json& payload);
79     void HandleReportCosmicCubeState(uint32_t resType, int64_t value, const nlohmann::json& payload);
80     void HandleOnAppStopped(uint32_t resType, int64_t value, const nlohmann::json& payload);
81 
82 private:
83     bool CheckVisibilityForRenderProcess(ProcessRecord &pr, ProcessRecord &mainProc);
84     bool GetProcInfoByPayload(int32_t &uid, int32_t &pid, std::shared_ptr<Application>& app,
85         std::shared_ptr<ProcessRecord>& procRecord, const nlohmann::json& payload);
86     bool ParsePayload(int32_t& uid, int32_t& pid, const nlohmann::json& payload);
87     bool ParsePayload(int32_t& uid, int32_t& pid, int32_t& tid, int64_t value, const nlohmann::json& payload);
88     bool ParseValue(int32_t& value, const char* name, const nlohmann::json& payload);
89     bool ParseLongValue(int64_t& value, const char* name, const nlohmann::json& payload);
90     bool ParseString(std::string& value, const char* name, const nlohmann::json& payload);
91     void UpdateActivepWebRenderInfo(int32_t uid, int32_t pid, int32_t windowId, int32_t state,
92         const std::shared_ptr<ProcessRecord>& proc);
93     void HandleEmptyPayloadForCosmicCubeState(uint32_t resType, int64_t value);
94     void HandleUIExtensionAbilityStateChange(uint32_t resType, int64_t value, const nlohmann::json& payload);
95     std::shared_ptr<Supervisor> supervisor_;
96     std::shared_ptr<ffrt::queue> cgroupEventQueue_;
97     std::unordered_map<std::string, ffrt::task_handle> delayTaskMap_;
98     ffrt::mutex delayTaskMapMutex_;
99     int32_t ffrtSwitch_ = 1000; // delayTime transfer to ffrt
100 };
101 } // namespace ResourceSchedule
102 } // namespace OHOS
103 
104 #endif // CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_CGROUP_EVENT_HANDLER_H_
105