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 "inner_errors.h" 17 #include "notification_manager_log.h" 18 19 namespace OHOS { 20 namespace CJSystemapi { 21 namespace Notification { ErrorToExternal(uint32_t errCode)22 int32_t ErrorToExternal(uint32_t errCode) 23 { 24 static std::vector<std::pair<uint32_t, int32_t>> errorsConvert = { 25 {ERR_ANS_PERMISSION_DENIED, ERROR_PERMISSION_DENIED}, 26 {ERR_ANS_NON_SYSTEM_APP, ERROR_NOT_SYSTEM_APP}, 27 {ERR_ANS_NOT_SYSTEM_SERVICE, ERROR_NOT_SYSTEM_APP}, 28 {ERR_ANS_INVALID_PARAM, ERROR_PARAM_INVALID}, 29 {ERR_ANS_INVALID_UID, ERROR_PARAM_INVALID}, 30 {ERR_ANS_ICON_OVER_SIZE, ERROR_PARAM_INVALID}, 31 {ERR_ANS_PICTURE_OVER_SIZE, ERROR_PARAM_INVALID}, 32 {ERR_ANS_PUSH_CHECK_EXTRAINFO_INVALID, ERROR_PARAM_INVALID}, 33 {ERR_ANS_NO_MEMORY, ERROR_NO_MEMORY}, 34 {ERR_ANS_TASK_ERR, ERROR_INTERNAL_ERROR}, 35 {ERR_ANS_PARCELABLE_FAILED, ERROR_IPC_ERROR}, 36 {ERR_ANS_TRANSACT_FAILED, ERROR_IPC_ERROR}, 37 {ERR_ANS_REMOTE_DEAD, ERROR_IPC_ERROR}, 38 {ERR_ANS_SERVICE_NOT_READY, ERROR_SERVICE_CONNECT_ERROR}, 39 {ERR_ANS_SERVICE_NOT_CONNECTED, ERROR_SERVICE_CONNECT_ERROR}, 40 {ERR_ANS_NOT_ALLOWED, ERROR_NOTIFICATION_CLOSED}, 41 {ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, ERROR_SLOT_CLOSED}, 42 {ERR_ANS_NOTIFICATION_IS_UNREMOVABLE, ERROR_NOTIFICATION_UNREMOVABLE}, 43 {ERR_ANS_NOTIFICATION_NOT_EXISTS, ERROR_NOTIFICATION_NOT_EXIST}, 44 {ERR_ANS_GET_ACTIVE_USER_FAILED, ERROR_USER_NOT_EXIST}, 45 {ERR_ANS_INVALID_PID, ERROR_BUNDLE_NOT_FOUND}, 46 {ERR_ANS_INVALID_BUNDLE, ERROR_BUNDLE_NOT_FOUND}, 47 {ERR_ANS_OVER_MAX_ACTIVE_PERSECOND, ERROR_OVER_MAX_NUM_PER_SECOND}, 48 {ERR_ANS_DISTRIBUTED_OPERATION_FAILED, ERROR_DISTRIBUTED_OPERATION_FAILED}, 49 {ERR_ANS_DISTRIBUTED_GET_INFO_FAILED, ERROR_DISTRIBUTED_OPERATION_FAILED}, 50 {ERR_ANS_PREFERENCES_NOTIFICATION_READ_TEMPLATE_CONFIG_FAILED, ERROR_READ_TEMPLATE_CONFIG_FAILED}, 51 {ERR_ANS_REPEAT_CREATE, ERROR_REPEAT_SET}, 52 {ERR_ANS_END_NOTIFICATION, ERROR_REPEAT_SET}, 53 {ERR_ANS_EXPIRED_NOTIFICATION, ERROR_EXPIRED_NOTIFICATION}, 54 {ERR_ANS_PUSH_CHECK_FAILED, ERROR_NO_RIGHT}, 55 {ERR_ANS_PUSH_CHECK_UNREGISTERED, ERROR_NO_RIGHT}, 56 {ERR_ANS_PUSH_CHECK_NETWORK_UNREACHABLE, ERROR_NETWORK_UNREACHABLE} 57 }; 58 59 int32_t externalCode = SUCCESS_CODE; 60 for (const auto &errorConvert : errorsConvert) { 61 if (errCode == errorConvert.first) { 62 externalCode = errorConvert.second; 63 break; 64 } 65 } 66 67 LOGI("internal errorCode[%{public}u] to external errorCode[%{public}d]", errCode, externalCode); 68 return externalCode; 69 } 70 71 } // namespace Notification 72 } // namespace CJSystemapi 73 } // namespace OHOS 74