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 <map> 21 #include <string> 22 #include <want.h> 23 24 #include "iremote_broker.h" 25 26 namespace OHOS::AAFwk { 27 class AbilityStartSetting; 28 } 29 namespace OHOS::AppExecFwk { 30 struct AbilityInfo; 31 } 32 33 namespace OHOS::Rosen { 34 constexpr int32_t INVALID_SESSION_ID = 0; 35 36 enum class WSError : int32_t { 37 WS_OK = 0, 38 WS_DO_NOTHING, 39 WS_ERROR_NO_MEM, 40 WS_ERROR_DESTROYED_OBJECT, 41 WS_ERROR_INVALID_WINDOW, 42 WS_ERROR_INVALID_WINDOW_MODE_OR_SIZE, 43 WS_ERROR_INVALID_OPERATION, 44 WS_ERROR_INVALID_PERMISSION, 45 WS_ERROR_NOT_SYSTEM_APP, 46 WS_ERROR_NO_REMOTE_ANIMATION, 47 WS_ERROR_INVALID_DISPLAY, 48 WS_ERROR_INVALID_PARENT, 49 WS_ERROR_OPER_FULLSCREEN_FAILED, 50 WS_ERROR_REPEAT_OPERATION, 51 WS_ERROR_INVALID_SESSION, 52 WS_ERROR_UNCLEARABLE_SESSION, 53 WS_ERROR_FAIL_TO_GET_SNAPSHOT, 54 55 WS_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system 56 57 WS_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report 58 WS_ERROR_NULLPTR, 59 WS_ERROR_INVALID_TYPE, 60 WS_ERROR_INVALID_PARAM, 61 WS_ERROR_SAMGR, 62 WS_ERROR_IPC_FAILED, 63 WS_ERROR_NEED_REPORT_END, 64 WS_ERROR_START_ABILITY_FAILED, 65 WS_ERROR_SET_SESSION_LABEL_FAILED, 66 WS_ERROR_SET_SESSION_ICON_FAILED, 67 WS_ERROR_INVALID_SESSION_LISTENER, 68 WS_ERROR_START_UI_EXTENSION_ABILITY_FAILED, 69 WS_ERROR_MIN_UI_EXTENSION_ABILITY_FAILED, 70 WS_ERROR_TERMINATE_UI_EXTENSION_ABILITY_FAILED, 71 }; 72 73 enum class WSErrorCode : int32_t { 74 WS_OK = 0, 75 WS_ERROR_NO_PERMISSION = 201, 76 WS_ERROR_INVALID_PARAM = 401, 77 WS_ERROR_DEVICE_NOT_SUPPORT = 801, 78 WS_ERROR_TIMEOUT = 901, 79 WS_ERROR_REPEAT_OPERATION = 1300001, 80 WS_ERROR_STATE_ABNORMALLY = 1300002, 81 WS_ERROR_SYSTEM_ABNORMALLY = 1300003, 82 WS_ERROR_INVALID_CALLING = 1300004, 83 WS_ERROR_STAGE_ABNORMALLY = 1300005, 84 WS_ERROR_CONTEXT_ABNORMALLY = 1300006, 85 }; 86 87 const std::map<WSError, WSErrorCode> WS_JS_TO_ERROR_CODE_MAP { 88 { WSError::WS_OK, WSErrorCode::WS_OK }, 89 { WSError::WS_DO_NOTHING, WSErrorCode::WS_ERROR_STATE_ABNORMALLY }, 90 { WSError::WS_ERROR_INVALID_SESSION, WSErrorCode::WS_ERROR_STATE_ABNORMALLY }, 91 { WSError::WS_ERROR_INVALID_PARAM, WSErrorCode::WS_ERROR_STATE_ABNORMALLY }, 92 { WSError::WS_ERROR_IPC_FAILED, WSErrorCode::WS_ERROR_SYSTEM_ABNORMALLY }, 93 { WSError::WS_ERROR_NULLPTR, WSErrorCode::WS_ERROR_STATE_ABNORMALLY }, 94 }; 95 96 enum class SessionState : uint32_t { 97 STATE_DISCONNECT = 0, 98 STATE_CONNECT, 99 STATE_FOREGROUND, 100 STATE_ACTIVE, 101 STATE_INACTIVE, 102 STATE_BACKGROUND, 103 STATE_END, 104 }; 105 106 enum ContinueState { 107 CONTINUESTATE_UNKNOWN = -1, 108 CONTINUESTATE_ACTIVE = 0, 109 CONTINUESTATE_INACTIVE = 1, 110 CONTINUESTATE_MAX 111 }; 112 113 enum class StartMethod : int32_t { 114 START_NORMAL, 115 START_CALL 116 }; 117 118 /** 119 * @brief collaborator type. 120 */ 121 enum CollaboratorType : int32_t { 122 DEFAULT_TYPE = 0, 123 RESERVE_TYPE, 124 OTHERS_TYPE, 125 }; 126 127 struct SessionInfo { 128 std::string bundleName_ = ""; 129 std::string moduleName_ = ""; 130 std::string abilityName_ = ""; 131 bool isSystem_ = false; 132 uint32_t windowType_ = 1; // WINDOW_TYPE_APP_MAIN_WINDOW 133 sptr<IRemoteObject> callerToken_ = nullptr; 134 135 mutable sptr<AAFwk::Want> want; 136 std::shared_ptr<AAFwk::AbilityStartSetting> startSetting = nullptr; 137 mutable std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = nullptr; 138 int32_t resultCode; 139 int32_t requestCode; 140 int32_t errorCode; 141 std::string errorReason; 142 int32_t persistentId_ = INVALID_SESSION_ID; 143 int32_t callerPersistentId_ = INVALID_SESSION_ID; 144 uint32_t callState_ = 0; 145 uint32_t callingTokenId_ = 0; 146 bool reuse = false; 147 StartMethod startMethod = StartMethod::START_NORMAL; 148 bool lockedState = false; 149 std::string time; 150 ContinueState continueState = ContinueState::CONTINUESTATE_ACTIVE; 151 int64_t uiAbilityId_ = 0; 152 }; 153 154 enum class SessionFlag : uint32_t { 155 SESSION_FLAG_NEED_AVOID = 1, 156 SESSION_FLAG_PARENT_LIMIT = 1 << 1, 157 SESSION_FLAG_SHOW_WHEN_LOCKED = 1 << 2, 158 SESSION_FLAG_FORBID_SPLIT_MOVE = 1 << 3, 159 SESSION_FLAG_WATER_MARK = 1 << 4, 160 SESSION_FLAG_END = 1 << 5, 161 }; 162 163 enum class SizeChangeReason : uint32_t { 164 UNDEFINED = 0, 165 MAXIMIZE, 166 RECOVER, 167 ROTATION, 168 DRAG, 169 DRAG_START, 170 DRAG_END, 171 RESIZE, 172 MOVE, 173 HIDE, 174 TRANSFORM, 175 CUSTOM_ANIMATION_SHOW, 176 FULL_TO_SPLIT, 177 SPLIT_TO_FULL, 178 END, 179 }; 180 181 enum class SessionEvent : uint32_t { 182 EVENT_MAXIMIZE = 100, 183 EVENT_RECOVER, 184 EVENT_MINIMIZE, 185 EVENT_CLOSE, 186 EVENT_START_MOVE, 187 EVENT_END_MOVE, 188 EVENT_MAXIMIZE_FLOATING, 189 EVENT_TERMINATE, 190 EVENT_EXCEPTION, 191 EVENT_SPLIT_PRIMARY, 192 EVENT_SPLIT_SECONDARY, 193 }; 194 195 struct WSRect { 196 int32_t posX_ = 0; 197 int32_t posY_ = 0; 198 uint32_t width_ = 0; 199 uint32_t height_ = 0; 200 201 bool operator==(const WSRect& a) const 202 { 203 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_); 204 } 205 206 bool operator!=(const WSRect& a) const 207 { 208 return !this->operator==(a); 209 } 210 IsEmptyWSRect211 bool IsEmpty() const 212 { 213 if (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0) { 214 return true; 215 } 216 return false; 217 } 218 }; 219 220 struct WindowShadowConfig { 221 float offsetX_ = 0.0f; 222 float offsetY_ = 0.0f; 223 float alpha_ = 0.0f; 224 float radius_ = 0.0f; 225 std::string color_ = "#000000"; 226 }; 227 228 struct KeyboardSceneAnimationConfig { 229 std::string curveType_ = "default"; 230 float ctrlX1_ = 0.2f; 231 float ctrlY1_ = 0.0f; 232 float ctrlX2_ = 0.2f; 233 float ctrlY2_ = 1.0f; 234 uint32_t durationIn_ = 150; // default durationIn time 235 uint32_t durationOut_ = 150; // default durationOut time 236 }; 237 238 struct WindowAnimationConfig { 239 int32_t duration_ = 0; 240 std::string curveType_ = "easeOut"; 241 float ctrlX1_ = 0.2f; 242 float ctrlY1_ = 0.0f; 243 float ctrlX2_ = 0.2f; 244 float ctrlY2_ = 1.0f; 245 float scaleX_ = 0.0f; 246 float scaleY_ = 0.0f; 247 float rotationX_ = 0.0f; 248 float rotationY_ = 0.0f; 249 float rotationZ_ = 0.0f; 250 int32_t angle_ = 0; 251 float translateX_ = 0.0f; 252 float translateY_ = 0.0f; 253 float opacity_ = 0; 254 }; 255 256 struct StartingWindowAnimationConfig { 257 bool enabled_ = true; 258 int duration_ = 200; 259 std::string curve_ = "linear"; 260 float opacityStart_ = 1; 261 float opacityEnd_ = 0; 262 }; 263 264 struct AppWindowSceneConfig { 265 float floatCornerRadius_ = 0.0f; 266 267 WindowShadowConfig focusedShadow_; 268 WindowShadowConfig unfocusedShadow_; 269 KeyboardSceneAnimationConfig keyboardAnimation_; 270 WindowAnimationConfig windowAnimation_; 271 StartingWindowAnimationConfig startingWindowAnimationConfig_; 272 }; 273 274 /** 275 * @brief Enumerates session gravity. 276 */ 277 enum class SessionGravity : uint32_t { 278 SESSION_GRAVITY_FLOAT = 0, 279 SESSION_GRAVITY_BOTTOM, 280 }; 281 282 /** 283 * @brief TerminateType session terminate type. 284 */ 285 enum class TerminateType : uint32_t { 286 CLOSE_AND_KEEP_MULTITASK = 0, 287 CLOSE_AND_CLEAR_MULTITASK, 288 CLOSE_AND_START_CALLER, 289 CLOSE_BY_EXCEPTION, 290 }; 291 } // namespace OHOS::Rosen 292 #endif // OHOS_ROSEN_WINDOW_SCENE_WS_COMMON_H 293