• 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     threadHandler_->PostTask([pid, uid, bundleName, state] {
95         IntelliSenseServer::GetInstance().ReportAppInfo(pid, uid, bundleName, state);
96     });
97 }
98 
ReportProcessInfo(const int pid,const int uid,const std::string bundleName,ThreadState state)99 void FrameMsgIntf::ReportProcessInfo(const int pid, const int uid, const std::string bundleName, ThreadState state)
100 {
101     std::lock_guard<std::mutex> autoLock(frameMsgIntfMutex_);
102     if (threadHandler_ == nullptr) {
103         RME_LOGI("[ReportProcessInfo]:threandHandler none!");
104         return;
105     }
106     threadHandler_->PostTask([pid, uid, bundleName, state] {
107         IntelliSenseServer::GetInstance().ReportProcessInfo(pid, uid, bundleName, state);
108     });
109 }
110 
ReportCgroupChange(const int pid,const int uid,const int oldGroup,const int newGroup)111 void FrameMsgIntf::ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup)
112 {
113     std::lock_guard<std::mutex> autoLock(frameMsgIntfMutex_);
114     if (threadHandler_ == nullptr) {
115         RME_LOGI("[ReportProcessInfo]:threandHandler none!");
116         return;
117     }
118     threadHandler_->PostTask([pid, uid, oldGroup, newGroup] {
119         IntelliSenseServer::GetInstance().ReportCgroupChange(pid, uid, oldGroup, newGroup);
120     });
121 }
122 
Stop()123 void FrameMsgIntf::Stop()
124 {
125     std::lock_guard<std::mutex> autoLock(frameMsgIntfMutex_);
126     if (threadHandler_ != nullptr) {
127         threadHandler_->RemoveAllEvents();
128         threadHandler_ = nullptr;
129     }
130     if (runner_ != nullptr) {
131         runner_->Stop();
132         runner_ = nullptr;
133     }
134 }
135 } // namespace RME
136 } // namespace OHOS
137 
138