• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 <chrono>
17 #include <mutex>
18 #include <set>
19 #include <string>
20 #include <unistd.h>
21 #include <vector>
22 #include <unordered_set>
23 
24 #include "app_mgr_constants.h"
25 #include "app_mgr_client.h"
26 #include "bundle_mgr_interface.h"
27 #include "iservice_registry.h"
28 #include "nweb_log.h"
29 #include "ohos_adapter_helper.h"
30 #include "res_sched_client.h"
31 #include "res_sched_client_adapter.h"
32 #include "res_type.h"
33 #include "singleton.h"
34 #include "system_ability_definition.h"
35 #include "system_properties_adapter_impl.h"
36 
37 namespace OHOS::NWeb {
38 using namespace OHOS::ResourceSchedule;
39 
40 const std::unordered_map<ResSchedTypeAdapter, uint32_t> RES_TYPE_MAP = {
41     { ResSchedTypeAdapter::RES_TYPE_KEY_THREAD, ResType::RES_TYPE_REPORT_KEY_THREAD },
42     { ResSchedTypeAdapter::RES_TYPE_WEB_STATUS_CHANGE, ResType::RES_TYPE_REPORT_WINDOW_STATE },
43     { ResSchedTypeAdapter::RES_TYPE_WEB_SCENE, ResType::RES_TYPE_REPORT_SCENE_SCHED },
44     { ResSchedTypeAdapter::RES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE, ResType::RES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE },
45     { ResSchedTypeAdapter::RES_TYPE_WEBVIEW_SCREEN_CAPTURE, ResType::RES_TYPE_WEBVIEW_SCREEN_CAPTURE },
46     { ResSchedTypeAdapter::RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE, ResType::RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE },
47 };
48 
49 const std::unordered_map<ResSchedStatusAdapter, int64_t> RES_STATUS_MAP = {
50     { ResSchedStatusAdapter::THREAD_CREATED, ResType::ReportChangeStatus::CREATE },
51     { ResSchedStatusAdapter::THREAD_DESTROYED, ResType::ReportChangeStatus::REMOVE },
52     { ResSchedStatusAdapter::WEB_ACTIVE, ResType::WindowStates::ACTIVE },
53     { ResSchedStatusAdapter::WEB_INACTIVE, ResType::WindowStates::INACTIVE },
54     { ResSchedStatusAdapter::WEB_SCENE_ENTER, ResType::SceneControl::SCENE_IN },
55     { ResSchedStatusAdapter::WEB_SCENE_EXIT, ResType::SceneControl::SCENE_OUT },
56     { ResSchedStatusAdapter::AUDIO_STATUS_START, ResType::AudioStatus::START },
57     { ResSchedStatusAdapter::AUDIO_STATUS_STOP, ResType::AudioStatus::STOP },
58     { ResSchedStatusAdapter::SCREEN_CAPTURE_START, ResType::WebScreenCapture::WEB_SCREEN_CAPTURE_START },
59     { ResSchedStatusAdapter::SCREEN_CAPTURE_STOP, ResType::WebScreenCapture::WEB_SCREEN_CAPTURE_STOP },
60     { ResSchedStatusAdapter::VIDEO_PLAYING_START, ResType::WebVideoState::WEB_VIDEO_PLAYING_START },
61     { ResSchedStatusAdapter::VIDEO_PLAYING_STOP, ResType::WebVideoState::WEB_VIDEO_PLAYING_STOP },
62 };
63 
64 const std::unordered_map<ResSchedRoleAdapter, ResType::ThreadRole> RES_ROLE_MAP = {
65     { ResSchedRoleAdapter::USER_INTERACT, ResType::ThreadRole::USER_INTERACT },
66     { ResSchedRoleAdapter::NORMAL_DISPLAY, ResType::ThreadRole::NORMAL_DISPLAY },
67     { ResSchedRoleAdapter::IMPORTANT_DISPLAY, ResType::ThreadRole::IMPORTANT_DISPLAY },
68     { ResSchedRoleAdapter::NORMAL_AUDIO, ResType::ThreadRole::NORMAL_AUDIO },
69     { ResSchedRoleAdapter::IMPORTANT_AUDIO, ResType::ThreadRole::IMPORTANT_AUDIO },
70     { ResSchedRoleAdapter::IMAGE_DECODE, ResType::ThreadRole::IMAGE_DECODE },
71 };
72 
73 const std::unordered_map<ResSchedSceneAdapter, int32_t> RES_SCENE_MAP = {
74     { ResSchedSceneAdapter::LOAD_URL, ResType::WebScene::WEB_SCENE_LOAD_URL },
75     { ResSchedSceneAdapter::CLICK, ResType::WebScene::WEB_SCENE_CLICK },
76     { ResSchedSceneAdapter::SLIDE, ResType::WebScene::WEB_SCENE_SLIDE },
77     { ResSchedSceneAdapter::RESIZE, ResType::WebScene::WEB_SCENE_RESIZE },
78     { ResSchedSceneAdapter::VISIBLE, ResType::WebScene::WEB_SCENE_VISIBLE },
79     { ResSchedSceneAdapter::KEYBOARD_CLICK, ResType::WebScene::WEB_SCENE_KEYBOARD_CLICK },
80     { ResSchedSceneAdapter::KEY_TASK, ResType::WebScene::WEB_SCENE_KEY_TASK },
81     { ResSchedSceneAdapter::IMAGE_DECODE, ResType::WebScene::WEB_SCENE_IMAGE_DECODE },
82 };
83 
84 const int32_t WEBVIEW_DESTROY = 1010;
85 const int32_t WEBVIEW_DESTROY_ORIGIN = 1007;
86 const int32_t INVALID_NUMBER = -1;
87 const int64_t INVALID_NUMBER_INT64 = -1;
88 const int64_t SLIDE_PERIOD_MS = 300;
89 const pid_t INVALID_PID = -1;
90 constexpr char PID[] = "pid";
91 constexpr char UID[] = "uid";
92 constexpr char TID[] = "tid";
93 constexpr char ROLE[] = "role";
94 constexpr char WINDOW_ID[] = "windowId";
95 constexpr char SERIAL_NUMBER[] = "serialNum";
96 constexpr char SCENE_ID[] = "sceneId";
97 constexpr char STATE[] = "state";
98 std::set<int32_t> g_nwebSet;
99 std::unordered_map<pid_t, std::unordered_map<int32_t, ResSchedStatusAdapter>> g_pidNwebMap;
100 std::unordered_map<int32_t, std::vector<pid_t>> g_nwebProcessMap;
101 std::unordered_set<pid_t> g_processInUse;
102 std::mutex g_windowIdMutex {};
103 int32_t g_windowId = INVALID_NUMBER;
104 int32_t g_nwebId = INVALID_NUMBER;
105 pid_t g_lastPid = INVALID_PID;
106 int64_t g_lastStatus = INVALID_NUMBER_INT64;
107 int64_t g_timeStamp = 0;
108 int64_t g_preTimeStamp = 0;
109 pid_t g_lastRenderPid = INVALID_PID;
110 int64_t g_lastRenderStatus = INVALID_NUMBER_INT64;
111 bool g_siteIsolationMode = false;
112 
GetUidString()113 std::string GetUidString()
114 {
115     static std::string uidString = std::to_string(getuid());
116     return uidString;
117 }
118 
GetBundleNameByUid(int32_t uid)119 std::string GetBundleNameByUid(int32_t uid)
120 {
121     sptr<ISystemAbilityManager> systemAbilityManager =
122         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
123     if (systemAbilityManager == nullptr) {
124         WVLOG_E("get SystemAbilityManager failed");
125         return "";
126     }
127     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
128     if (remoteObject == nullptr) {
129         WVLOG_E("get Bundle Manager failed");
130         return "";
131     }
132     auto bundleMgr = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
133     if (bundleMgr == nullptr) {
134         return "";
135     }
136     std::string bundle {""};
137     bundleMgr->GetNameForUid(uid, bundle);
138     return bundle;
139 }
140 
ConvertStatus(ResSchedStatusAdapter statusAdapter,int64_t & status)141 bool ConvertStatus(ResSchedStatusAdapter statusAdapter, int64_t& status)
142 {
143     if (auto it = RES_STATUS_MAP.find(statusAdapter); it == RES_STATUS_MAP.end()) {
144         WVLOG_E("invalid status: %{public}d", statusAdapter);
145         return false;
146     } else {
147         status = it->second;
148     }
149     return true;
150 }
151 
NeedReportScene(ResSchedSceneAdapter sceneAdapter)152 bool NeedReportScene(ResSchedSceneAdapter sceneAdapter)
153 {
154     if (sceneAdapter != ResSchedSceneAdapter::SLIDE) {
155         return true;
156     }
157     auto currentTime = std::chrono::system_clock::now().time_since_epoch();
158     g_timeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime).count();
159     if (g_timeStamp - g_preTimeStamp > SLIDE_PERIOD_MS) {
160         g_preTimeStamp = g_timeStamp;
161         return true;
162     }
163     return false;
164 }
165 
ReportSceneInternal(ResSchedStatusAdapter statusAdapter,ResSchedSceneAdapter sceneAdapter)166 bool ReportSceneInternal(ResSchedStatusAdapter statusAdapter, ResSchedSceneAdapter sceneAdapter)
167 {
168     // To limit the frequency of events reported in some scenarios
169     if(!NeedReportScene(sceneAdapter)) {
170         return false;
171     }
172 
173     int64_t status;
174     bool ret = ConvertStatus(statusAdapter, status);
175     if (!ret) {
176         return false;
177     }
178 
179     int32_t sceneId;
180     if (auto it = RES_SCENE_MAP.find(sceneAdapter); it == RES_SCENE_MAP.end()) {
181         WVLOG_E("invalid scene id: %{public}d", sceneAdapter);
182         return false;
183     } else {
184         sceneId = it->second;
185     }
186 
187     auto& systemPropertiesAdapter = OhosAdapterHelper::GetInstance().GetSystemPropertiesInstance();
188     auto deviceType = systemPropertiesAdapter.GetProductDeviceType();
189     if (deviceType == ProductDeviceType::DEVICE_TYPE_2IN1 && sceneId == WEBVIEW_DESTROY_ORIGIN) {
190         sceneId = WEBVIEW_DESTROY;
191     }
192     std::unordered_map<std::string, std::string> mapPayload { { UID, GetUidString() },
193         { SCENE_ID, std::to_string(sceneId) } };
194     ResSchedClient::GetInstance().ReportData(ResType::RES_TYPE_REPORT_SCENE_SCHED, status, mapPayload);
195     WVLOG_D("ReportScene status: %{public}d, uid: %{public}s, sceneId: %{public}d", static_cast<int32_t>(status),
196         GetUidString().c_str(), sceneId);
197     return true;
198 }
199 
IsSameSourceWebSiteActive(ResSchedStatusAdapter statusAdapter,pid_t pid,int32_t nwebId)200 bool IsSameSourceWebSiteActive(ResSchedStatusAdapter statusAdapter, pid_t pid, int32_t nwebId)
201 {
202     static std::mutex initMutex;
203     std::lock_guard<std::mutex> lock(initMutex);
204     g_pidNwebMap[pid][nwebId] = statusAdapter;
205     if (statusAdapter == ResSchedStatusAdapter::WEB_INACTIVE) {
206         auto nwebMap = g_pidNwebMap[pid];
207         for (auto it : nwebMap) {
208             if (it.second == ResSchedStatusAdapter::WEB_ACTIVE) {
209                 WVLOG_D("IsSameSourceWebSiteActive, current nwebId: %{public}d, active nwebId: %{public}d, "
210                         "pid: %{public}d", nwebId, it.first, pid);
211                 return true;
212             }
213         }
214         g_pidNwebMap.erase(pid);
215     }
216     return false;
217 }
218 
ReportStatusData(ResSchedStatusAdapter statusAdapter,pid_t pid,uint32_t windowId,int32_t nwebId,bool isSiteManage)219 void ReportStatusData(ResSchedStatusAdapter statusAdapter,
220                       pid_t pid, uint32_t windowId, int32_t nwebId, bool isSiteManage)
221 {
222     static uint32_t serialNum = 0;
223     static constexpr uint32_t serialNumMax = 10000;
224 
225     static std::mutex initMutex;
226     std::lock_guard<std::mutex> lock(initMutex);
227     if (g_nwebSet.find(nwebId) == g_nwebSet.end() || pid == 0) {
228         WVLOG_D("Don't report window status, nwebId: %{public}d, pid: %{public}d", nwebId, pid);
229         return;
230     }
231 
232     int64_t status;
233     bool ret = ConvertStatus(statusAdapter, status);
234     if (!ret) {
235         return;
236     }
237 
238     ProductDeviceType deviceType = SystemPropertiesAdapterImpl::GetInstance().GetProductDeviceType();
239     if (deviceType == ProductDeviceType::DEVICE_TYPE_MOBILE || g_processInUse.count(pid)) {
240         if (isSiteManage && IsSameSourceWebSiteActive(statusAdapter, pid, nwebId)) {
241             return;
242         }
243     }
244 
245     if (pid == g_lastPid && status == g_lastStatus) {
246         return;
247     }
248     g_lastPid = pid;
249     g_lastStatus = status;
250 
251     std::unordered_map<std::string, std::string> mapPayload { { UID, GetUidString() }, { PID, std::to_string(pid) },
252         { WINDOW_ID, std::to_string(windowId) }, { SERIAL_NUMBER, std::to_string(serialNum) },
253         { STATE, std::to_string(status) } };
254     ResSchedClient::GetInstance().ReportData(
255         ResType::RES_TYPE_REPORT_WINDOW_STATE, ResType::ReportChangeStatus::CREATE, mapPayload);
256 
257     WVLOG_D("ReportWindowStatus status: %{public}d, uid: %{public}s, pid: %{public}d, windowId: %{public}d, "
258             "nwebId: %{public}d, sn: %{public}d",
259             static_cast<int32_t>(status), GetUidString().c_str(), pid, windowId, nwebId, serialNum);
260     serialNum = (serialNum + 1) % serialNumMax;
261 
262     // Report visible scene event again when tab becomes active to solve timing problem
263     if (statusAdapter == ResSchedStatusAdapter::WEB_ACTIVE) {
264         ReportSceneInternal(statusAdapter, ResSchedSceneAdapter::VISIBLE);
265     }
266 }
267 
ReportKeyThread(ResSchedStatusAdapter statusAdapter,pid_t pid,pid_t tid,ResSchedRoleAdapter roleAdapter)268 bool ResSchedClientAdapter::ReportKeyThread(
269     ResSchedStatusAdapter statusAdapter, pid_t pid, pid_t tid, ResSchedRoleAdapter roleAdapter)
270 {
271     static std::mutex initMutex;
272     std::lock_guard<std::mutex> lock(initMutex);
273     int64_t status;
274     bool ret = ConvertStatus(statusAdapter, status);
275     if (!ret) {
276         return false;
277     }
278 
279     ResType::ThreadRole role;
280     if (auto it = RES_ROLE_MAP.find(roleAdapter); it == RES_ROLE_MAP.end()) {
281         WVLOG_E("invalid role: %{public}d", roleAdapter);
282         return false;
283     } else {
284         role = it->second;
285     }
286 
287     std::unordered_map<std::string, std::string> mapPayload { { UID, GetUidString() }, { PID, std::to_string(pid) },
288         { TID, std::to_string(tid) }, { ROLE, std::to_string(role) } };
289 
290     // Report process creation event first when render process is created
291     if (pid == tid) {
292         mapPayload["processType"] = std::to_string(static_cast<uint32_t>(AppExecFwk::ProcessType::RENDER));
293         mapPayload["bundleName"] = GetBundleNameByUid(getuid());
294     }
295 
296     ResSchedClient::GetInstance().ReportData(ResType::RES_TYPE_REPORT_KEY_THREAD, status, mapPayload);
297     WVLOG_D("ReportKeyThread status: %{public}d, uid: %{public}s, pid: %{public}d, tid:%{public}d, role: %{public}d",
298         static_cast<int32_t>(status), GetUidString().c_str(), pid, tid, static_cast<int32_t>(role));
299 
300     if (pid == tid && g_windowId != INVALID_NUMBER && g_nwebId != INVALID_NUMBER) {
301         std::lock_guard<std::mutex> lock(g_windowIdMutex);
302         ReportStatusData(ResSchedStatusAdapter::WEB_ACTIVE, pid, g_windowId, g_nwebId, false);
303     }
304 
305     if (pid == tid && statusAdapter == ResSchedStatusAdapter::THREAD_DESTROYED) {
306         g_processInUse.erase(pid);
307     }
308 
309     // Load url may create new render process, repeat report load url event when
310     // render key thread create to solve timing problem. Later events will overwrite previous events
311     if (statusAdapter == ResSchedStatusAdapter::THREAD_CREATED && pid != getprocpid()) {
312         ReportSceneInternal(statusAdapter, ResSchedSceneAdapter::LOAD_URL);
313     }
314     return true;
315 }
316 
ReportAudioData(ResSchedStatusAdapter statusAdapter,pid_t pid,pid_t tid)317 bool ResSchedClientAdapter::ReportAudioData(ResSchedStatusAdapter statusAdapter, pid_t pid, pid_t tid)
318 {
319     static uint32_t resType = ResType::RES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE;
320 
321     int64_t status;
322     if (!ConvertStatus(statusAdapter, status)) {
323         return false;
324     }
325 
326     uid_t uid = getuid();
327     std::unordered_map<std::string, std::string> mapPayload { { UID, std::to_string(uid) },
328         { PID, std::to_string(pid) }, { TID, std::to_string(tid) } };
329     WVLOG_D("ReportAudioData status: %{public}d, uid: %{public}d, pid: %{public}d, tid:%{public}d",
330         static_cast<int32_t>(status), uid, pid, tid);
331     ResSchedClient::GetInstance().ReportData(resType, status, mapPayload);
332 
333     return true;
334 }
335 
ReportProcessInUse(pid_t pid)336 void ResSchedClientAdapter::ReportProcessInUse(pid_t pid)
337 {
338     static std::mutex initMutex;
339     std::lock_guard<std::mutex> lock(initMutex);
340     int32_t nwebId = g_nwebId;
341     if (g_pidNwebMap.count(pid)) {
342         nwebId = g_pidNwebMap[pid].begin()->first;
343     }
344 
345     g_processInUse.insert(pid);
346 
347     if (nwebId != INVALID_NUMBER) {
348         g_nwebProcessMap[nwebId].push_back(pid);
349         WVLOG_D("ReportProcessInUse nwebId: %{public}d, pid: %{public}d", nwebId, pid);
350 
351         if (g_siteIsolationMode) {
352             ReportStatusData(ResSchedStatusAdapter::WEB_ACTIVE, pid, g_windowId, nwebId, true);
353         }
354     }
355 }
356 
ReportSiteIsolationMode(bool mode)357 void ResSchedClientAdapter::ReportSiteIsolationMode(bool mode)
358 {
359     g_siteIsolationMode = mode;
360     WVLOG_D("ReportSiteIsolationMode g_siteIsolationMode: %{public}d", mode);
361 }
362 
ReportWindowStatus(ResSchedStatusAdapter statusAdapter,pid_t pid,uint32_t windowId,int32_t nwebId)363 bool ResSchedClientAdapter::ReportWindowStatus(
364     ResSchedStatusAdapter statusAdapter, pid_t pid, uint32_t windowId, int32_t nwebId)
365 {
366     static std::mutex initMutex;
367     std::lock_guard<std::mutex> lock(initMutex);
368     if (g_nwebSet.find(nwebId) == g_nwebSet.end() || pid == 0) {
369         WVLOG_D("Don't report window status, nwebId: %{public}d, pid: %{public}d", nwebId, pid);
370         return false;
371     }
372 
373     int64_t status;
374     if (!ConvertStatus(statusAdapter, status)) {
375         return false;
376     }
377     if (statusAdapter == ResSchedStatusAdapter::WEB_ACTIVE) {
378         ReportWindowId(windowId, nwebId);
379     }
380 
381     ReportStatusData(statusAdapter, pid, windowId, nwebId, true);
382 
383     ProductDeviceType deviceType = SystemPropertiesAdapterImpl::GetInstance().GetProductDeviceType();
384     if (deviceType == ProductDeviceType::DEVICE_TYPE_TABLET || deviceType == ProductDeviceType::DEVICE_TYPE_2IN1) {
385         for (auto pidInNweb : g_nwebProcessMap[nwebId]) {
386             if (pidInNweb == pid) {
387                 continue;
388             }
389             ReportStatusData(statusAdapter, pidInNweb, windowId, nwebId, true);
390         }
391     }
392 
393     return true;
394 }
395 
ReportScene(ResSchedStatusAdapter statusAdapter,ResSchedSceneAdapter sceneAdapter,int32_t nwebId)396 bool ResSchedClientAdapter::ReportScene(
397     ResSchedStatusAdapter statusAdapter, ResSchedSceneAdapter sceneAdapter, int32_t nwebId)
398 {
399     static std::mutex initMutex;
400     std::lock_guard<std::mutex> lock(initMutex);
401     if (nwebId == -1) {
402         return ReportSceneInternal(statusAdapter, sceneAdapter);
403     }
404 
405     if (g_nwebSet.find(nwebId) == g_nwebSet.end()) {
406         WVLOG_E("ReportScene nwebId %{public}d not exist in render set", nwebId);
407         return false;
408     }
409     return ReportSceneInternal(statusAdapter, sceneAdapter);
410 }
411 
ReportWindowId(int32_t windowId,int32_t nwebId)412 void ResSchedClientAdapter::ReportWindowId(int32_t windowId, int32_t nwebId)
413 {
414     std::lock_guard<std::mutex> lock(g_windowIdMutex);
415     g_windowId = windowId;
416     g_nwebId = nwebId;
417     WVLOG_D("ReportWindowId windowId: %{public}d, nwebId: %{public}d", g_windowId, g_nwebId);
418 }
419 
ReportNWebInit(ResSchedStatusAdapter statusAdapter,int32_t nwebId)420 void ResSchedClientAdapter::ReportNWebInit(ResSchedStatusAdapter statusAdapter, int32_t nwebId)
421 {
422     static std::mutex initMutex;
423     std::lock_guard<std::mutex> lock(initMutex);
424     if (statusAdapter == ResSchedStatusAdapter::WEB_SCENE_ENTER) {
425         WVLOG_D("ReportNWebInit %{public}d", nwebId);
426         g_nwebSet.emplace(nwebId);
427     } else if (statusAdapter == ResSchedStatusAdapter::WEB_SCENE_EXIT) {
428         g_nwebSet.erase(nwebId);
429         g_nwebProcessMap.erase(nwebId);
430         for (auto nwebMap : g_pidNwebMap) {
431             auto it = nwebMap.second.find(nwebId);
432             if (it != nwebMap.second.end()) {
433                 nwebMap.second.erase(it);
434             }
435         }
436     }
437 }
438 
ReportRenderProcessStatus(ResSchedStatusAdapter statusAdapter,pid_t pid)439 void ResSchedClientAdapter::ReportRenderProcessStatus(ResSchedStatusAdapter statusAdapter, pid_t pid)
440 {
441     int64_t status;
442     bool ret = ConvertStatus(statusAdapter, status);
443     if (!ret) {
444         WVLOG_E("ReportRenderProcessStatus get appMgrClient failed");
445         return;
446     }
447 
448     if (pid == g_lastRenderPid && status == g_lastRenderStatus) {
449         WVLOG_D("ReportRenderProcessStatus same status and process");
450         return;
451     }
452     g_lastRenderPid = pid;
453     g_lastRenderStatus = status;
454 
455     auto appMgrClient = DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance();
456     if (appMgrClient == nullptr) {
457         WVLOG_E("ReportRenderProcessStatus get appMgrClient failed");
458         return;
459     }
460     appMgrClient->UpdateRenderState(pid, status);
461     WVLOG_D("ReportRenderProcessStatus status: %{public}d, pid: %{public}d", static_cast<int32_t>(status), pid);
462 }
463 
ReportScreenCapture(ResSchedStatusAdapter statusAdapter,pid_t pid)464 bool ResSchedClientAdapter::ReportScreenCapture(ResSchedStatusAdapter statusAdapter, pid_t pid)
465 {
466     static uint32_t resType = ResType::RES_TYPE_WEBVIEW_SCREEN_CAPTURE;
467 
468     int64_t status;
469     if (!ConvertStatus(statusAdapter, status)) {
470         return false;
471     }
472 
473     uid_t uid = getuid();
474     std::unordered_map<std::string, std::string> mapPayload { { UID, std::to_string(uid) },
475         { PID, std::to_string(pid) } };
476     WVLOG_D("ReportScreenCapture status: %{public}d, uid: %{public}d, pid: %{public}d",
477         static_cast<int32_t>(status), uid, pid);
478     ResSchedClient::GetInstance().ReportData(resType, status, mapPayload);
479 
480     return true;
481 }
482 
ReportVideoPlaying(ResSchedStatusAdapter statusAdapter,pid_t pid)483 bool ResSchedClientAdapter::ReportVideoPlaying(ResSchedStatusAdapter statusAdapter, pid_t pid)
484 {
485     static uint32_t resType = ResType::RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE;
486 
487     int64_t status;
488     if (!ConvertStatus(statusAdapter, status)) {
489         return false;
490     }
491 
492     uid_t uid = getuid();
493     std::unordered_map<std::string, std::string> mapPayload { { UID, std::to_string(uid) },
494         { PID, std::to_string(pid) } };
495     WVLOG_D("ReportVideoPlaying status: %{public}d, uid: %{public}d, pid: %{public}d",
496         static_cast<int32_t>(status), uid, pid);
497     ResSchedClient::GetInstance().ReportData(resType, status, mapPayload);
498 
499     return true;
500 }
501 } // namespace OHOS::NWeb
502