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 #include "wm_common.h" 25 26 namespace OHOS { 27 namespace ResourceSchedule { 28 using OHOS::Rosen::WindowType; 29 30 class CgroupEventHandler { 31 public: 32 explicit CgroupEventHandler(const std::string &queueName); 33 ~CgroupEventHandler(); 34 void ProcessEvent(uint32_t eventId, int64_t eventParam); 35 void SetSupervisor(std::shared_ptr<Supervisor> supervisor); 36 void HandleAbilityAdded(int32_t saId, const std::string& deviceId); 37 void HandleAbilityRemoved(int32_t saId, const std::string& deviceId); 38 void HandleApplicationStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state); 39 void HandleProcessStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state); 40 void HandleAbilityStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, 41 const std::string& abilityName, uintptr_t token, int32_t abilityState, int32_t abilityType); 42 void HandleExtensionStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, 43 const std::string& abilityName, uintptr_t token, int32_t extensionState, int32_t abilityType); 44 void HandleProcessCreated(uid_t uid, pid_t pid, int32_t hostPid, int32_t processType, 45 const std::string& bundleName, int32_t extensionType); 46 void HandleProcessDied(uid_t uid, pid_t pid, const std::string& bundleName); 47 void HandleTransientTaskStart(uid_t uid, pid_t pid, const std::string& packageName); 48 void HandleTransientTaskEnd(uid_t uid, pid_t pid, const std::string& packageName); 49 void HandleContinuousTaskCancel(uid_t uid, pid_t pid, int32_t typeId, int32_t abilityId); 50 void HandleContinuousTaskUpdate( 51 uid_t uid, pid_t pid, const std::vector<uint32_t>& typeIds, int32_t abilityId); 52 void HandleFocusedWindow(uint32_t windowId, uintptr_t abilityToken, 53 WindowType windowType, uint64_t displayId, int32_t pid, int32_t uid); 54 void HandleUnfocusedWindow(uint32_t windowId, uintptr_t abilityToken, 55 WindowType windowType, uint64_t displayId, int32_t pid, int32_t uid); 56 void HandleWindowVisibilityChanged(uint32_t windowId, uint32_t visibilityState, 57 WindowType windowType, int32_t pid, int32_t uid); 58 void HandleDrawingContentChangeWindow(uint32_t windowId, WindowType windowType, 59 bool drawingContentState, int32_t pid, int32_t uid); 60 void HandleReportMMIProcess(uint32_t resType, int64_t value, const nlohmann::json& payload); 61 void HandleReportRenderThread(uint32_t resType, int64_t value, const nlohmann::json& payload); 62 void HandleReportKeyThread(uint32_t resType, int64_t value, const nlohmann::json& payload); 63 void HandleReportWindowState(uint32_t resType, int64_t value, const nlohmann::json& payload); 64 void HandleReportAudioState(uint32_t resType, int64_t value, const nlohmann::json& payload); 65 void HandleReportWebviewAudioState(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 HandleReportScreenCaptureEvent(uint32_t resType, int64_t value, const nlohmann::json& payload); 72 void HandleReportWebviewVideoState(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 RemoveTask(const std::string &taskName); 76 77 private: 78 bool CheckVisibilityForRenderProcess(ProcessRecord &pr, ProcessRecord &mainProc); 79 bool GetProcInfoByPayload(int32_t &uid, int32_t &pid, std::shared_ptr<Application>& app, 80 std::shared_ptr<ProcessRecord>& procRecord, const nlohmann::json& payload); 81 bool ParsePayload(int32_t& uid, int32_t& pid, const nlohmann::json& payload); 82 bool ParsePayload(int32_t& uid, int32_t& pid, int32_t& tid, int64_t value, const nlohmann::json& payload); 83 bool ParseValue(int32_t& value, const char* name, const nlohmann::json& payload); 84 void UpdateActivepWebRenderInfo(int32_t uid, int32_t pid, int32_t windowId, int32_t state, 85 const std::shared_ptr<ProcessRecord>& proc); 86 std::shared_ptr<Supervisor> supervisor_; 87 std::shared_ptr<ffrt::queue> cgroupEventQueue_; 88 std::unordered_map<std::string, ffrt::task_handle> delayTaskMap_; 89 ffrt::mutex delayTaskMapMutex_; 90 int32_t ffrtSwitch_ = 1000; // delayTime transfer to ffrt 91 }; 92 } // namespace ResourceSchedule 93 } // namespace OHOS 94 95 #endif // CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_CGROUP_EVENT_HANDLER_H_ 96