1 /* 2 * Copyright (c) 2025 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 BASE_NOTIFICATION_COMMON_EVENT_MANAGER_INCLUDE_ANI_EVENT_ERRORS_UTILS_H 17 #define BASE_NOTIFICATION_COMMON_EVENT_MANAGER_INCLUDE_ANI_EVENT_ERRORS_UTILS_H 18 19 #include <ani.h> 20 #include <string> 21 22 #include "errors.h" 23 24 namespace OHOS { 25 namespace EventManagerFwkAni { 26 using namespace std; 27 28 constexpr const char *BUSINESS_ERROR_CLASS = "L@ohos/base/BusinessError;"; 29 constexpr const char *ERROR_CLASS_NAME = "Lescompat/Error;"; 30 31 constexpr const char* ERROR_MSG_PERMISSION_DENIED = "The application does not have permission to call the interface."; 32 constexpr const char* ERROR_MSG_NOT_SYSTEM_APP = "The application is not system-app, can not use system-api."; 33 constexpr const char* ERROR_MSG_INVALID_PARAM = "Invalid input parameter."; 34 constexpr const char* ERROR_MSG_CAPABILITY_NOT_SUPPORT = "Capability not support."; 35 constexpr const char* ERROR_MSG_INNER = "Internal error."; 36 constexpr const char* ERROR_MSG_RESOLVE_ABILITY = "The specified ability does not exist."; 37 constexpr const char* ERROR_MSG_INVALID_ABILITY_TYPE = "Incorrect ability type."; 38 constexpr const char* ERROR_MSG_INVISIBLE = "Failed to start the invisible ability."; 39 constexpr const char* ERROR_MSG_STATIC_CFG_PERMISSION = "The specified process does not have the permission."; 40 constexpr const char* ERROR_MSG_CROSS_USER = "Cross-user operations are not allowed."; 41 constexpr const char* ERROR_MSG_CROWDTEST_EXPIRED = "The crowdtesting application expires."; 42 constexpr const char* ERROR_MSG_WUKONG_MODE = "An ability cannot be started or stopped in Wukong mode."; 43 constexpr const char* ERROR_MSG_NOT_TOP_ABILITY = "The ability is not on the top of the UI."; 44 constexpr const char* ERROR_MSG_FREE_INSTALL_TIMEOUT = "Installation-free timed out."; 45 constexpr const char* ERROR_MSG_INVALID_CALLER = "The caller has been released."; 46 constexpr const char* ERROR_MSG_NOT_SELF_APPLICATION = "The target application is not the current application."; 47 constexpr const char* ERROR_MSG_INVALID_CONTEXT = "The context does not exist."; 48 49 enum { 50 // success 51 ERROR_OK = 0, 52 53 // no such permission. 54 ERROR_CODE_PERMISSION_DENIED = 201, 55 56 // non-system-app use system-api. 57 ERROR_CODE_NOT_SYSTEM_APP = 202, 58 59 // invalid param. 60 ERROR_CODE_INVALID_PARAM = 401, 61 62 // capability not support. 63 ERROR_CODE_CAPABILITY_NOT_SUPPORT = 801, 64 65 // common inner error. 66 ERROR_CODE_INNER = 16000050, 67 68 // can not find target ability. 69 ERROR_CODE_RESOLVE_ABILITY = 16000001, 70 71 // ability type is wrong. 72 ERROR_CODE_INVALID_ABILITY_TYPE = 16000002, 73 74 // no start invisible ability permission. 75 ERROR_CODE_NO_INVISIBLE_PERMISSION = 16000004, 76 77 // check static permission failed. 78 ERROR_CODE_STATIC_CFG_PERMISSION = 16000005, 79 80 // no permission to cross user. 81 ERROR_CODE_CROSS_USER = 16000006, 82 83 // crowdtest app expiration. 84 ERROR_CODE_CROWDTEST_EXPIRED = 16000008, 85 86 // wukong mode. 87 ERROR_CODE_WUKONG_MODE = 16000009, 88 89 // context is invalid. 90 ERROR_CODE_INVALID_CONTEXT = 16000011, 91 92 // not top ability, not enable to free install. 93 ERROR_CODE_NOT_TOP_ABILITY = 16000053, 94 95 // free install timeout. 96 ERROR_CODE_FREE_INSTALL_TIMEOUT = 16000055, 97 98 // invalid caller. 99 ERROR_CODE_INVALID_CALLER = 16200001, 100 101 // not self application. 102 ERROR_NOT_SELF_APPLICATION = 16300003, 103 }; 104 105 static std::unordered_map<int32_t, const char*> ERR_CODE_MAP = { 106 { ERROR_CODE_PERMISSION_DENIED, ERROR_MSG_PERMISSION_DENIED }, 107 { ERROR_CODE_NOT_SYSTEM_APP, ERROR_MSG_NOT_SYSTEM_APP }, 108 { ERROR_CODE_INVALID_PARAM, ERROR_MSG_INVALID_PARAM }, 109 { ERROR_CODE_CAPABILITY_NOT_SUPPORT, ERROR_MSG_CAPABILITY_NOT_SUPPORT }, 110 { ERROR_CODE_INNER, ERROR_MSG_INNER }, 111 { ERROR_CODE_RESOLVE_ABILITY, ERROR_MSG_RESOLVE_ABILITY }, 112 { ERROR_CODE_INVALID_ABILITY_TYPE, ERROR_MSG_INVALID_ABILITY_TYPE }, 113 { ERROR_CODE_INVALID_CONTEXT, ERROR_MSG_INVALID_CONTEXT }, 114 { ERROR_CODE_NO_INVISIBLE_PERMISSION, ERROR_MSG_INVISIBLE }, 115 { ERROR_CODE_STATIC_CFG_PERMISSION, ERROR_MSG_STATIC_CFG_PERMISSION }, 116 { ERROR_CODE_CROSS_USER, ERROR_MSG_CROSS_USER }, 117 { ERROR_CODE_CROWDTEST_EXPIRED, ERROR_MSG_CROWDTEST_EXPIRED }, 118 { ERROR_CODE_WUKONG_MODE, ERROR_MSG_WUKONG_MODE }, 119 { ERROR_CODE_NOT_TOP_ABILITY, ERROR_MSG_NOT_TOP_ABILITY }, 120 { ERROR_CODE_FREE_INSTALL_TIMEOUT, ERROR_MSG_FREE_INSTALL_TIMEOUT }, 121 { ERROR_CODE_INVALID_CALLER, ERROR_MSG_INVALID_CALLER }, 122 { ERROR_NOT_SELF_APPLICATION, ERROR_MSG_NOT_SELF_APPLICATION }, 123 }; 124 125 int32_t GetExternalCode(int32_t errCode); 126 std::string FindErrorMsg(const int32_t errCode); 127 ani_object CreateError(ani_env *env, ani_int code, const std::string &msg); 128 ani_object WrapError(ani_env *env, const std::string &msg); 129 void ThrowError(ani_env *env, int32_t errCode); 130 void ThrowErrorByNativeError(ani_env *env, int32_t innerCode); 131 } // namespace EventManagerFwkAni 132 } // namespace OHOS 133 #endif // BASE_NOTIFICATION_COMMON_EVENT_MANAGER_INCLUDE_ANI_EVENT_ERRORS_UTILS_H