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