1 /* 2 * Copyright (c) 2021-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_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_INNER_ERRORS_H 17 #define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_INNER_ERRORS_H 18 19 #include <map> 20 #include <sstream> 21 #include "errors.h" 22 23 namespace OHOS { 24 namespace Notification { 25 /** 26 * ErrCode layout 27 * 28 * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 29 * | Bit |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00| 30 * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 31 * |Field|Reserved| Subsystem | Module | Code | 32 * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 33 */ 34 35 constexpr uint32_t EVENT_SUB_MODULE_OFFSET = 8; // sub-module offset value 36 37 // ANS's module const defined. 38 enum AnsModule : uint32_t { 39 ANS_MODULE_COMMON = 0x00, 40 }; 41 42 // Offset of common event sub-system's errcode base. 43 constexpr ErrCode ANS_COMMON_ERR_OFFSET = ErrCodeOffset(SUBSYS_NOTIFICATION, ANS_MODULE_COMMON); 44 45 // Error code defined. 46 enum ErrorCode : uint32_t { 47 ERR_ANS_SERVICE_NOT_READY = ANS_COMMON_ERR_OFFSET + 1, 48 ERR_ANS_SERVICE_NOT_CONNECTED, 49 ERR_ANS_INVALID_PARAM, 50 ERR_ANS_INVALID_UID, 51 ERR_ANS_NOT_SYSTEM_SERVICE, 52 ERR_ANS_INVALID_PID, 53 ERR_ANS_INVALID_BUNDLE, 54 ERR_ANS_NOT_ALLOWED, 55 ERR_ANS_PARCELABLE_FAILED, 56 ERR_ANS_TRANSACT_FAILED, 57 ERR_ANS_REMOTE_DEAD, 58 ERR_ANS_NO_MEMORY, 59 ERR_ANS_TASK_ERR, 60 ERR_ANS_NON_SYSTEM_APP, 61 ERR_ANS_PERMISSION_DENIED, 62 ERR_ANS_NOTIFICATION_NOT_EXISTS, 63 ERR_ANS_NOTIFICATION_IS_UNREMOVABLE, 64 ERR_ANS_OVER_MAX_ACTIVE_PERSECOND, 65 ERR_ANS_ICON_OVER_SIZE, 66 ERR_ANS_PICTURE_OVER_SIZE, 67 ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED, 68 ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST, 69 ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST, 70 ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, 71 ERR_ANS_PREFERENCES_NOTIFICATION_SLOTGROUP_NOT_EXIST, 72 ERR_ANS_PREFERENCES_NOTIFICATION_SLOTGROUP_ID_INVALID, 73 ERR_ANS_PREFERENCES_NOTIFICATION_SLOTGROUP_EXCEED_MAX_NUM, 74 ERR_ANS_PREFERENCES_NOTIFICATION_READ_TEMPLATE_CONFIG_FAILED, 75 ERR_ANS_DISTRIBUTED_OPERATION_FAILED, 76 ERR_ANS_DISTRIBUTED_GET_INFO_FAILED, 77 ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED, 78 ERR_ANS_GET_ACTIVE_USER_FAILED, 79 ERR_ANS_SUBSCRIBER_IS_DELETING, 80 ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, 81 ERR_ANS_DLP_HAP, 82 ERR_ANS_PUSH_CHECK_FAILED, 83 ERR_ANS_DIALOG_POP_SUCCEEDED, 84 ERR_ANS_DIALOG_IS_POPPING, 85 ERR_ANS_PUSH_CHECK_UNREGISTERED, 86 ERR_ANS_REPEAT_CREATE, 87 ERR_ANS_END_NOTIFICATION, 88 ERR_ANS_EXPIRED_NOTIFICATION, 89 ERR_ANS_PUSH_CHECK_NETWORK_UNREACHABLE, 90 ERR_ANS_PUSH_CHECK_EXTRAINFO_INVALID, 91 ERR_ANS_OVER_MAX_UPDATE_PERSECOND, 92 ERR_ANS_DUPLICATE_MSG, 93 ERR_ANS_NO_AGENT_SETTING, 94 ERR_ANS_NO_PROFILE_TEMPLATE, 95 ERR_ANS_ENCRYPT_FAIL, 96 ERR_ANS_DECRYPT_FAIL, 97 ERR_ANS_REJECTED_WITH_DISABLE_NOTIFICATION, 98 ERR_ANS_OPERATION_TIMEOUT, 99 ERR_ANS_LOCAL_SUBSCRIBE_CHECK_FAILED, 100 }; 101 102 enum ReminderErrorCode : uint32_t { 103 ERR_REMINDER_PERMISSION_DENIED = 201, 104 ERR_REMINDER_INVALID_PARAM = 401, 105 ERR_REMINDER_NOTIFICATION_NOT_ENABLE = 1700001, 106 ERR_REMINDER_NUMBER_OVERLOAD, 107 ERR_REMINDER_NOT_EXIST, 108 ERR_REMINDER_PACKAGE_NOT_EXIST, 109 ERR_REMINDER_CALLER_TOKEN_INVALID, 110 ERR_REMINDER_DATA_SHARE_PERMISSION_DENIED, 111 ERR_REMINDER_PARAM_ERROR, 112 }; 113 114 static std::map<uint32_t, std::string> reminderErrCodeMsgMap = { 115 { ERR_REMINDER_PERMISSION_DENIED, "Permission denied." }, 116 { ERR_REMINDER_INVALID_PARAM, "Parameter error." }, 117 { ERR_REMINDER_NOTIFICATION_NOT_ENABLE, "Notification not enable." }, 118 { ERR_REMINDER_NUMBER_OVERLOAD, "The number of reminders exceeds the limit." }, 119 { ERR_REMINDER_NOT_EXIST, "The reminder not exist." }, 120 { ERR_REMINDER_PACKAGE_NOT_EXIST, "The package name not exist." }, 121 { ERR_REMINDER_CALLER_TOKEN_INVALID, "The caller token invalid." }, 122 { ERR_REMINDER_DATA_SHARE_PERMISSION_DENIED, "The data share permission denied." }, 123 { ERR_REMINDER_PARAM_ERROR, "Parameter error." } 124 }; 125 126 // Notification error msg 127 static inline std::string MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED = "Mandatory parameters are left unspecified."; 128 static inline std::string INCORRECT_PARAMETER_TYPES = "Incorrect parameter types."; 129 static inline std::string PARAMETER_VERIFICATION_FAILED = "Parameter verification failed."; 130 131 // Common error code 132 const uint32_t ERROR_PERMISSION_DENIED = 201; // No permission to call the interface. 133 const uint32_t ERROR_NOT_SYSTEM_APP = 202; // Not system application to call the interface. 134 const uint32_t ERROR_PARAM_INVALID = 401; // Invalid input parameter. 135 const uint32_t ERROR_SYSTEM_CAP_ERROR = 801; // The specified SystemCapability names was not found. 136 137 // Notification error code 138 const int32_t ERROR_INTERNAL_ERROR = 1600001; // Internal error. 139 const int32_t ERROR_IPC_ERROR = 1600002; // Marshalling or unmarshalling error. 140 const int32_t ERROR_SERVICE_CONNECT_ERROR = 1600003; // Failed to connect to the service. 141 const int32_t ERROR_NOTIFICATION_CLOSED = 1600004; // Notification disabled. 142 const int32_t ERROR_SLOT_CLOSED = 1600005; // Notification slot disabled. 143 const int32_t ERROR_NOTIFICATION_UNREMOVABLE = 1600006; // Notification deletion disabled. 144 const int32_t ERROR_NOTIFICATION_NOT_EXIST = 1600007; // The notification does not exist. 145 const int32_t ERROR_USER_NOT_EXIST = 1600008; // The user does not exist. 146 // The notification sending frequency reaches the upper limit. 147 const int32_t ERROR_OVER_MAX_NUM_PER_SECOND = 1600009; 148 const int32_t ERROR_DISTRIBUTED_OPERATION_FAILED = 1600010; // Distributed operation failed. 149 const int32_t ERROR_READ_TEMPLATE_CONFIG_FAILED = 1600011; // Failed to read the template configuration. 150 const int32_t ERROR_NO_MEMORY = 1600012; // No memory space. 151 const int32_t ERROR_DIALOG_IS_POPPING = 1600013; // A notification dialog box is already displayed. 152 const int32_t ERROR_NO_RIGHT = 1600014; // No permission. 153 const int32_t ERROR_REPEAT_SET = 1600015; // Repeat create or end. 154 const int32_t ERROR_EXPIRED_NOTIFICATION = 1600016; // Low update version. 155 const int32_t ERROR_NO_AGENT_SETTING = 1600017; // No corresponding agent relationship configuration. 156 const int32_t ERROR_SETTING_WINDOW_EXIST = 1600018; // The notification settings window is already displayed. 157 const int32_t ERROR_NO_PROFILE_TEMPLATE = 1600019; // Not exit noNotDisturb profile template. 158 const int32_t ERROR_REJECTED_WITH_DISABLE_NOTIFICATION = 159 1600020; // The application is not allowed to send notifications due to permission settings. 160 const int32_t ERROR_DISTRIBUTED_OPERATION_TIMEOUT = 1600021; // Distributed operation timeout. 161 const int32_t ERROR_NETWORK_UNREACHABLE = 2300007; // Network unreachable. 162 const int32_t ERROR_BUNDLE_NOT_FOUND = 17700001; // The specified bundle name was not found. 163 164 int32_t ErrorToExternal(uint32_t errCode); 165 std::string GetAnsErrMessage(uint32_t errCode, std::string defaultMsg = ""); 166 } // namespace Notification 167 } // namespace OHOS 168 169 #endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_INNER_ERRORS_H 170