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 OHOS_ROSEN_WINDOW_SCENE_WS_COMMON_H
17 #define OHOS_ROSEN_WINDOW_SCENE_WS_COMMON_H
18
19 #include <inttypes.h>
20 #include <iomanip>
21 #include <map>
22 #include <sstream>
23 #include <string>
24
25 #include <iremote_broker.h>
26 #include <want.h>
27
28 namespace OHOS::AAFwk {
29 class AbilityStartSetting;
30 }
31 namespace OHOS::AppExecFwk {
32 struct AbilityInfo;
33 }
34
35 namespace OHOS::Rosen {
36 constexpr int32_t INVALID_SESSION_ID = 0;
37
38 enum class WSError : int32_t {
39 WS_OK = 0,
40 WS_DO_NOTHING,
41 WS_ERROR_NO_MEM,
42 WS_ERROR_DESTROYED_OBJECT,
43 WS_ERROR_INVALID_WINDOW,
44 WS_ERROR_INVALID_WINDOW_MODE_OR_SIZE,
45 WS_ERROR_INVALID_OPERATION,
46 WS_ERROR_INVALID_PERMISSION,
47 WS_ERROR_NOT_SYSTEM_APP,
48 WS_ERROR_NO_REMOTE_ANIMATION,
49 WS_ERROR_INVALID_DISPLAY,
50 WS_ERROR_INVALID_PARENT,
51 WS_ERROR_OPER_FULLSCREEN_FAILED,
52 WS_ERROR_REPEAT_OPERATION,
53 WS_ERROR_INVALID_SESSION,
54 WS_ERROR_INVALID_CALLING,
55 WS_ERROR_UNCLEARABLE_SESSION,
56 WS_ERROR_FAIL_TO_GET_SNAPSHOT,
57 WS_ERROR_INTERNAL_ERROR,
58 WS_ERROR_NO_UI_CONTENT_ERROR,
59
60 WS_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system
61
62 WS_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report
63 WS_ERROR_NULLPTR,
64 WS_ERROR_INVALID_TYPE,
65 WS_ERROR_INVALID_PARAM,
66 WS_ERROR_SAMGR,
67 WS_ERROR_IPC_FAILED,
68 WS_ERROR_NEED_REPORT_END,
69 WS_ERROR_START_ABILITY_FAILED,
70 WS_ERROR_SET_SESSION_LABEL_FAILED,
71 WS_ERROR_SET_SESSION_ICON_FAILED,
72 WS_ERROR_INVALID_SESSION_LISTENER,
73 WS_ERROR_START_UI_EXTENSION_ABILITY_FAILED,
74 WS_ERROR_MIN_UI_EXTENSION_ABILITY_FAILED,
75 WS_ERROR_TERMINATE_UI_EXTENSION_ABILITY_FAILED,
76
77 WS_ERROR_EDM_CONTROLLED = 2097215, // enterprise limit
78 };
79
80 enum class WSErrorCode : int32_t {
81 WS_OK = 0,
82 WS_ERROR_NO_PERMISSION = 201,
83 WS_ERROR_INVALID_PARAM = 401,
84 WS_ERROR_DEVICE_NOT_SUPPORT = 801,
85 WS_ERROR_TIMEOUT = 901,
86 WS_ERROR_NOT_REGISTER_SYNC_CALLBACK = 100011,
87 WS_ERROR_TRANSFER_DATA_FAILED = 100012,
88 WS_ERROR_REPEAT_OPERATION = 1300001,
89 WS_ERROR_STATE_ABNORMALLY = 1300002,
90 WS_ERROR_SYSTEM_ABNORMALLY = 1300003,
91 WS_ERROR_INVALID_CALLING = 1300004,
92 WS_ERROR_STAGE_ABNORMALLY = 1300005,
93 WS_ERROR_CONTEXT_ABNORMALLY = 1300006,
94
95 WS_ERROR_EDM_CONTROLLED = 16000013, // enterprise limit
96 };
97
98 const std::map<WSError, WSErrorCode> WS_JS_TO_ERROR_CODE_MAP {
99 { WSError::WS_OK, WSErrorCode::WS_OK },
100 { WSError::WS_DO_NOTHING, WSErrorCode::WS_ERROR_STATE_ABNORMALLY },
101 { WSError::WS_ERROR_INVALID_SESSION, WSErrorCode::WS_ERROR_STATE_ABNORMALLY },
102 { WSError::WS_ERROR_INVALID_PARAM, WSErrorCode::WS_ERROR_STATE_ABNORMALLY },
103 { WSError::WS_ERROR_IPC_FAILED, WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY },
104 { WSError::WS_ERROR_NULLPTR, WSErrorCode::WS_ERROR_STATE_ABNORMALLY },
105 { WSError::WS_ERROR_EDM_CONTROLLED, WSErrorCode::WS_ERROR_EDM_CONTROLLED},
106 };
107
108 enum class SessionState : uint32_t {
109 STATE_DISCONNECT = 0,
110 STATE_CONNECT,
111 STATE_FOREGROUND,
112 STATE_ACTIVE,
113 STATE_INACTIVE,
114 STATE_BACKGROUND,
115 STATE_END,
116 };
117
118 enum ContinueState {
119 CONTINUESTATE_UNKNOWN = -1,
120 CONTINUESTATE_ACTIVE = 0,
121 CONTINUESTATE_INACTIVE = 1,
122 CONTINUESTATE_MAX
123 };
124
125 enum class StartMethod : int32_t {
126 START_NORMAL,
127 START_CALL
128 };
129
130 /**
131 * @brief collaborator type.
132 */
133 enum CollaboratorType : int32_t {
134 DEFAULT_TYPE = 0,
135 RESERVE_TYPE,
136 OTHERS_TYPE,
137 };
138
139 enum AncoSceneState: int32_t {
140 DEFAULT_STATE = 0,
141 NOTIFY_START,
142 NOTIFY_CREATE,
143 NOTIFY_LOAD,
144 NOTIFY_UPDATE,
145 NOTIFY_FOREGROUND,
146 };
147
148 /**
149 * @brief collaborator type.
150 */
151 enum SessionOperationType : int32_t {
152 TYPE_DEFAULT = 0,
153 TYPE_CLEAR,
154 };
155
156 enum class ManagerState : uint32_t {
157 MANAGER_STATE_SCREEN_LOCKED = 0,
158 };
159
160 struct SessionInfo {
161 std::string bundleName_ = "";
162 std::string moduleName_ = "";
163 std::string abilityName_ = "";
164 int32_t appIndex_ = 0;
165 bool isSystem_ = false;
166 uint32_t windowType_ = 1; // WINDOW_TYPE_APP_MAIN_WINDOW
167 sptr<IRemoteObject> callerToken_ = nullptr;
168 sptr<IRemoteObject> rootToken_ = nullptr;
169 uint64_t screenId_ = -1ULL; // -1ULL:SCREEN_ID_INVALID
170 bool isPersistentRecover_ = false;
171
172 mutable std::shared_ptr<AAFwk::Want> want; // want for ability start
173 std::shared_ptr<AAFwk::Want> closeAbilityWant;
174 std::shared_ptr<AAFwk::AbilityStartSetting> startSetting = nullptr;
175 mutable std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = nullptr;
176 int32_t resultCode = -1;
177 int32_t requestCode;
178 int32_t errorCode;
179 std::string errorReason;
180 int32_t persistentId_ = INVALID_SESSION_ID;
181 int32_t callerPersistentId_ = INVALID_SESSION_ID;
182 uint32_t callState_ = 0;
183 uint32_t callingTokenId_ = 0;
184 bool reuse = false;
185 int32_t windowMode = 0;
186 StartMethod startMethod = StartMethod::START_NORMAL;
187 bool lockedState = false;
188 std::string time;
189 ContinueState continueState = ContinueState::CONTINUESTATE_ACTIVE;
190 int64_t uiAbilityId_ = 0;
191 int32_t ancoSceneState;
192 bool isClearSession = false;
193 std::string sessionAffinity;
194 int32_t collaboratorType_ = CollaboratorType::DEFAULT_TYPE;
195 SessionState sessionState_ = SessionState::STATE_DISCONNECT;
196 uint32_t requestOrientation_ = 0;
197 bool isRotable_ = false;
198 bool isSystemInput_ = false;
199 bool isAsyncModalBinding_ = false;
200 };
201
202 enum class SessionFlag : uint32_t {
203 SESSION_FLAG_NEED_AVOID = 1,
204 SESSION_FLAG_PARENT_LIMIT = 1 << 1,
205 SESSION_FLAG_SHOW_WHEN_LOCKED = 1 << 2,
206 SESSION_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
207 SESSION_FLAG_WATER_MARK = 1 << 4,
208 SESSION_FLAG_END = 1 << 5,
209 };
210
211 enum class SizeChangeReason : uint32_t {
212 UNDEFINED = 0,
213 MAXIMIZE,
214 RECOVER,
215 ROTATION,
216 DRAG,
217 DRAG_START,
218 DRAG_END,
219 RESIZE,
220 MOVE,
221 HIDE,
222 TRANSFORM,
223 CUSTOM_ANIMATION_SHOW,
224 FULL_TO_SPLIT,
225 SPLIT_TO_FULL,
226 FULL_TO_FLOATING,
227 FLOATING_TO_FULL,
228 END,
229 };
230
231 enum class SessionEvent : uint32_t {
232 EVENT_MAXIMIZE = 100,
233 EVENT_RECOVER,
234 EVENT_MINIMIZE,
235 EVENT_CLOSE,
236 EVENT_START_MOVE,
237 EVENT_END_MOVE,
238 EVENT_MAXIMIZE_FLOATING,
239 EVENT_TERMINATE,
240 EVENT_EXCEPTION,
241 EVENT_SPLIT_PRIMARY,
242 EVENT_SPLIT_SECONDARY,
243 EVENT_DRAG_START,
244 };
245
246 enum class BrokerStates: uint32_t {
247 BROKER_UNKOWN = 1,
248 BROKER_STARTED = 0,
249 BROKER_NOT_START = -1,
250 };
251
GreatOrEqual(double left,double right)252 inline bool GreatOrEqual(double left, double right)
253 {
254 constexpr double epsilon = -0.00001f;
255 return (left - right) > epsilon;
256 }
257
LessOrEqual(double left,double right)258 inline bool LessOrEqual(double left, double right)
259 {
260 constexpr double epsilon = 0.00001f;
261 return (left - right) < epsilon;
262 }
263
NearEqual(const double left,const double right,const double epsilon)264 inline bool NearEqual(const double left, const double right, const double epsilon)
265 {
266 return (std::fabs(left - right) <= epsilon);
267 }
268
NearEqual(const float & left,const float & right)269 inline bool NearEqual(const float& left, const float& right)
270 {
271 constexpr double epsilon = 0.001f;
272 return NearEqual(left, right, epsilon);
273 }
274
NearEqual(const int32_t & left,const int32_t & right)275 inline bool NearEqual(const int32_t& left, const int32_t& right)
276 {
277 return left == right;
278 }
279
NearZero(const double left)280 inline bool NearZero(const double left)
281 {
282 constexpr double epsilon = 0.001f;
283 return NearEqual(left, 0.0, epsilon);
284 }
285
286 template<typename T>
287 struct WSRectT {
288 T posX_ = 0;
289 T posY_ = 0;
290 T width_ = 0;
291 T height_ = 0;
292
293 bool operator==(const WSRectT<T>& a) const
294 {
295 return (NearEqual(posX_, a.posX_) && NearEqual(posY_, a.posY_) &&
296 NearEqual(width_, a.width_) && NearEqual(height_, a.height_));
297 }
298
299 bool operator!=(const WSRectT<T>& a) const
300 {
301 return !this->operator==(a);
302 }
303
IsEmptyWSRectT304 bool IsEmpty() const
305 {
306 if (NearZero(posX_) && NearZero(posY_) && NearZero(width_) && NearZero(height_)) {
307 return true;
308 }
309 return false;
310 }
311
IsInRegionWSRectT312 inline bool IsInRegion(int32_t pointX, int32_t pointY)
313 {
314 return GreatOrEqual(pointX, posX_) && LessOrEqual(pointX, posX_ + width_) &&
315 GreatOrEqual(pointY, posY_) && LessOrEqual(pointY, posY_ + height_);
316 }
317
IsInvalidWSRectT318 inline bool IsInvalid() const
319 {
320 return IsEmpty() || NearZero(width_) || NearZero(height_);
321 }
322
ToStringWSRectT323 inline std::string ToString() const
324 {
325 constexpr int precision = 2;
326 std::stringstream ss;
327 ss << "[" << std::fixed << std::setprecision(precision) << posX_ << " " << posY_ << " " <<
328 width_ << " " << height_ << "]";
329 return ss.str();
330 }
331 };
332
333 using WSRect = WSRectT<int32_t>;
334 using WSRectF = WSRectT<float>;
335
336 struct WindowShadowConfig {
337 float offsetX_ = 0.0f;
338 float offsetY_ = 0.0f;
339 float alpha_ = 0.0f;
340 float radius_ = 0.0f;
341 std::string color_ = "#000000";
342 };
343
344 struct KeyboardSceneAnimationConfig {
345 std::string curveType_ = "default";
346 float ctrlX1_ = 0.2f;
347 float ctrlY1_ = 0.0f;
348 float ctrlX2_ = 0.2f;
349 float ctrlY2_ = 1.0f;
350 uint32_t duration_ = 150;
351 };
352
353 struct WindowAnimationConfig {
354 int32_t duration_ = 0;
355 std::string curveType_ = "easeOut";
356 float ctrlX1_ = 0.2f;
357 float ctrlY1_ = 0.0f;
358 float ctrlX2_ = 0.2f;
359 float ctrlY2_ = 1.0f;
360 float scaleX_ = 0.0f;
361 float scaleY_ = 0.0f;
362 float rotationX_ = 0.0f;
363 float rotationY_ = 0.0f;
364 float rotationZ_ = 0.0f;
365 int32_t angle_ = 0;
366 float translateX_ = 0.0f;
367 float translateY_ = 0.0f;
368 float opacity_ = 0;
369 };
370
371 struct StartingWindowAnimationConfig {
372 bool enabled_ = true;
373 int duration_ = 200;
374 std::string curve_ = "linear";
375 float opacityStart_ = 1;
376 float opacityEnd_ = 0;
377 };
378
379 struct AppWindowSceneConfig {
380 float floatCornerRadius_ = 0.0f;
381
382 WindowShadowConfig focusedShadow_;
383 WindowShadowConfig unfocusedShadow_;
384 KeyboardSceneAnimationConfig keyboardAnimationIn_;
385 KeyboardSceneAnimationConfig keyboardAnimationOut_;
386 WindowAnimationConfig windowAnimation_;
387 StartingWindowAnimationConfig startingWindowAnimationConfig_;
388 };
389
390 /**
391 * @brief Enumerates session gravity.
392 */
393 enum class SessionGravity : uint32_t {
394 SESSION_GRAVITY_FLOAT = 0,
395 SESSION_GRAVITY_BOTTOM,
396 SESSION_GRAVITY_DEFAULT,
397 };
398
399 /**
400 * @brief TerminateType session terminate type.
401 */
402 enum class TerminateType : uint32_t {
403 CLOSE_AND_KEEP_MULTITASK = 0,
404 CLOSE_AND_CLEAR_MULTITASK,
405 CLOSE_AND_START_CALLER,
406 CLOSE_BY_EXCEPTION,
407 };
408
409 /**
410 * @brief System animaged scene type.
411 */
412 enum class SystemAnimatedSceneType : uint32_t {
413 SCENE_ENTER_MISSION_CENTER, // Enter the mission center
414 SCENE_EXIT_MISSION_CENTER, // Exit the mission center
415 SCENE_ENTER_TFS_WINDOW, // Three-finger sliding window recovery
416 SCENE_EXIT_TFU_WINDOW, // The three-finger up window disappears
417 SCENE_ENTER_WINDOW_FULL_SCREEN, // Enter the window full screen
418 SCENE_EXIT_WINDOW_FULL_SCREEN, // Exit the window full screen
419 SCENE_ENTER_MAX_WINDOW, // Enter the window maximization state
420 SCENE_EXIT_MAX_WINDOW, // Exit the window maximization state
421 SCENE_ENTER_SPLIT_SCREEN, // Enter the split screen
422 SCENE_EXIT_SPLIT_SCREEN, // Exit the split screen
423 SCENE_ENTER_APP_CENTER, // Enter the app center
424 SCENE_EXIT_APP_CENTER, // Exit the app center
425 SCENE_APPEAR_MISSION_CENTER, // A special case scenario that displays the mission center
426 SCENE_ENTER_WIND_CLEAR, // Enter win+D in clear screen mode
427 SCENE_ENTER_WIND_RECOVER, // Enter win+D in recover mode
428 SCENE_OTHERS, // 1.Default state 2.The state in which the animation ends
429 };
430 } // namespace OHOS::Rosen
431 #endif // OHOS_ROSEN_WINDOW_SCENE_WS_COMMON_H
432