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 "ffrt_inner.h"
18 #include "intellisense_server.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
~FrameMsgIntf()31 FrameMsgIntf::~FrameMsgIntf()
32 {
33 if (taskQueue_ != nullptr) {
34 delete taskQueue_;
35 taskQueue_ = nullptr;
36 }
37 }
38
Init()39 bool FrameMsgIntf::Init()
40 {
41 std::lock_guard<ffrt::mutex> autoLock(frameMsgIntfMutex_);
42 RME_LOGI("init begin!");
43 if (!GetThreadQueue()) {
44 return false;
45 }
46 taskQueue_->submit([] {
47 IntelliSenseServer::GetInstance().Init();
48 });
49 return true;
50 }
51
GetThreadQueue()52 bool FrameMsgIntf::GetThreadQueue()
53 {
54 if (taskQueue_ == nullptr) {
55 taskQueue_ = new(ffrt::queue)("frame_aware_sched_msg_queue",
56 ffrt::queue_attr().qos(ffrt::qos_user_interactive));
57 if (taskQueue_ == nullptr) {
58 RME_LOGE("failed to create taskQueue!");
59 return false;
60 }
61 }
62 RME_LOGI("Init process success!");
63 return true;
64 }
65
ReportWindowFocus(const int pid,const int uid,const int isFocus)66 void FrameMsgIntf::ReportWindowFocus(const int pid, const int uid, const int isFocus)
67 {
68 std::lock_guard<ffrt::mutex> autoLock(frameMsgIntfMutex_);
69 if (taskQueue_ == nullptr) {
70 RME_LOGE("[ReportWindowFocus]:taskQueue none!");
71 return;
72 }
73 taskQueue_->submit([pid, uid, isFocus] {
74 IntelliSenseServer::GetInstance().ReportWindowFocus(pid, uid, isFocus);
75 });
76 }
77
ReportRenderThread(const int pid,const int uid,const int renderTid)78 void FrameMsgIntf::ReportRenderThread(const int pid, const int uid, const int renderTid)
79 {
80 std::lock_guard<ffrt::mutex> autoLock(frameMsgIntfMutex_);
81 RME_LOGI("[ReportRenderThread]:render get %{public}d with render %{pubilc}d", pid, renderTid);
82 if (taskQueue_ == nullptr) {
83 RME_LOGE("[ReportRenderThread]:taskQueue none!");
84 return;
85 }
86 taskQueue_->submit([pid, uid, renderTid] {
87 IntelliSenseServer::GetInstance().ReportRenderThread(pid, uid, renderTid);
88 });
89 }
90
ReportAppInfo(const int pid,const int uid,const std::string bundleName,ThreadState state)91 void FrameMsgIntf::ReportAppInfo(const int pid, const int uid, const std::string bundleName, ThreadState state)
92 {
93 std::lock_guard<ffrt::mutex> autoLock(frameMsgIntfMutex_);
94 if (taskQueue_ == nullptr) {
95 RME_LOGI("[ReportAppInfo]:taskQueue none!");
96 return;
97 }
98 RME_LOGI("ReportProcessInfo pid is %{public}d, uid is %{public}d", pid, uid);
99 taskQueue_->submit([pid, uid, bundleName, state] {
100 IntelliSenseServer::GetInstance().ReportAppInfo(pid, uid, bundleName, state);
101 });
102 }
103
ReportProcessInfo(const int pid,const int uid,const std::string bundleName,ThreadState state)104 void FrameMsgIntf::ReportProcessInfo(const int pid, const int uid, const std::string bundleName, ThreadState state)
105 {
106 std::lock_guard<ffrt::mutex> autoLock(frameMsgIntfMutex_);
107 if (taskQueue_ == nullptr) {
108 RME_LOGI("[ReportProcessInfo]:taskQueue none!");
109 return;
110 }
111 taskQueue_->submit([pid, uid, bundleName, state] {
112 IntelliSenseServer::GetInstance().ReportProcessInfo(pid, uid, bundleName, state);
113 });
114 }
115
ReportCgroupChange(const int pid,const int uid,const int oldGroup,const int newGroup)116 void FrameMsgIntf::ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup)
117 {
118 std::lock_guard<ffrt::mutex> autoLock(frameMsgIntfMutex_);
119 if (taskQueue_ == nullptr) {
120 RME_LOGI("[ReportProcessInfo]:taskQueue none!");
121 return;
122 }
123 RME_LOGI("CgroupChanged pid is %{public}d, uid is %{public}d, oldGroup is %{public}d, newGroup is %{public}d",
124 pid, uid, oldGroup, newGroup);
125 taskQueue_->submit([pid, uid, oldGroup, newGroup] {
126 IntelliSenseServer::GetInstance().ReportCgroupChange(pid, uid, oldGroup, newGroup);
127 });
128 }
129
ReportContinuousTask(const int pid,const int uid,const int status)130 void FrameMsgIntf::ReportContinuousTask(const int pid, const int uid, const int status)
131 {
132 std::lock_guard<ffrt::mutex> autoLock(frameMsgIntfMutex_);
133 if (taskQueue_ == nullptr) {
134 RME_LOGI("[ReportProcessInfo]:taskQueue none!");
135 return;
136 }
137 taskQueue_->submit([pid, uid, status] {
138 IntelliSenseServer::GetInstance().ReportContinuousTask(pid, uid, status);
139 });
140 }
141
ReportSlideEvent(const int pid,const int uid,const int64_t status)142 void FrameMsgIntf::ReportSlideEvent(const int pid, const int uid, const int64_t status)
143 {
144 return;
145 }
146
Stop()147 void FrameMsgIntf::Stop()
148 {
149 return;
150 }
151 } // namespace RME
152 } // namespace OHOS
153
154