• 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 #include "frame_msg_intf.h"
17 #include "intellisense_server.h"
18 #include "event_handler.h"
19 #include "rme_log_domain.h"
20 
21 namespace OHOS {
22 namespace RME {
23 DEFINE_RMELOG_INTELLISENSE("ueaServer-FrameMsgIntf");
24 
GetInstance()25 FrameMsgIntf& FrameMsgIntf::GetInstance()
26 {
27     static FrameMsgIntf instance;
28     return instance;
29 }
30 
Init()31 bool FrameMsgIntf::Init()
32 {
33     std::lock_guard<std::mutex> autoLock(frameMsgIntfMutex_);
34     RME_LOGI("init begin!");
35     if (!GetThreadHandler()) {
36         return false;
37     }
38     threadHandler_->PostTask([] {
39         IntelliSenseServer::GetInstance().Init();
40     });
41     return true;
42 }
43 
GetThreadHandler()44 bool FrameMsgIntf::GetThreadHandler()
45 {
46     if (threadHandler_ == nullptr) {
47         runner_ = AppExecFwk::EventRunner::Create("frame_aware_sched_msg");
48         if (runner_ == nullptr) {
49             RME_LOGE("failed to create eventRunner!");
50             return false;
51         }
52         threadHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner_);
53         if (threadHandler_ == nullptr) {
54             RME_LOGE("failed to create thread handler!");
55             return false;
56         }
57     }
58     RME_LOGI("Init process success!");
59     return true;
60 }
61 
ReportWindowFocus(const int pid,const int uid,const int isFocus)62 void FrameMsgIntf::ReportWindowFocus(const int pid, const int uid, const int isFocus)
63 {
64     std::lock_guard<std::mutex> autoLock(frameMsgIntfMutex_);
65     if (threadHandler_ == nullptr) {
66         RME_LOGE("[ReportWindowFocus]:threandHandler none!");
67         return;
68     }
69     threadHandler_->PostTask([pid, uid, isFocus] {
70         IntelliSenseServer::GetInstance().ReportWindowFocus(pid, uid, isFocus);
71     });
72 }
73 
ReportRenderThread(const int pid,const int uid,const int renderTid)74 void FrameMsgIntf::ReportRenderThread(const int pid, const int uid, const int renderTid)
75 {
76     std::lock_guard<std::mutex> autoLock(frameMsgIntfMutex_);
77     RME_LOGI("[ReportRenderThread]:render get %{public}d with render %{pubilc}d", pid, renderTid);
78     if (threadHandler_ == nullptr) {
79         RME_LOGE("[ReportRenderThread]:threandHandler none!");
80         return;
81     }
82     threadHandler_->PostTask([pid, uid, renderTid] {
83         IntelliSenseServer::GetInstance().ReportRenderThread(pid, uid, renderTid);
84     });
85 }
86 
ReportAppInfo(const int pid,const int uid,const std::string bundleName,ThreadState state)87 void FrameMsgIntf::ReportAppInfo(const int pid, const int uid, const std::string bundleName, ThreadState state)
88 {
89     std::lock_guard<std::mutex> autoLock(frameMsgIntfMutex_);
90     if (threadHandler_ == nullptr) {
91         RME_LOGI("[ReportAppInfo]:threandHandler none!");
92         return;
93     }
94     RME_LOGI("ReportProcessInfo pid is %{public}d, uid is %{public}d", pid, uid);
95     threadHandler_->PostTask([pid, uid, bundleName, state] {
96         IntelliSenseServer::GetInstance().ReportAppInfo(pid, uid, bundleName, state);
97     });
98 }
99 
ReportProcessInfo(const int pid,const int uid,const std::string bundleName,ThreadState state)100 void FrameMsgIntf::ReportProcessInfo(const int pid, const int uid, const std::string bundleName, ThreadState state)
101 {
102     std::lock_guard<std::mutex> autoLock(frameMsgIntfMutex_);
103     if (threadHandler_ == nullptr) {
104         RME_LOGI("[ReportProcessInfo]:threandHandler none!");
105         return;
106     }
107     threadHandler_->PostTask([pid, uid, bundleName, state] {
108         IntelliSenseServer::GetInstance().ReportProcessInfo(pid, uid, bundleName, state);
109     });
110 }
111 
ReportCgroupChange(const int pid,const int uid,const int oldGroup,const int newGroup)112 void FrameMsgIntf::ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup)
113 {
114     std::lock_guard<std::mutex> autoLock(frameMsgIntfMutex_);
115     if (threadHandler_ == nullptr) {
116         RME_LOGI("[ReportProcessInfo]:threandHandler none!");
117         return;
118     }
119     RME_LOGI("CgroupChanged pid is %{public}d, uid is %{public}d, oldGroup is %{public}d, newGroup is %{public}d",
120         pid, uid, oldGroup, newGroup);
121     threadHandler_->PostTask([pid, uid, oldGroup, newGroup] {
122         IntelliSenseServer::GetInstance().ReportCgroupChange(pid, uid, oldGroup, newGroup);
123     });
124 }
125 
Stop()126 void FrameMsgIntf::Stop()
127 {
128     std::lock_guard<std::mutex> autoLock(frameMsgIntfMutex_);
129     if (threadHandler_ != nullptr) {
130         threadHandler_->RemoveAllEvents();
131         threadHandler_ = nullptr;
132     }
133     if (runner_ != nullptr) {
134         runner_->Stop();
135         runner_ = nullptr;
136     }
137 }
138 } // namespace RME
139 } // namespace OHOS
140 
141