• 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 "event_handler.h"
21 #include "nlohmann/json.hpp"
22 #include "supervisor.h"
23 #include "wm_common.h"
24 
25 namespace OHOS {
26 namespace ResourceSchedule {
27 using OHOS::AppExecFwk::EventHandler;
28 using OHOS::AppExecFwk::EventRunner;
29 using OHOS::Rosen::WindowType;
30 
31 class CgroupEventHandler : public EventHandler {
32 public:
33     explicit CgroupEventHandler(const std::shared_ptr<EventRunner> &runner);
34     ~CgroupEventHandler();
35     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override;
36     void SetSupervisor(std::shared_ptr<Supervisor> supervisor);
37     void HandleAbilityAdded(int32_t saId, const std::string& deviceId);
38     void HandleAbilityRemoved(int32_t saId, const std::string& deviceId);
39     void HandleForegroundApplicationChanged(uid_t uid, std::string bundleName, int32_t state);
40     void HandleApplicationStateChanged(uid_t uid, std::string bundleName, int32_t state);
41     void HandleAbilityStateChanged(uid_t uid, pid_t pid, std::string bundleName, std::string abilityName,
42         uintptr_t token, int32_t abilityState, int32_t abilityType);
43     void HandleExtensionStateChanged(uid_t uid, pid_t pid, std::string bundleName, std::string abilityName,
44         uintptr_t token, int32_t extensionState, int32_t abilityType);
45     void HandleProcessCreated(uid_t uid, pid_t pid, std::string bundleName);
46     void HandleProcessDied(uid_t uid, pid_t pid, std::string bundleName);
47     void HandleTransientTaskStart(uid_t uid, pid_t pid, std::string packageName);
48     void HandleTransientTaskEnd(uid_t uid, pid_t pid, std::string packageName);
49     void HandleContinuousTaskStart(uid_t uid, pid_t pid, int32_t typeId, std::string abilityName);
50     void HandleContinuousTaskCancel(uid_t uid, pid_t pid, int32_t typeId, std::string abilityName);
51     void HandleFocusedWindow(uint32_t windowId, uintptr_t abilityToken,
52         WindowType windowType, uint64_t displayId, int32_t pid, int32_t uid);
53     void HandleUnfocusedWindow(uint32_t windowId, uintptr_t abilityToken,
54         WindowType windowType, uint64_t displayId, int32_t pid, int32_t uid);
55     void HandleWindowVisibilityChanged(uint32_t windowId, bool isVisible,
56         WindowType windowType, int32_t pid, int32_t uid);
57     void HandleReportMMIProcess(uint32_t resType, int64_t value, const nlohmann::json& payload);
58     void HandleReportRenderThread(uint32_t resType, int64_t value, const nlohmann::json& payload);
59 
60 private:
61     bool ParsePayload(int32_t& uid, int32_t& pid, int32_t& tid, int64_t value, const nlohmann::json& payload);
62     std::shared_ptr<Supervisor> supervisor_;
63 };
64 } // namespace ResourceSchedule
65 } // namespace OHOS
66 
67 #endif // CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_CGROUP_EVENT_HANDLER_H_
68