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 #ifndef INNER_ERRORS_H 17 #define INNER_ERRORS_H 18 19 #include <cstdint> 20 #include <string> 21 #include <unordered_map> 22 23 namespace OHOS { 24 /** 25 * ErrCode layout 26 * 27 * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 28 * | 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| 29 * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 30 * |Field|Reserved| Subsystem | Module | Code | 31 * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 32 */ 33 34 using ErrCode = int; 35 namespace CJSystemapi { 36 namespace Notification { 37 const int32_t SUCCESS_CODE = 0; 38 39 // be used to init the subsystem errorno. 40 /** 41 * @brief Generate base error code for a specified module in specified 42 * subsystem. 43 * 44 * @param subsystem Value of 'Subsystem' segment. 45 * @param module Value of 'Module' segment, 46 * which is 0 by default. 47 * @return Return base ErrCode for specified module. 48 */ 49 constexpr ErrCode ErrCodeOffset(unsigned int subsystem, unsigned int module = 0) 50 { 51 constexpr int subsystemBitNum = 21; 52 constexpr int moduleBitNum = 16; 53 return (subsystem << subsystemBitNum) | (module << moduleBitNum); 54 } 55 56 constexpr uint32_t SUBSYS_NOTIFICATION = 32; 57 58 // ANS's module const defined. 59 enum AnsModule : uint32_t { 60 ANS_MODULE_COMMON = 0x00, 61 }; 62 63 constexpr ErrCode ANS_COMMON_ERR_OFFSET = ErrCodeOffset(SUBSYS_NOTIFICATION, ANS_MODULE_COMMON); 64 // Error code defined. 65 enum ErrorCode : uint32_t { 66 ERR_ANS_SERVICE_NOT_READY = ANS_COMMON_ERR_OFFSET + 1, 67 ERR_ANS_SERVICE_NOT_CONNECTED, 68 ERR_ANS_INVALID_PARAM, 69 ERR_ANS_INVALID_UID, 70 ERR_ANS_NOT_SYSTEM_SERVICE, 71 ERR_ANS_INVALID_PID, 72 ERR_ANS_INVALID_BUNDLE, 73 ERR_ANS_NOT_ALLOWED, 74 ERR_ANS_PARCELABLE_FAILED, 75 ERR_ANS_TRANSACT_FAILED, 76 ERR_ANS_REMOTE_DEAD, 77 ERR_ANS_NO_MEMORY, 78 ERR_ANS_TASK_ERR, 79 ERR_ANS_NON_SYSTEM_APP, 80 ERR_ANS_PERMISSION_DENIED, 81 ERR_ANS_NOTIFICATION_NOT_EXISTS, 82 ERR_ANS_NOTIFICATION_IS_UNREMOVABLE, 83 ERR_ANS_OVER_MAX_ACTIVE_PERSECOND, 84 ERR_ANS_ICON_OVER_SIZE, 85 ERR_ANS_PICTURE_OVER_SIZE, 86 ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED, 87 ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST, 88 ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST, 89 ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, 90 ERR_ANS_PREFERENCES_NOTIFICATION_SLOTGROUP_NOT_EXIST, 91 ERR_ANS_PREFERENCES_NOTIFICATION_SLOTGROUP_ID_INVALID, 92 ERR_ANS_PREFERENCES_NOTIFICATION_SLOTGROUP_EXCEED_MAX_NUM, 93 ERR_ANS_PREFERENCES_NOTIFICATION_READ_TEMPLATE_CONFIG_FAILED, 94 ERR_ANS_DISTRIBUTED_OPERATION_FAILED, 95 ERR_ANS_DISTRIBUTED_GET_INFO_FAILED, 96 ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED, 97 ERR_ANS_GET_ACTIVE_USER_FAILED, 98 ERR_ANS_SUBSCRIBER_IS_DELETING, 99 ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, 100 ERR_ANS_DLP_HAP, 101 ERR_ANS_PUSH_CHECK_FAILED, 102 ERR_ANS_DIALOG_POP_SUCCEEDED, 103 ERR_ANS_DIALOG_IS_POPPING, 104 ERR_ANS_PUSH_CHECK_UNREGISTERED, 105 ERR_ANS_REPEAT_CREATE, 106 ERR_ANS_END_NOTIFICATION, 107 ERR_ANS_EXPIRED_NOTIFICATION, 108 ERR_ANS_PUSH_CHECK_NETWORK_UNREACHABLE, 109 ERR_ANS_PUSH_CHECK_EXTRAINFO_INVALID, 110 ERR_ANS_NO_PROFILE_TEMPLATE, 111 }; 112 // Common error code 113 const uint32_t ERROR_PERMISSION_DENIED = 201; // No permission to call the interface. 114 const uint32_t ERROR_NOT_SYSTEM_APP = 202; // Not system application to call the interface. 115 const uint32_t ERROR_PARAM_INVALID = 401; // Invalid input parameter. 116 const uint32_t ERROR_SYSTEM_CAP_ERROR = 801; // The specified SystemCapability names was not found. 117 118 // Notification error code 119 const int32_t ERROR_INTERNAL_ERROR = 1600001; // Internal error. 120 const int32_t ERROR_IPC_ERROR = 1600002; // Marshalling or unmarshalling error. 121 const int32_t ERROR_SERVICE_CONNECT_ERROR = 1600003; // Failed to connect to the service. 122 const int32_t ERROR_NOTIFICATION_CLOSED = 1600004; // Notification disabled. 123 const int32_t ERROR_SLOT_CLOSED = 1600005; // Notification slot disabled. 124 const int32_t ERROR_NOTIFICATION_UNREMOVABLE = 1600006; // Notification deletion disabled. 125 const int32_t ERROR_NOTIFICATION_NOT_EXIST = 1600007; // The notification does not exist. 126 const int32_t ERROR_USER_NOT_EXIST = 1600008; // The user does not exist. 127 // The notification sending frequency reaches the upper limit. 128 const int32_t ERROR_OVER_MAX_NUM_PER_SECOND = 1600009; 129 const int32_t ERROR_DISTRIBUTED_OPERATION_FAILED = 1600010; // Distributed operation failed. 130 const int32_t ERROR_READ_TEMPLATE_CONFIG_FAILED = 1600011; // Failed to read the template configuration. 131 const int32_t ERROR_NO_MEMORY = 1600012; // No memory space. 132 const int32_t ERROR_DIALOG_IS_POPPING = 1600013; // A notification dialog box is already displayed. 133 const int32_t ERROR_NO_RIGHT = 1600014; // No permission. 134 const int32_t ERROR_REPEAT_SET = 1600015; // Repeat create or end. 135 const int32_t ERROR_EXPIRED_NOTIFICATION = 1600016; // Low update version. 136 const int32_t ERROR_SETTING_WINDOW_EXIST = 1600018; // The notification settings window is already displayed. 137 const int32_t ERROR_NO_PROFILE_TEMPLATE = 1600019; // Not exit noNotDisturb profile template. 138 const int32_t ERROR_NETWORK_UNREACHABLE = 2300007; // Network unreachable. 139 const int32_t ERROR_BUNDLE_NOT_FOUND = 17700001; // The specified bundle name was not found. 140 141 int32_t ErrorToExternal(uint32_t errCode); 142 } // namespace Notification 143 } // namespace CJSystemapi 144 } // namespace OHOS 145 146 #endif 147