• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef OHOS_ROSEN_DM_COMMON_H
17 #define OHOS_ROSEN_DM_COMMON_H
18 
19 #include <refbase.h>
20 #include <string>
21 #include <map>
22 
23 namespace OHOS {
24 namespace Rosen {
25 using DisplayId = uint64_t;
26 using ScreenId = uint64_t;
27 namespace {
28     constexpr DisplayId DISPLAY_ID_INVALID = -1ULL;
29     constexpr ScreenId SCREEN_ID_INVALID = -1ULL;
30     constexpr int DOT_PER_INCH = 160;
31     const static std::string DEFAULT_SCREEN_NAME = "buildIn";
32     constexpr int DOT_PER_INCH_MAXIMUM_VALUE = 640;
33     constexpr int DOT_PER_INCH_MINIMUM_VALUE = 80;
34     constexpr uint32_t BASELINE_DENSITY = 160;
35 }
36 
37 /**
38  * @brief Power state change reason.
39  */
40 enum class PowerStateChangeReason : uint32_t {
41     POWER_BUTTON,
42 };
43 
44 /**
45  * @brief Enumerates the state of the screen power.
46  */
47 enum class ScreenPowerState : uint32_t {
48     POWER_ON,
49     POWER_STAND_BY,
50     POWER_SUSPEND,
51     POWER_OFF,
52     POWER_BUTT,
53     INVALID_STATE,
54 };
55 
56 /**
57  * @brief Enumerates the state of the display.
58  */
59 enum class DisplayState : uint32_t {
60     UNKNOWN,
61     OFF,
62     ON,
63     DOZE,
64     DOZE_SUSPEND,
65     VR,
66     ON_SUSPEND,
67 };
68 
69 /**
70  * @brief Enumerates display events.
71  */
72 enum class DisplayEvent : uint32_t {
73     UNLOCK,
74     KEYGUARD_DRAWN,
75 };
76 
77 /**
78  * @brief Enumerates DMError.
79  */
80 enum class DMError : int32_t {
81     DM_OK = 0,
82     DM_ERROR_INIT_DMS_PROXY_LOCKED = 100,
83     DM_ERROR_IPC_FAILED = 101,
84     DM_ERROR_REMOTE_CREATE_FAILED = 110,
85     DM_ERROR_NULLPTR = 120,
86     DM_ERROR_INVALID_PARAM = 130,
87     DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED = 140,
88     DM_ERROR_DEATH_RECIPIENT = 150,
89     DM_ERROR_INVALID_MODE_ID = 160,
90     DM_ERROR_WRITE_DATA_FAILED = 170,
91     DM_ERROR_RENDER_SERVICE_FAILED = 180,
92     DM_ERROR_UNREGISTER_AGENT_FAILED = 190,
93     DM_ERROR_INVALID_CALLING = 200,
94     DM_ERROR_INVALID_PERMISSION = 201,
95     DM_ERROR_NOT_SYSTEM_APP = 202,
96     DM_ERROR_UNKNOWN = -1,
97 };
98 
99 /**
100  * @brief Enumerates DM error codes.
101  */
102 enum class DmErrorCode : int32_t {
103     DM_OK = 0,
104     DM_ERROR_NO_PERMISSION = 201,
105     DM_ERROR_NOT_SYSTEM_APP = 202,
106     DM_ERROR_INVALID_PARAM = 401,
107     DM_ERROR_DEVICE_NOT_SUPPORT = 801,
108     DM_ERROR_INVALID_SCREEN = 1400001,
109     DM_ERROR_INVALID_CALLING = 1400002,
110     DM_ERROR_SYSTEM_INNORMAL = 1400003,
111 };
112 
113 /**
114  * @brief Constructs the mapping of the DM errors to the DM error codes.
115  */
116 const std::map<DMError, DmErrorCode> DM_JS_TO_ERROR_CODE_MAP {
117     {DMError::DM_OK,                                    DmErrorCode::DM_OK                          },
118     {DMError::DM_ERROR_INVALID_PERMISSION,              DmErrorCode::DM_ERROR_NO_PERMISSION         },
119     {DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
120     {DMError::DM_ERROR_IPC_FAILED,                      DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
121     {DMError::DM_ERROR_REMOTE_CREATE_FAILED,            DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
122     {DMError::DM_ERROR_NULLPTR,                         DmErrorCode::DM_ERROR_INVALID_SCREEN        },
123     {DMError::DM_ERROR_INVALID_PARAM,                   DmErrorCode::DM_ERROR_INVALID_PARAM         },
124     {DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED,    DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
125     {DMError::DM_ERROR_DEATH_RECIPIENT,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
126     {DMError::DM_ERROR_INVALID_MODE_ID,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
127     {DMError::DM_ERROR_WRITE_DATA_FAILED,               DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
128     {DMError::DM_ERROR_RENDER_SERVICE_FAILED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
129     {DMError::DM_ERROR_UNREGISTER_AGENT_FAILED,         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
130     {DMError::DM_ERROR_INVALID_CALLING,                 DmErrorCode::DM_ERROR_INVALID_CALLING       },
131     {DMError::DM_ERROR_NOT_SYSTEM_APP,                  DmErrorCode::DM_ERROR_NOT_SYSTEM_APP        },
132     {DMError::DM_ERROR_UNKNOWN,                         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
133 };
134 
135 using DisplayStateCallback = std::function<void(DisplayState)>;
136 
137 /**
138  * @brief Enumerates display power events.
139  */
140 enum class DisplayPowerEvent : uint32_t {
141     WAKE_UP,
142     SLEEP,
143     DISPLAY_ON,
144     DISPLAY_OFF,
145     DESKTOP_READY,
146 };
147 
148 /**
149  * @brief Enumerates event status.
150  */
151 enum class EventStatus : uint32_t {
152     BEGIN,
153     END,
154 };
155 
156 class IDisplayPowerEventListener : public RefBase {
157 public:
158     /**
159      * @brief Notify when display power event status changed.
160      */
161     virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0;
162 };
163 
164 /**
165  * @brief Enumerates screen change events.
166  */
167 enum class ScreenChangeEvent : uint32_t {
168     UPDATE_ORIENTATION,
169     UPDATE_ROTATION,
170     CHANGE_MODE,
171     VIRTUAL_PIXEL_RATIO_CHANGED,
172 };
173 
174 /**
175  * @brief Enumerates screen group change events.
176  */
177 enum class ScreenGroupChangeEvent : uint32_t {
178     ADD_TO_GROUP,
179     REMOVE_FROM_GROUP,
180     CHANGE_GROUP,
181 };
182 
183 /**
184  * @brief Enumerates rotations.
185  */
186 enum class Rotation : uint32_t {
187     ROTATION_0,
188     ROTATION_90,
189     ROTATION_180,
190     ROTATION_270,
191 };
192 
193 /**
194  * @brief Enumerates orientations.
195  */
196 enum class Orientation : uint32_t {
197     BEGIN = 0,
198     UNSPECIFIED = BEGIN,
199     VERTICAL = 1,
200     HORIZONTAL = 2,
201     REVERSE_VERTICAL = 3,
202     REVERSE_HORIZONTAL = 4,
203     SENSOR = 5,
204     SENSOR_VERTICAL = 6,
205     SENSOR_HORIZONTAL = 7,
206     AUTO_ROTATION_RESTRICTED = 8,
207     AUTO_ROTATION_PORTRAIT_RESTRICTED = 9,
208     AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10,
209     LOCKED = 11,
210     END = LOCKED,
211 };
212 
213 /**
214  * @brief Enumerates display orientations.
215  */
216 enum class DisplayOrientation : uint32_t {
217     PORTRAIT = 0,
218     LANDSCAPE,
219     PORTRAIT_INVERTED,
220     LANDSCAPE_INVERTED,
221     UNKNOWN,
222 };
223 
224 /**
225  * @brief Enumerates display change events.
226  */
227 enum class DisplayChangeEvent : uint32_t {
228     UPDATE_ORIENTATION,
229     UPDATE_ROTATION,
230     DISPLAY_SIZE_CHANGED,
231     DISPLAY_FREEZED,
232     DISPLAY_UNFREEZED,
233     DISPLAY_VIRTUAL_PIXEL_RATIO_CHANGED,
234     UPDATE_ORIENTATION_FROM_WINDOW,
235     UPDATE_ROTATION_FROM_WINDOW,
236     UNKNOWN,
237 };
238 
239 /**
240  * @brief Enumerates screen source mode.
241  */
242 enum class ScreenSourceMode: uint32_t {
243     SCREEN_MAIN = 0,
244     SCREEN_MIRROR = 1,
245     SCREEN_EXTEND = 2,
246     SCREEN_ALONE = 3,
247 };
248 
249 /**
250  * @brief Enumerates the fold status.
251  */
252 enum class FoldStatus: uint32_t {
253     UNKNOWN = 0,
254     EXPAND = 1,
255     FOLDED = 2,
256     HALF_FOLD = 3,
257 };
258 
259 /**
260  * @brief Enumerates the fold display mode.
261  */
262 enum class FoldDisplayMode: uint32_t {
263     UNKNOWN = 0,
264     FULL = 1,
265     MAIN = 2,
266     SUB = 3,
267     COORDINATION = 4,
268 };
269 }
270 }
271 #endif // OHOS_ROSEN_DM_COMMON_H