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 #ifndef RES_SCHED_CLIENT_ADAPTER_H
17 #define RES_SCHED_CLIENT_ADAPTER_H
18 
19 #include <cstdint>
20 #include <unistd.h>
21 
22 namespace OHOS::NWeb {
23 
24 enum class ResSchedTypeAdapter : int32_t {
25     RES_TYPE_KEY_THREAD = 0,
26     RES_TYPE_WEB_STATUS_CHANGE,
27     RES_TYPE_WEB_SCENE,
28     RES_TYPE_WEBVIEW_AUDIO_STATUS_CHANGE,
29     RES_TYPE_WEBVIEW_SCREEN_CAPTURE,
30     RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE,
31 };
32 
33 enum class ResSchedStatusAdapter : int32_t {
34     THREAD_CREATED = 0,
35     THREAD_DESTROYED,
36     WEB_ACTIVE,
37     WEB_INACTIVE,
38     WEB_SCENE_ENTER,
39     WEB_SCENE_EXIT,
40     AUDIO_STATUS_START,
41     AUDIO_STATUS_STOP,
42     SCREEN_CAPTURE_START,
43     SCREEN_CAPTURE_STOP,
44     VIDEO_PLAYING_START,
45     VIDEO_PLAYING_STOP,
46 };
47 
48 enum class ResSchedRoleAdapter : int32_t {
49     USER_INTERACT = 0,
50     NORMAL_DISPLAY,
51     IMPORTANT_DISPLAY,
52     NORMAL_AUDIO,
53     IMPORTANT_AUDIO,
54     IMAGE_DECODE,
55 };
56 
57 enum class ResSchedSceneAdapter : int32_t {
58     LOAD_URL = 0,
59     CLICK,
60     SLIDE,
61     RESIZE,
62     VISIBLE,
63     KEYBOARD_CLICK,
64     KEY_TASK,
65     IMAGE_DECODE,
66 };
67 
68 class ResSchedClientAdapter {
69 public:
70     ResSchedClientAdapter() = default;
71 
72     virtual ~ResSchedClientAdapter() = default;
73 
74     static bool ReportKeyThread(
75         ResSchedStatusAdapter statusAdapter, pid_t pid, pid_t tid, ResSchedRoleAdapter roleAdapter);
76     static bool ReportWindowStatus(
77         ResSchedStatusAdapter statusAdapter, pid_t pid, uint32_t windowId, int32_t nwebId = -1);
78     static bool ReportScene(
79         ResSchedStatusAdapter statusAdapter, ResSchedSceneAdapter sceneAdapter, int32_t nwebId = -1);
80     static bool ReportAudioData(ResSchedStatusAdapter statusAdapter, pid_t pid, pid_t tid);
81     static void ReportWindowId(int32_t windowId, int32_t nwebId = -1);
82     static void ReportNWebInit(ResSchedStatusAdapter statusAdapter, int32_t nwebId);
83     static void ReportRenderProcessStatus(ResSchedStatusAdapter statusAdapter, pid_t pid);
84     static bool ReportScreenCapture(ResSchedStatusAdapter statusAdapter, pid_t pid);
85     static bool ReportVideoPlaying(ResSchedStatusAdapter statusAdapter, pid_t pid);
86     static void ReportProcessInUse(pid_t pid);
87     static void ReportSiteIsolationMode(bool mode);
88 };
89 
90 } // namespace OHOS::NWeb
91 
92 #endif // RES_SCHED_CLIENT_ADAPTER_H
93