diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 22bc47c61a37fafbadb906025ed15eac9f0e7ce7..6a7fcd5cfb2cf889c43bfa3e42d1534198209992 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -72,6 +72,7 @@ ohos_shared_library("ans_innerkits") { sources = [ "${core_path}/common/src/ans_convert_enum.cpp", + "${core_path}/common/src/ans_inner_errors.cpp", "${core_path}/src/ans_image_util.cpp", "${core_path}/src/ans_notification.cpp", "${core_path}/src/dialog_status_data.cpp", diff --git a/frameworks/core/common/include/ans_inner_errors.h b/frameworks/core/common/include/ans_inner_errors.h index 1ec6e8744de3beb49c0c1e0043572823320e0f85..8a642b6093df2ea236e5fcdfae834805503cad5b 100644 --- a/frameworks/core/common/include/ans_inner_errors.h +++ b/frameworks/core/common/include/ans_inner_errors.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -159,6 +159,9 @@ const int32_t ERROR_REJECTED_WITH_DISABLE_NOTIFICATION = const int32_t ERROR_DISTRIBUTED_OPERATION_TIMEOUT = 1600021; // Distributed operation timeout. const int32_t ERROR_NETWORK_UNREACHABLE = 2300007; // Network unreachable. const int32_t ERROR_BUNDLE_NOT_FOUND = 17700001; // The specified bundle name was not found. + +int32_t ErrorToExternal(uint32_t errCode); +std::string GetAnsErrMessage(uint32_t errCode, std::string defaultMsg = ""); } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/common/src/ans_inner_errors.cpp b/frameworks/core/common/src/ans_inner_errors.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18fbed802188c4d282cfb1e33e8f8bdfa9f98966 --- /dev/null +++ b/frameworks/core/common/src/ans_inner_errors.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ans_inner_errors.h" + +#include "ans_log_wrapper.h" +#include "ipc_types.h" + +namespace OHOS { +namespace Notification { +static const std::unordered_map ANS_ERROR_CODE_MESSAGE_MAP = { + {ERROR_PERMISSION_DENIED, "Permission denied"}, + {ERROR_NOT_SYSTEM_APP, "The application isn't system application"}, + {ERROR_PARAM_INVALID, "Invalid parameter"}, + {ERROR_SYSTEM_CAP_ERROR, "SystemCapability not found"}, + {ERROR_INTERNAL_ERROR, "Internal error. Possible cause: 1.IPC communication failed. 2.Memory operation error"}, + {ERROR_IPC_ERROR, "Marshalling or unmarshalling error"}, + {ERROR_SERVICE_CONNECT_ERROR, "Failed to connect to the service"}, + {ERROR_NOTIFICATION_CLOSED, "Notification disabled"}, + {ERROR_SLOT_CLOSED, "Notification slot disabled"}, + {ERROR_NOTIFICATION_UNREMOVABLE, "Notification deletion disabled"}, + {ERROR_NOTIFICATION_NOT_EXIST, "The notification does not exist"}, + {ERROR_USER_NOT_EXIST, "The user does not exist"}, + {ERROR_OVER_MAX_NUM_PER_SECOND, "The notification sending frequency reaches the upper limit"}, + {ERROR_DISTRIBUTED_OPERATION_FAILED, "Distributed operation failed"}, + {ERROR_READ_TEMPLATE_CONFIG_FAILED, "Failed to read the template configuration"}, + {ERROR_NO_MEMORY, "Memory operation failed"}, + {ERROR_BUNDLE_NOT_FOUND, "The specified bundle name was not found"}, + {ERROR_NO_AGENT_SETTING, "There is no corresponding agent relationship configuration"}, + {ERROR_DIALOG_IS_POPPING, "Dialog is popping"}, + {ERROR_SETTING_WINDOW_EXIST, "The notification settings window is already displayed"}, + {ERROR_NO_PROFILE_TEMPLATE, "Not exit noNotDisturb profile template"}, + {ERROR_REPEAT_SET, "Repeat create or end"}, + {ERROR_NO_RIGHT, "The specified process does not have the permission"}, + {ERROR_EXPIRED_NOTIFICATION, "Low update version"}, + {ERROR_NETWORK_UNREACHABLE, "Network unreachable"}, + {ERROR_REJECTED_WITH_DISABLE_NOTIFICATION, + "The application is not allowed to publish notifications due to permission control settings"}, + {ERROR_DISTRIBUTED_OPERATION_TIMEOUT, "Distributed operation timeout"}, +}; + +static std::vector> errorsConvert = { + {ERR_ANS_PERMISSION_DENIED, ERROR_PERMISSION_DENIED}, + {ERR_ANS_NON_SYSTEM_APP, ERROR_NOT_SYSTEM_APP}, + {ERR_ANS_NOT_SYSTEM_SERVICE, ERROR_NOT_SYSTEM_APP}, + {ERR_ANS_INVALID_PARAM, ERROR_PARAM_INVALID}, + {ERR_ANS_INVALID_UID, ERROR_PARAM_INVALID}, + {ERR_ANS_ICON_OVER_SIZE, ERROR_PARAM_INVALID}, + {ERR_ANS_PICTURE_OVER_SIZE, ERROR_PARAM_INVALID}, + {ERR_ANS_PUSH_CHECK_EXTRAINFO_INVALID, ERROR_PARAM_INVALID}, + {ERR_ANS_NO_MEMORY, ERROR_NO_MEMORY}, + {ERR_ANS_TASK_ERR, ERROR_INTERNAL_ERROR}, + {ERR_ANS_PARCELABLE_FAILED, ERROR_IPC_ERROR}, + {ERR_ANS_TRANSACT_FAILED, ERROR_IPC_ERROR}, + {ERR_ANS_REMOTE_DEAD, ERROR_IPC_ERROR}, + {ERR_INVALID_VALUE, ERROR_IPC_ERROR}, + {ERR_INVALID_DATA, ERROR_IPC_ERROR}, + {DEAD_OBJECT, ERROR_IPC_ERROR}, + {ERR_ANS_SERVICE_NOT_READY, ERROR_SERVICE_CONNECT_ERROR}, + {ERR_ANS_SERVICE_NOT_CONNECTED, ERROR_SERVICE_CONNECT_ERROR}, + {ERR_ANS_NOT_ALLOWED, ERROR_NOTIFICATION_CLOSED}, + {ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, ERROR_SLOT_CLOSED}, + {ERR_ANS_NOTIFICATION_IS_UNREMOVABLE, ERROR_NOTIFICATION_UNREMOVABLE}, + {ERR_ANS_NOTIFICATION_NOT_EXISTS, ERROR_NOTIFICATION_NOT_EXIST}, + {ERR_ANS_GET_ACTIVE_USER_FAILED, ERROR_USER_NOT_EXIST}, + {ERR_ANS_INVALID_PID, ERROR_BUNDLE_NOT_FOUND}, + {ERR_ANS_INVALID_BUNDLE, ERROR_BUNDLE_NOT_FOUND}, + {ERR_ANS_OVER_MAX_ACTIVE_PERSECOND, ERROR_OVER_MAX_NUM_PER_SECOND}, + {ERR_ANS_OVER_MAX_UPDATE_PERSECOND, ERROR_OVER_MAX_NUM_PER_SECOND}, + {ERR_ANS_DISTRIBUTED_OPERATION_FAILED, ERROR_DISTRIBUTED_OPERATION_FAILED}, + {ERR_ANS_DISTRIBUTED_GET_INFO_FAILED, ERROR_DISTRIBUTED_OPERATION_FAILED}, + {ERR_ANS_PREFERENCES_NOTIFICATION_READ_TEMPLATE_CONFIG_FAILED, ERROR_READ_TEMPLATE_CONFIG_FAILED}, + {ERR_ANS_REPEAT_CREATE, ERROR_REPEAT_SET}, + {ERR_ANS_END_NOTIFICATION, ERROR_REPEAT_SET}, + {ERR_ANS_EXPIRED_NOTIFICATION, ERROR_EXPIRED_NOTIFICATION}, + {ERR_ANS_PUSH_CHECK_FAILED, ERROR_NO_RIGHT}, + {ERR_ANS_PUSH_CHECK_UNREGISTERED, ERROR_NO_RIGHT}, + {ERR_ANS_PUSH_CHECK_NETWORK_UNREACHABLE, ERROR_NETWORK_UNREACHABLE}, + {ERR_ANS_NO_AGENT_SETTING, ERROR_NO_AGENT_SETTING}, + {ERR_ANS_DIALOG_IS_POPPING, ERROR_DIALOG_IS_POPPING}, + {ERR_ANS_NO_PROFILE_TEMPLATE, ERROR_NO_PROFILE_TEMPLATE}, + {ERR_ANS_REJECTED_WITH_DISABLE_NOTIFICATION, ERROR_REJECTED_WITH_DISABLE_NOTIFICATION}, + {ERR_ANS_OPERATION_TIMEOUT, ERROR_DISTRIBUTED_OPERATION_TIMEOUT}, +}; + +int32_t ErrorToExternal(uint32_t errCode) +{ + int32_t ExternalCode = ERROR_INTERNAL_ERROR; + for (const auto &errorConvert : errorsConvert) { + if (errCode == errorConvert.first) { + ExternalCode = errorConvert.second; + break; + } + } + + ANS_LOGI("internal errorCode[%{public}u] to external errorCode[%{public}d]", errCode, ExternalCode); + return ExternalCode; +} + +std::string GetAnsErrMessage(uint32_t errCode, std::string defaultMsg) +{ + auto iter = ANS_ERROR_CODE_MESSAGE_MAP.find(errCode); + return iter != ANS_ERROR_CODE_MESSAGE_MAP.end() ? iter->second : defaultMsg; +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index 1cc7baa087461b28750e666e179d7d8578ed14e7..ad69cf1a1aa74f75219290fc03e1b43462cd5f26 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -16,6 +16,7 @@ group("unittest") { deps = [] deps += [ + "ans_core_common_test:unittest", "ans_image_util_test:unittest", "ans_manager_proxy_test:unittest", "ans_notification_annex_test:unittest", diff --git a/frameworks/core/test/unittest/ans_core_common_test/BUILD.gn b/frameworks/core/test/unittest/ans_core_common_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7d180cb0cbe86eea106a34aacc3e4721112b6bb5 --- /dev/null +++ b/frameworks/core/test/unittest/ans_core_common_test/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = + "${component_name}/distributed_notification_service/unittest" + +ohos_unittest("ans_core_common_unit_test") { + module_out_path = module_output_path + include_dirs = [] + + sources = [ "ans_inner_errors_test.cpp" ] + + deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + + external_deps = [ + "c_utils:utils", + "googletest:gmock_main", + "hilog:libhilog", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_core_common_unit_test" ] +} diff --git a/frameworks/core/test/unittest/ans_core_common_test/ans_inner_errors_test.cpp b/frameworks/core/test/unittest/ans_core_common_test/ans_inner_errors_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d94de126d7c0709879f44caf238e1261bfa15ad0 --- /dev/null +++ b/frameworks/core/test/unittest/ans_core_common_test/ans_inner_errors_test.cpp @@ -0,0 +1,82 @@ + /* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" + +#include "ans_inner_errors.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +class AnsInnerErrorsTest : public ::testing::Test { +protected: +void SetUp() override {} +void TearDown() override {} +}; + +HWTEST_F(AnsInnerErrorsTest, GetAnsErrMessage_001, TestSize.Level1) +{ + // Arrange + uint32_t errCode = ERROR_NOTIFICATION_NOT_EXIST; + std::string defaultMsg = "Default error message"; + std::string expectedMsg = "The notification does not exist"; + + // Act + std::string actualMsg = GetAnsErrMessage(errCode, defaultMsg); + + // Assert + EXPECT_EQ(expectedMsg, actualMsg); +} + +HWTEST_F(AnsInnerErrorsTest, GetAnsErrMessage_002, TestSize.Level1) +{ + // Arrange + uint32_t errCode = 999999; // Assuming 999999 is an invalid error code in ANS_ERROR_CODE_MESSAGE_MAP + std::string defaultMsg = "Default error message"; + std::string expectedMsg = defaultMsg; + + // Act + std::string actualMsg = GetAnsErrMessage(errCode, defaultMsg); + + // Assert + EXPECT_EQ(expectedMsg, actualMsg); +} + +HWTEST_F(AnsInnerErrorsTest, ErrorToExternal_ShouldReturnCorrectExternalCode_WhenInternalCodeIsKnown, TestSize.Level1) +{ + // Arrange + uint32_t internalCode = ERR_ANS_DISTRIBUTED_GET_INFO_FAILED; + int32_t expectedExternalCode = ERROR_DISTRIBUTED_OPERATION_FAILED; + + // Act + int32_t actualExternalCode = ErrorToExternal(internalCode); + + // Assert + EXPECT_EQ(expectedExternalCode, actualExternalCode); +} +HWTEST_F(AnsInnerErrorsTest, ErrorToExternal_ShouldReturnDefaultCode_WhenInternalCodeIsUnknown, TestSize.Level1) +{ + // Arrange + uint32_t internalCode = 9999; + int32_t expectedExternalCode = ERROR_INTERNAL_ERROR; + + // Act + int32_t actualExternalCode = ErrorToExternal(internalCode); + + // Assert + EXPECT_EQ(expectedExternalCode, actualExternalCode); +} \ No newline at end of file diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index f00dcc256657e7cdb56259253b9e5a806d33a711..528ef6188b8c6b0a3596806fd368140262b03dc8 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -1837,7 +1837,6 @@ public: static napi_value NapiReturnCapErr(napi_env env, napi_callback_info info); static napi_value NapiReturnFalseCb(napi_env env, napi_callback_info info); static napi_value NapiReturnFalseCbNewType(napi_env env, napi_callback_info info); - static int32_t ErrorToExternal(uint32_t errCode); static void CreateReturnValue(const napi_env &env, const CallbackPromiseInfo &info, const napi_value &result); static napi_value GetLockScreenPicture( const napi_env &env, const napi_value &contentResult, std::shared_ptr basicContent); diff --git a/frameworks/js/napi/src/common_utils.cpp b/frameworks/js/napi/src/common_utils.cpp index d4f19f30285b9d9b73d325fe695a2094c209c4a5..1023b19bac8025e1ae472f90c3e53ebda76e8c2b 100644 --- a/frameworks/js/napi/src/common_utils.cpp +++ b/frameworks/js/napi/src/common_utils.cpp @@ -31,39 +31,6 @@ namespace OHOS { namespace NotificationNapi { const uint32_t MAX_PARAM_NUM = 5; -namespace { -static const std::unordered_map ERROR_CODE_MESSAGE { - {ERROR_PERMISSION_DENIED, "Permission denied"}, - {ERROR_NOT_SYSTEM_APP, "The application isn't system application"}, - {ERROR_PARAM_INVALID, "Invalid parameter"}, - {ERROR_SYSTEM_CAP_ERROR, "SystemCapability not found"}, - {ERROR_INTERNAL_ERROR, "Internal error. Possible cause: 1.IPC communication failed. 2.Memory operation error"}, - {ERROR_IPC_ERROR, "Marshalling or unmarshalling error"}, - {ERROR_SERVICE_CONNECT_ERROR, "Failed to connect to the service"}, - {ERROR_NOTIFICATION_CLOSED, "Notification disabled"}, - {ERROR_SLOT_CLOSED, "Notification slot disabled"}, - {ERROR_NOTIFICATION_UNREMOVABLE, "Notification deletion disabled"}, - {ERROR_NOTIFICATION_NOT_EXIST, "The notification does not exist"}, - {ERROR_USER_NOT_EXIST, "The user does not exist"}, - {ERROR_OVER_MAX_NUM_PER_SECOND, "The notification sending frequency reaches the upper limit"}, - {ERROR_DISTRIBUTED_OPERATION_FAILED, "Distributed operation failed"}, - {ERROR_READ_TEMPLATE_CONFIG_FAILED, "Failed to read the template configuration"}, - {ERROR_NO_MEMORY, "Memory operation failed"}, - {ERROR_BUNDLE_NOT_FOUND, "The specified bundle name was not found"}, - {ERROR_NO_AGENT_SETTING, "There is no corresponding agent relationship configuration"}, - {ERROR_DIALOG_IS_POPPING, "Dialog is popping"}, - {ERROR_SETTING_WINDOW_EXIST, "The notification settings window is already displayed"}, - {ERROR_NO_PROFILE_TEMPLATE, "Not exit noNotDisturb profile template"}, - {ERROR_REPEAT_SET, "Repeat create or end"}, - {ERROR_NO_RIGHT, "The specified process does not have the permission"}, - {ERROR_EXPIRED_NOTIFICATION, "Low update version"}, - {ERROR_NETWORK_UNREACHABLE, "Network unreachable"}, - {ERROR_REJECTED_WITH_DISABLE_NOTIFICATION, - "The application is not allowed to publish notifications due to permission control settings"}, - {ERROR_DISTRIBUTED_OPERATION_TIMEOUT, "Distributed operation timeout"}, -}; -} - napi_value Common::NapiGetBoolean(napi_env env, const bool &isValue) { napi_value result = nullptr; @@ -96,8 +63,7 @@ napi_value Common::CreateErrorValue(napi_env env, int32_t errCode, bool newType) napi_value code = nullptr; napi_create_int32(env, errCode, &code); - auto iter = ERROR_CODE_MESSAGE.find(errCode); - std::string errMsg = iter != ERROR_CODE_MESSAGE.end() ? iter->second : ""; + std::string errMsg = OHOS::Notification::GetAnsErrMessage(errCode); napi_value message = nullptr; napi_create_string_utf8(env, errMsg.c_str(), NAPI_AUTO_LENGTH, &message); @@ -117,8 +83,7 @@ napi_value Common::CreateErrorValue(napi_env env, int32_t errCode, std::string & napi_value code = nullptr; napi_create_int32(env, errCode, &code); - auto iter = ERROR_CODE_MESSAGE.find(errCode); - std::string errMsg = iter != ERROR_CODE_MESSAGE.end() ? iter->second : ""; + std::string errMsg = OHOS::Notification::GetAnsErrMessage(errCode); napi_value message = nullptr; napi_create_string_utf8(env, errMsg.append(" ").append(msg).c_str(), NAPI_AUTO_LENGTH, &message); @@ -301,64 +266,6 @@ void Common::CreateReturnValue(const napi_env &env, const CallbackPromiseInfo &i ANS_LOGD("end"); } -int32_t Common::ErrorToExternal(uint32_t errCode) -{ - static std::vector> errorsConvert = { - {ERR_ANS_PERMISSION_DENIED, ERROR_PERMISSION_DENIED}, - {ERR_ANS_NON_SYSTEM_APP, ERROR_NOT_SYSTEM_APP}, - {ERR_ANS_NOT_SYSTEM_SERVICE, ERROR_NOT_SYSTEM_APP}, - {ERR_ANS_INVALID_PARAM, ERROR_PARAM_INVALID}, - {ERR_ANS_INVALID_UID, ERROR_PARAM_INVALID}, - {ERR_ANS_ICON_OVER_SIZE, ERROR_PARAM_INVALID}, - {ERR_ANS_PICTURE_OVER_SIZE, ERROR_PARAM_INVALID}, - {ERR_ANS_PUSH_CHECK_EXTRAINFO_INVALID, ERROR_PARAM_INVALID}, - {ERR_ANS_NO_MEMORY, ERROR_NO_MEMORY}, - {ERR_ANS_TASK_ERR, ERROR_INTERNAL_ERROR}, - {ERR_ANS_PARCELABLE_FAILED, ERROR_IPC_ERROR}, - {ERR_ANS_TRANSACT_FAILED, ERROR_IPC_ERROR}, - {ERR_ANS_REMOTE_DEAD, ERROR_IPC_ERROR}, - {ERR_INVALID_VALUE, ERROR_IPC_ERROR}, - {ERR_INVALID_DATA, ERROR_IPC_ERROR}, - {DEAD_OBJECT, ERROR_IPC_ERROR}, - {ERR_ANS_SERVICE_NOT_READY, ERROR_SERVICE_CONNECT_ERROR}, - {ERR_ANS_SERVICE_NOT_CONNECTED, ERROR_SERVICE_CONNECT_ERROR}, - {ERR_ANS_NOT_ALLOWED, ERROR_NOTIFICATION_CLOSED}, - {ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, ERROR_SLOT_CLOSED}, - {ERR_ANS_NOTIFICATION_IS_UNREMOVABLE, ERROR_NOTIFICATION_UNREMOVABLE}, - {ERR_ANS_NOTIFICATION_NOT_EXISTS, ERROR_NOTIFICATION_NOT_EXIST}, - {ERR_ANS_GET_ACTIVE_USER_FAILED, ERROR_USER_NOT_EXIST}, - {ERR_ANS_INVALID_PID, ERROR_BUNDLE_NOT_FOUND}, - {ERR_ANS_INVALID_BUNDLE, ERROR_BUNDLE_NOT_FOUND}, - {ERR_ANS_OVER_MAX_ACTIVE_PERSECOND, ERROR_OVER_MAX_NUM_PER_SECOND}, - {ERR_ANS_OVER_MAX_UPDATE_PERSECOND, ERROR_OVER_MAX_NUM_PER_SECOND}, - {ERR_ANS_DISTRIBUTED_OPERATION_FAILED, ERROR_DISTRIBUTED_OPERATION_FAILED}, - {ERR_ANS_DISTRIBUTED_GET_INFO_FAILED, ERROR_DISTRIBUTED_OPERATION_FAILED}, - {ERR_ANS_PREFERENCES_NOTIFICATION_READ_TEMPLATE_CONFIG_FAILED, ERROR_READ_TEMPLATE_CONFIG_FAILED}, - {ERR_ANS_REPEAT_CREATE, ERROR_REPEAT_SET}, - {ERR_ANS_END_NOTIFICATION, ERROR_REPEAT_SET}, - {ERR_ANS_EXPIRED_NOTIFICATION, ERROR_EXPIRED_NOTIFICATION}, - {ERR_ANS_PUSH_CHECK_FAILED, ERROR_NO_RIGHT}, - {ERR_ANS_PUSH_CHECK_UNREGISTERED, ERROR_NO_RIGHT}, - {ERR_ANS_PUSH_CHECK_NETWORK_UNREACHABLE, ERROR_NETWORK_UNREACHABLE}, - {ERR_ANS_NO_AGENT_SETTING, ERROR_NO_AGENT_SETTING}, - {ERR_ANS_DIALOG_IS_POPPING, ERROR_DIALOG_IS_POPPING}, - {ERR_ANS_NO_PROFILE_TEMPLATE, ERROR_NO_PROFILE_TEMPLATE}, - {ERR_ANS_REJECTED_WITH_DISABLE_NOTIFICATION, ERROR_REJECTED_WITH_DISABLE_NOTIFICATION}, - {ERR_ANS_OPERATION_TIMEOUT, ERROR_DISTRIBUTED_OPERATION_TIMEOUT}, - }; - - int32_t ExternalCode = ERROR_INTERNAL_ERROR; - for (const auto &errorConvert : errorsConvert) { - if (errCode == errorConvert.first) { - ExternalCode = errorConvert.second; - break; - } - } - - ANS_LOGI("internal errorCode[%{public}u] to external errorCode[%{public}d]", errCode, ExternalCode); - return ExternalCode; -} - napi_value Common::NapiReturnCapErrCb(napi_env env, napi_callback_info info) { size_t argc = MAX_PARAM_NUM; diff --git a/frameworks/js/napi/src/distributed_operation_callback.cpp b/frameworks/js/napi/src/distributed_operation_callback.cpp index a0d58a33df76cb8070f95ff36661860e07111fc7..288c46aaabbc665382a74d19eab3b2cdcd8e3cfd 100644 --- a/frameworks/js/napi/src/distributed_operation_callback.cpp +++ b/frameworks/js/napi/src/distributed_operation_callback.cpp @@ -37,7 +37,7 @@ ErrCode DistributedOperationCallback::OnOperationCallback(const int32_t operatio } if (operationResult != ERR_OK) { - operationOnCallBack->operationResult = Common::ErrorToExternal(operationResult); + operationOnCallBack->operationResult = OHOS::Notification::ErrorToExternal(operationResult); } else { operationOnCallBack->operationResult = operationResult; } diff --git a/frameworks/js/napi/src/manager/napi_open_settings.cpp b/frameworks/js/napi/src/manager/napi_open_settings.cpp index cda74b8d73e60f3c68f87770cce5a7a86c1daa8a..bb858b60a12d8aecd8efc49dd9d354f17fea2e73 100644 --- a/frameworks/js/napi/src/manager/napi_open_settings.cpp +++ b/frameworks/js/napi/src/manager/napi_open_settings.cpp @@ -41,7 +41,7 @@ void NapiAsyncCompleteCallbackOpenSettings(napi_env env, void *data) errorCode = ERROR_SETTING_WINDOW_EXIST; } else { errorCode = asynccallbackinfo->info.errorCode == - ERR_OK ? ERR_OK : Common::ErrorToExternal(asynccallbackinfo->info.errorCode); + ERR_OK ? ERR_OK : OHOS::Notification::ErrorToExternal(asynccallbackinfo->info.errorCode); } if (asynccallbackinfo->info.isCallback) { Common::SetCallback(env, asynccallbackinfo->info.callback, errorCode, result, true); diff --git a/frameworks/js/napi/src/manager/napi_push.cpp b/frameworks/js/napi/src/manager/napi_push.cpp index e216dc2cf3c39af46fdf91fe02335bded6ffab49..73335dfcd8626db1f2d62aa83af17e307c870925 100644 --- a/frameworks/js/napi/src/manager/napi_push.cpp +++ b/frameworks/js/napi/src/manager/napi_push.cpp @@ -111,7 +111,7 @@ napi_value NapiPush::OnRegisterPushCallback(napi_env env, const napi_callback_in auto result = NotificationHelper::RegisterPushCallback(jsPushCallBack_->AsObject(), checkRequest); if (result != ERR_OK) { ANS_LOGE("Register failed, result is %{public}d", result); - ThrowError(env, Common::ErrorToExternal(result)); + ThrowError(env, OHOS::Notification::ErrorToExternal(result)); } return undefined; } diff --git a/tools/dump/src/notification_shell_command.cpp b/tools/dump/src/notification_shell_command.cpp index f7c1fe48efa54af3b03d957c6d1ac9f088f1a95b..3b88812456b3d104c62fed3b03e07b53de73ffbf 100644 --- a/tools/dump/src/notification_shell_command.cpp +++ b/tools/dump/src/notification_shell_command.cpp @@ -366,6 +366,10 @@ ErrCode NotificationShellCommand::RunSetEnableCmd() resultReceiver_.append("set notification enabled success\n"); } else { resultReceiver_.append("set notification enabled failed\n"); + std::string message = GetAnsErrMessage(ErrorToExternal(ret)); + if (message != "") { + resultReceiver_.append("failed reason is " + message + "\n"); + } } return ret; } @@ -391,6 +395,10 @@ ErrCode NotificationShellCommand::RunGetDeviceStatusCmd() resultReceiver_.append("\n"); } else { resultReceiver_.append("Get device status failed\n"); + std::string message = GetAnsErrMessage(ErrorToExternal(ret)); + if (message != "") { + resultReceiver_.append("failed reason is " + message + "\n"); + } } return ret; } @@ -420,6 +428,10 @@ ErrCode NotificationShellCommand::RunSetDeviceStatusCmd() resultReceiver_.append("set device status success\n"); } else { resultReceiver_.append("set device status failed\n"); + std::string message = GetAnsErrMessage(ErrorToExternal(ret)); + if (message != "") { + resultReceiver_.append("failed reason is " + message + "\n"); + } } return ret; } @@ -448,6 +460,10 @@ ErrCode NotificationShellCommand::RunSetSmartReminderEnabledCmd() resultReceiver_.append("set collaboration switch success\n"); } else { resultReceiver_.append("set collaboration switch failed\n"); + std::string message = GetAnsErrMessage(ErrorToExternal(ret)); + if (message != "") { + resultReceiver_.append("failed reason is " + message + "\n"); + } } return ret; } @@ -486,6 +502,10 @@ ErrCode NotificationShellCommand::RunSetDistributedEnabledByBundleCmd() resultReceiver_.append("set bundle collaboration switch success\n"); } else { resultReceiver_.append("set bundle collaboration switch failed\n"); + std::string message = GetAnsErrMessage(ErrorToExternal(ret)); + if (message != "") { + resultReceiver_.append("failed reason is " + message + "\n"); + } } return ret; } @@ -525,6 +545,10 @@ ErrCode NotificationShellCommand::RunSetDistributedEnabledBySlotCmd() resultReceiver_.append("set slot collaboration switch success\n"); } else { resultReceiver_.append("set slot collaboration switch failed\n"); + std::string message = GetAnsErrMessage(ErrorToExternal(ret)); + if (message != "") { + resultReceiver_.append("failed reason is " + message + "\n"); + } } return ret; }