• 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 "res_sched_client.h"
30 #include "res_sched_client_adapter.h"
31 #include "res_type.h"
32 #include "singleton.h"
33 #include "system_ability_definition.h"
34 #include "system_properties_adapter_impl.h"
35 
36 namespace OHOS::NWeb {
37 using namespace OHOS::ResourceSchedule;
38 
39 const std::unordered_map<ResSchedTypeAdapter, uint32_t> RES_TYPE_MAP = {
40     { ResSchedTypeAdapter::RES_TYPE_KEY_THREAD, ResType::RES_TYPE_REPORT_KEY_THREAD },
41     { ResSchedTypeAdapter::RES_TYPE_WEB_STATUS_CHANGE, ResType::RES_TYPE_REPORT_WINDOW_STATE },
42     { ResSchedTypeAdapter::RES_TYPE_WEB_SCENE, ResType::RES_TYPE_REPORT_SCENE_SCHED },
43     { ResSchedTypeAdapter::RES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE, ResType::RES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE },
44     { ResSchedTypeAdapter::RES_TYPE_WEBVIEW_SCREEN_CAPTURE, ResType::RES_TYPE_WEBVIEW_SCREEN_CAPTURE },
45     { ResSchedTypeAdapter::RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE, ResType::RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE },
46 };
47 
48 const std::unordered_map<ResSchedStatusAdapter, int64_t> RES_STATUS_MAP = {
49     { ResSchedStatusAdapter::THREAD_CREATED, ResType::ReportChangeStatus::CREATE },
50     { ResSchedStatusAdapter::THREAD_DESTROYED, ResType::ReportChangeStatus::REMOVE },
51     { ResSchedStatusAdapter::WEB_ACTIVE, ResType::WindowStates::ACTIVE },
52     { ResSchedStatusAdapter::WEB_INACTIVE, ResType::WindowStates::INACTIVE },
53     { ResSchedStatusAdapter::WEB_SCENE_ENTER, ResType::SceneControl::SCENE_IN },
54     { ResSchedStatusAdapter::WEB_SCENE_EXIT, ResType::SceneControl::SCENE_OUT },
55     { ResSchedStatusAdapter::AUDIO_STATUS_START, ResType::AudioStatus::START },
56     { ResSchedStatusAdapter::AUDIO_STATUS_STOP, ResType::AudioStatus::STOP },
57     { ResSchedStatusAdapter::SCREEN_CAPTURE_START, ResType::WebScreenCapture::WEB_SCREEN_CAPTURE_START },
58     { ResSchedStatusAdapter::SCREEN_CAPTURE_STOP, ResType::WebScreenCapture::WEB_SCREEN_CAPTURE_STOP },
59     { ResSchedStatusAdapter::VIDEO_PLAYING_START, ResType::WebVideoState::WEB_VIDEO_PLAYING_START },
60     { ResSchedStatusAdapter::VIDEO_PLAYING_STOP, ResType::WebVideoState::WEB_VIDEO_PLAYING_STOP },
61 };
62 
63 const std::unordered_map<ResSchedRoleAdapter, ResType::ThreadRole> RES_ROLE_MAP = {
64     { ResSchedRoleAdapter::USER_INTERACT, ResType::ThreadRole::USER_INTERACT },
65     { ResSchedRoleAdapter::NORMAL_DISPLAY, ResType::ThreadRole::NORMAL_DISPLAY },
66     { ResSchedRoleAdapter::IMPORTANT_DISPLAY, ResType::ThreadRole::IMPORTANT_DISPLAY },
67     { ResSchedRoleAdapter::NORMAL_AUDIO, ResType::ThreadRole::NORMAL_AUDIO },
68     { ResSchedRoleAdapter::IMPORTANT_AUDIO, ResType::ThreadRole::IMPORTANT_AUDIO },
69     { ResSchedRoleAdapter::IMAGE_DECODE, ResType::ThreadRole::IMAGE_DECODE },
70 };
71 
72 const std::unordered_map<ResSchedSceneAdapter, int32_t> RES_SCENE_MAP = {
73     { ResSchedSceneAdapter::LOAD_URL, ResType::WebScene::WEB_SCENE_LOAD_URL },
74     { ResSchedSceneAdapter::CLICK, ResType::WebScene::WEB_SCENE_CLICK },
75     { ResSchedSceneAdapter::SLIDE, ResType::WebScene::WEB_SCENE_SLIDE },
76     { ResSchedSceneAdapter::RESIZE, ResType::WebScene::WEB_SCENE_RESIZE },
77     { ResSchedSceneAdapter::VISIBLE, ResType::WebScene::WEB_SCENE_VISIBLE },
78     { ResSchedSceneAdapter::KEYBOARD_CLICK, ResType::WebScene::WEB_SCENE_KEYBOARD_CLICK },
79     { ResSchedSceneAdapter::KEY_TASK, ResType::WebScene::WEB_SCENE_KEY_TASK },
80     { ResSchedSceneAdapter::IMAGE_DECODE, ResType::WebScene::WEB_SCENE_IMAGE_DECODE },
81 };
82 
83 const int32_t INVALID_NUMBER = -1;
84 const int64_t INVALID_NUMBER_INT64 = -1;
85 const int64_t SLIDE_PERIOD_MS = 300;
86 const pid_t INVALID_PID = -1;
87 constexpr char PID[] = "pid";
88 constexpr char UID[] = "uid";
89 constexpr char TID[] = "tid";
90 constexpr char ROLE[] = "role";
91 constexpr char WINDOW_ID[] = "windowId";
92 constexpr char SERIAL_NUMBER[] = "serialNum";
93 constexpr char SCENE_ID[] = "sceneId";
94 constexpr char STATE[] = "state";
95 std::set<int32_t> g_nwebSet;
96 std::unordered_map<pid_t, std::unordered_map<int32_t, ResSchedStatusAdapter>> g_pidNwebMap;
97 std::unordered_map<int32_t, std::vector<pid_t>> g_nwebProcessMap;
98 std::unordered_set<pid_t> g_processInUse;
99 std::mutex g_windowIdMutex {};
100 std::mutex g_processInUseMutex {};
101 int32_t g_windowId = INVALID_NUMBER;
102 int32_t g_nwebId = INVALID_NUMBER;
103 pid_t g_lastPid = INVALID_PID;
104 int64_t g_lastStatus = INVALID_NUMBER_INT64;
105 int64_t g_timeStamp = 0;
106 int64_t g_preTimeStamp = 0;
107 pid_t g_lastRenderPid = INVALID_PID;
108 int64_t g_lastRenderStatus = INVALID_NUMBER_INT64;
109 bool g_siteIsolationMode = false;
110 
GetUidString()111 std::string GetUidString()
112 {
113     static std::string uidString = std::to_string(getuid());
114     return uidString;
115 }
116 
GetBundleNameByUid(int32_t uid)117 std::string GetBundleNameByUid(int32_t uid)
118 {
119     sptr<ISystemAbilityManager> systemAbilityManager =
120         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
121     if (systemAbilityManager == nullptr) {
122         WVLOG_E("get SystemAbilityManager failed");
123         return "";
124     }
125     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
126     if (remoteObject == nullptr) {
127         WVLOG_E("get Bundle Manager failed");
128         return "";
129     }
130     auto bundleMgr = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
131     if (bundleMgr == nullptr) {
132         return "";
133     }
134     std::string bundle {""};
135     bundleMgr->GetNameForUid(uid, bundle);
136     return bundle;
137 }
138 
ConvertStatus(ResSchedStatusAdapter statusAdapter,int64_t & status)139 bool ConvertStatus(ResSchedStatusAdapter statusAdapter, int64_t& status)
140 {
141     if (auto it = RES_STATUS_MAP.find(statusAdapter); it == RES_STATUS_MAP.end()) {
142         WVLOG_E("invalid status: %{public}d", statusAdapter);
143         return false;
144     } else {
145         status = it->second;
146     }
147     return true;
148 }
149 
NeedReportScene(ResSchedSceneAdapter sceneAdapter)150 bool NeedReportScene(ResSchedSceneAdapter sceneAdapter)
151 {
152     if (sceneAdapter != ResSchedSceneAdapter::SLIDE) {
153         return true;
154     }
155     auto currentTime = std::chrono::system_clock::now().time_since_epoch();
156     g_timeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime).count();
157     if (g_timeStamp - g_preTimeStamp > SLIDE_PERIOD_MS) {
158         g_preTimeStamp = g_timeStamp;
159         return true;
160     }
161     return false;
162 }
163 
ReportSceneInternal(ResSchedStatusAdapter statusAdapter,ResSchedSceneAdapter sceneAdapter)164 bool ReportSceneInternal(ResSchedStatusAdapter statusAdapter, ResSchedSceneAdapter sceneAdapter)
165 {
166     // To limit the frequency of events reported in some scenarios
167     if (!NeedReportScene(sceneAdapter)) {
168         return false;
169     }
170 
171     int64_t status;
172     bool ret = ConvertStatus(statusAdapter, status);
173     if (!ret) {
174         return false;
175     }
176 
177     int32_t sceneId;
178     if (auto it = RES_SCENE_MAP.find(sceneAdapter); it == RES_SCENE_MAP.end()) {
179         WVLOG_E("invalid scene id: %{public}d", sceneAdapter);
180         return false;
181     } else {
182         sceneId = it->second;
183     }
184 
185     std::unordered_map<std::string, std::string> mapPayload { { UID, GetUidString() },
186         { SCENE_ID, std::to_string(sceneId) } };
187     ResSchedClient::GetInstance().ReportData(ResType::RES_TYPE_REPORT_SCENE_SCHED, status, mapPayload);
188     WVLOG_D("ReportScene status: %{public}d, uid: %{public}s, sceneId: %{public}d", static_cast<int32_t>(status),
189         GetUidString().c_str(), sceneId);
190     return true;
191 }
192 
IsSameSourceWebSiteActive(ResSchedStatusAdapter statusAdapter,pid_t pid,int32_t nwebId)193 bool IsSameSourceWebSiteActive(ResSchedStatusAdapter statusAdapter, pid_t pid, int32_t nwebId)
194 {
195     static std::mutex initMutex;
196     std::lock_guard<std::mutex> lock(initMutex);
197     g_pidNwebMap[pid][nwebId] = statusAdapter;
198     if (statusAdapter == ResSchedStatusAdapter::WEB_INACTIVE) {
199         auto nwebMap = g_pidNwebMap[pid];
200         for (auto it : nwebMap) {
201             if (it.second == ResSchedStatusAdapter::WEB_ACTIVE) {
202                 WVLOG_D("IsSameSourceWebSiteActive, current nwebId: %{public}d, active nwebId: %{public}d, "
203                         "pid: %{public}d", nwebId, it.first, pid);
204                 return true;
205             }
206         }
207         g_pidNwebMap.erase(pid);
208     }
209     return false;
210 }
211 
ReportStatusData(ResSchedStatusAdapter statusAdapter,pid_t pid,uint32_t windowId,int32_t nwebId,bool isSiteManage)212 void ReportStatusData(ResSchedStatusAdapter statusAdapter,
213                       pid_t pid, uint32_t windowId, int32_t nwebId, bool isSiteManage)
214 {
215     static uint32_t serialNum = 0;
216     static constexpr uint32_t serialNumMax = 10000;
217 
218     static std::mutex initMutex;
219     std::lock_guard<std::mutex> lock(initMutex);
220     if (g_nwebSet.find(nwebId) == g_nwebSet.end() || pid == 0) {
221         WVLOG_D("Don't report window status, nwebId: %{public}d, pid: %{public}d", nwebId, pid);
222         return;
223     }
224 
225     int64_t status;
226     bool ret = ConvertStatus(statusAdapter, status);
227     if (!ret) {
228         return;
229     }
230 
231     ProductDeviceType deviceType = SystemPropertiesAdapterImpl::GetInstance().GetProductDeviceType();
232     {
233         std::lock_guard<std::mutex> lock(g_processInUseMutex);
234         if (deviceType == ProductDeviceType::DEVICE_TYPE_MOBILE || g_processInUse.count(pid)) {
235             if (isSiteManage && IsSameSourceWebSiteActive(statusAdapter, pid, nwebId)) {
236                 return;
237             }
238         }
239     }
240 
241     if (pid == g_lastPid && status == g_lastStatus) {
242         return;
243     }
244     g_lastPid = pid;
245     g_lastStatus = status;
246 
247     std::unordered_map<std::string, std::string> mapPayload { { UID, GetUidString() }, { PID, std::to_string(pid) },
248         { WINDOW_ID, std::to_string(windowId) }, { SERIAL_NUMBER, std::to_string(serialNum) },
249         { STATE, std::to_string(status) } };
250     ResSchedClient::GetInstance().ReportData(
251         ResType::RES_TYPE_REPORT_WINDOW_STATE, ResType::ReportChangeStatus::CREATE, mapPayload);
252 
253     WVLOG_I("ReportWindowStatus status: %{public}d, uid: %{public}s, pid: %{public}d, windowId: %{public}d, "
254             "nwebId: %{public}d, sn: %{public}d",
255             static_cast<int32_t>(status), GetUidString().c_str(), pid, windowId, nwebId, serialNum);
256     serialNum = (serialNum + 1) % serialNumMax;
257 
258     // Report visible scene event again when tab becomes active to solve timing problem
259     if (statusAdapter == ResSchedStatusAdapter::WEB_ACTIVE) {
260         ReportSceneInternal(statusAdapter, ResSchedSceneAdapter::VISIBLE);
261     }
262 }
263 
ReportKeyThread(ResSchedStatusAdapter statusAdapter,pid_t pid,pid_t tid,ResSchedRoleAdapter roleAdapter)264 bool ResSchedClientAdapter::ReportKeyThread(
265     ResSchedStatusAdapter statusAdapter, pid_t pid, pid_t tid, ResSchedRoleAdapter roleAdapter)
266 {
267     static std::mutex initMutex;
268     std::lock_guard<std::mutex> lock(initMutex);
269     int64_t status;
270     bool ret = ConvertStatus(statusAdapter, status);
271     if (!ret) {
272         return false;
273     }
274 
275     ResType::ThreadRole role;
276     if (auto it = RES_ROLE_MAP.find(roleAdapter); it == RES_ROLE_MAP.end()) {
277         WVLOG_E("invalid role: %{public}d", roleAdapter);
278         return false;
279     } else {
280         role = it->second;
281     }
282 
283     std::unordered_map<std::string, std::string> mapPayload { { UID, GetUidString() }, { PID, std::to_string(pid) },
284         { TID, std::to_string(tid) }, { ROLE, std::to_string(role) } };
285 
286     // Report process creation event first when render process is created
287     if (pid == tid) {
288         mapPayload["processType"] = std::to_string(static_cast<uint32_t>(AppExecFwk::ProcessType::RENDER));
289         mapPayload["bundleName"] = GetBundleNameByUid(getuid());
290     }
291 
292     ResSchedClient::GetInstance().ReportData(ResType::RES_TYPE_REPORT_KEY_THREAD, status, mapPayload);
293     WVLOG_I("ReportKeyThread status: %{public}d, uid: %{public}s, pid: %{public}d, tid:%{public}d, role: %{public}d",
294         static_cast<int32_t>(status), GetUidString().c_str(), pid, tid, static_cast<int32_t>(role));
295 
296     if (pid == tid && g_windowId != INVALID_NUMBER && g_nwebId != INVALID_NUMBER) {
297         std::lock_guard<std::mutex> lock(g_windowIdMutex);
298         ReportStatusData(ResSchedStatusAdapter::WEB_ACTIVE, pid, g_windowId, g_nwebId, false);
299     }
300 
301     if (pid == tid && statusAdapter == ResSchedStatusAdapter::THREAD_DESTROYED) {
302         std::lock_guard<std::mutex> lock(g_processInUseMutex);
303         g_processInUse.erase(pid);
304     }
305 
306     // Load url may create new render process, repeat report load url event when
307     // render key thread create to solve timing problem. Later events will overwrite previous events
308     if (statusAdapter == ResSchedStatusAdapter::THREAD_CREATED && pid != getprocpid()) {
309         ReportSceneInternal(statusAdapter, ResSchedSceneAdapter::LOAD_URL);
310     }
311     return true;
312 }
313 
ReportAudioData(ResSchedStatusAdapter statusAdapter,pid_t pid,pid_t tid)314 bool ResSchedClientAdapter::ReportAudioData(ResSchedStatusAdapter statusAdapter, pid_t pid, pid_t tid)
315 {
316     static uint32_t resType = ResType::RES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE;
317 
318     int64_t status;
319     if (!ConvertStatus(statusAdapter, status)) {
320         return false;
321     }
322 
323     uid_t uid = getuid();
324     std::unordered_map<std::string, std::string> mapPayload { { UID, std::to_string(uid) },
325         { PID, std::to_string(pid) }, { TID, std::to_string(tid) } };
326     WVLOG_D("ReportAudioData status: %{public}d, uid: %{public}d, pid: %{public}d, tid:%{public}d",
327         static_cast<int32_t>(status), uid, pid, tid);
328     ResSchedClient::GetInstance().ReportData(resType, status, mapPayload);
329 
330     return true;
331 }
332 
ReportProcessInUse(pid_t pid)333 void ResSchedClientAdapter::ReportProcessInUse(pid_t pid)
334 {
335     static std::mutex initMutex;
336     std::lock_guard<std::mutex> lock(initMutex);
337     int32_t nwebId = g_nwebId;
338     if (g_pidNwebMap.count(pid)) {
339         nwebId = g_pidNwebMap[pid].begin()->first;
340     }
341 
342     {
343         std::lock_guard<std::mutex> lock(g_processInUseMutex);
344         g_processInUse.insert(pid);
345     }
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