1 /*
2 * Copyright (c) 2024 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 "wm_common.h"
17 #include "window_manager_hilog.h"
18
19 namespace OHOS::Rosen {
20 const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP {
21 {WMError::WM_OK, WmErrorCode::WM_OK },
22 {WMError::WM_DO_NOTHING, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
23 {WMError::WM_ERROR_DESTROYED_OBJECT, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
24 {WMError::WM_ERROR_DEVICE_NOT_SUPPORT, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT },
25 {WMError::WM_ERROR_INVALID_OPERATION, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
26 {WMError::WM_ERROR_INVALID_PARAM, WmErrorCode::WM_ERROR_INVALID_PARAM },
27 {WMError::WM_ERROR_INVALID_PERMISSION, WmErrorCode::WM_ERROR_NO_PERMISSION },
28 {WMError::WM_ERROR_NOT_SYSTEM_APP, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP },
29 {WMError::WM_ERROR_INVALID_TYPE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
30 {WMError::WM_ERROR_INVALID_WINDOW, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
31 {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
32 {WMError::WM_ERROR_IPC_FAILED, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
33 {WMError::WM_ERROR_NO_MEM, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
34 {WMError::WM_ERROR_NO_REMOTE_ANIMATION, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
35 {WMError::WM_ERROR_INVALID_DISPLAY, WmErrorCode::WM_ERROR_INVALID_DISPLAY },
36 {WMError::WM_ERROR_INVALID_PARENT, WmErrorCode::WM_ERROR_INVALID_PARENT },
37 {WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS, WmErrorCode::WM_ERROR_INVALID_OP_IN_CUR_STATUS },
38 {WMError::WM_ERROR_REPEAT_OPERATION, WmErrorCode::WM_ERROR_REPEAT_OPERATION },
39 {WMError::WM_ERROR_NULLPTR, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
40 {WMError::WM_ERROR_SAMGR, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
41 {WMError::WM_ERROR_START_ABILITY_FAILED, WmErrorCode::WM_ERROR_START_ABILITY_FAILED },
42 {WMError::WM_ERROR_PIP_DESTROY_FAILED, WmErrorCode::WM_ERROR_PIP_DESTROY_FAILED },
43 {WMError::WM_ERROR_PIP_STATE_ABNORMALLY, WmErrorCode::WM_ERROR_PIP_STATE_ABNORMALLY },
44 {WMError::WM_ERROR_PIP_CREATE_FAILED, WmErrorCode::WM_ERROR_PIP_CREATE_FAILED },
45 {WMError::WM_ERROR_PIP_INTERNAL_ERROR, WmErrorCode::WM_ERROR_PIP_INTERNAL_ERROR },
46 {WMError::WM_ERROR_PIP_REPEAT_OPERATION, WmErrorCode::WM_ERROR_PIP_REPEAT_OPERATION },
47 {WMError::WM_ERROR_INVALID_CALLING, WmErrorCode::WM_ERROR_INVALID_CALLING },
48 {WMError::WM_ERROR_INVALID_SESSION, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
49 {WMError::WM_ERROR_SYSTEM_ABNORMALLY, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
50 {WMError::WM_ERROR_TIMEOUT, WmErrorCode::WM_ERROR_TIMEOUT },
51 {WMError::WM_ERROR_ILLEGAL_PARAM, WmErrorCode::WM_ERROR_ILLEGAL_PARAM },
52 {WMError::WM_ERROR_FB_PARAM_INVALID, WmErrorCode::WM_ERROR_FB_PARAM_INVALID },
53 {WMError::WM_ERROR_FB_CREATE_FAILED, WmErrorCode::WM_ERROR_FB_CREATE_FAILED },
54 {WMError::WM_ERROR_FB_REPEAT_CONTROLLER, WmErrorCode::WM_ERROR_FB_REPEAT_CONTROLLER },
55 {WMError::WM_ERROR_FB_REPEAT_OPERATION, WmErrorCode::WM_ERROR_FB_REPEAT_OPERATION },
56 {WMError::WM_ERROR_FB_INTERNAL_ERROR, WmErrorCode::WM_ERROR_FB_INTERNAL_ERROR },
57 {WMError::WM_ERROR_FB_STATE_ABNORMALLY, WmErrorCode::WM_ERROR_FB_STATE_ABNORMALLY },
58 {WMError::WM_ERROR_FB_INVALID_STATE, WmErrorCode::WM_ERROR_FB_INVALID_STATE },
59 {WMError::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED, WmErrorCode::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED },
60 {WMError::WM_ERROR_FB_UPDATE_TEMPLATE_TYPE_DENIED, WmErrorCode::WM_ERROR_FB_UPDATE_TEMPLATE_TYPE_DENIED },
61 {WMError::WM_ERROR_FB_UPDATE_STATIC_TEMPLATE_DENIED, WmErrorCode::WM_ERROR_FB_UPDATE_STATIC_TEMPLATE_DENIED },
62 {WMError::WM_ERROR_UI_EFFECT_ERROR, WmErrorCode::WM_ERROR_UI_EFFECT_ERROR },
63 };
64
ConvertErrorToCode(WMError error)65 WmErrorCode ConvertErrorToCode(WMError error)
66 {
67 auto iter = WM_JS_TO_ERROR_CODE_MAP.find(error);
68 if (iter != WM_JS_TO_ERROR_CODE_MAP.end()) {
69 return iter->second;
70 }
71 TLOGE(WmsLogTag::DEFAULT, "not find error::%{public}d", static_cast<int32_t>(error));
72 return WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY;
73 }
74 }