From 03caaa269c2090ef6a0d4674191c561414e7f3da Mon Sep 17 00:00:00 2001 From: heguokai Date: Sun, 22 Jun 2025 18:43:39 +0800 Subject: [PATCH 1/4] =?UTF-8?q?1=E3=80=81=E9=94=99=E8=AF=AF=E7=A0=81?= =?UTF-8?q?=E6=A0=A1=E6=AD=A3=202=E3=80=81=E5=8F=82=E6=95=B0=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: heguokai --- frameworks/ets/ani/include/sts_common.h | 6 ++ frameworks/ets/ani/include/sts_throw_erro.h | 54 +++++++++++++++ .../src/manager/ani_ans_dialog_callback.cpp | 1 + frameworks/ets/ani/src/manager/ani_cance.cpp | 47 +++++++------- .../ets/ani/src/manager/ani_display_badge.cpp | 13 ++-- .../src/manager/ani_distributed_enable.cpp | 39 ++++++----- .../src/manager/ani_do_not_disturb_date.cpp | 22 +++---- .../manager/ani_do_not_disturb_profile.cpp | 13 ++-- .../ets/ani/src/manager/ani_get_active.cpp | 15 ++--- .../ani/src/manager/ani_local_live_view.cpp | 9 ++- .../src/manager/ani_notification_enable.cpp | 19 +++--- frameworks/ets/ani/src/manager/ani_on.cpp | 3 +- .../ets/ani/src/manager/ani_open_settings.cpp | 3 +- .../ets/ani/src/manager/ani_publish.cpp | 9 ++- .../ets/ani/src/manager/ani_remove_group.cpp | 8 +-- .../ani/src/manager/ani_request_enable.cpp | 3 +- frameworks/ets/ani/src/manager/ani_slot.cpp | 65 +++++++++---------- .../ani/src/manager/ani_support_template.cpp | 15 ++--- .../ets/ani/src/manager/ani_sync_config.cpp | 5 +- frameworks/ets/ani/src/sts_bundle_option.cpp | 5 +- frameworks/ets/ani/src/sts_common.cpp | 4 ++ frameworks/ets/ani/src/sts_convert_other.cpp | 9 +-- .../ets/ani/src/sts_notification_content.cpp | 39 +++++------ .../ets/ani/src/sts_notification_manager.cpp | 2 +- frameworks/ets/ani/src/sts_request.cpp | 40 ++++++------ frameworks/ets/ani/src/sts_slot.cpp | 4 +- frameworks/ets/ani/src/sts_subscribe.cpp | 29 ++++----- frameworks/ets/ani/src/sts_subscribe_info.cpp | 10 ++- frameworks/ets/ani/src/sts_user_input.cpp | 2 +- .../ets/ani/src/subscribe/ani_remove.cpp | 26 ++++---- .../ets/ani/src/subscribe/ani_subscribe.cpp | 4 +- 31 files changed, 289 insertions(+), 234 deletions(-) diff --git a/frameworks/ets/ani/include/sts_common.h b/frameworks/ets/ani/include/sts_common.h index 8bfe1dac6..35f9d908f 100644 --- a/frameworks/ets/ani/include/sts_common.h +++ b/frameworks/ets/ani/include/sts_common.h @@ -24,6 +24,12 @@ namespace OHOS { namespace NotificationSts { +constexpr int32_t STR_MAX_SIZE = 204; +constexpr int32_t LONG_STR_MAX_SIZE = 1028; +constexpr int32_t COMMON_TEXT_SIZE = 3074; +constexpr int32_t SHORT_TEXT_SIZE = 1026; +std::string GetResizeStr(std::string instr, int32_t length); + bool IsUndefine(ani_env *env, const ani_object &obj); ani_object CreateBoolean(ani_env *env, bool value); ani_object CreateDouble(ani_env *env, ani_double value); diff --git a/frameworks/ets/ani/include/sts_throw_erro.h b/frameworks/ets/ani/include/sts_throw_erro.h index 642ed3b42..960b78fbf 100644 --- a/frameworks/ets/ani/include/sts_throw_erro.h +++ b/frameworks/ets/ani/include/sts_throw_erro.h @@ -56,6 +56,60 @@ static const std::unordered_map ERROR_CODE_TO_MESSAGE { {ERROR_DISTRIBUTED_OPERATION_TIMEOUT, "Distributed operation timeout"}, }; +inline int32_t GetExternalCode(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_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; +}; + inline std::string FindAnsErrMsg(const int32_t errCode) { auto findMsg = ERROR_CODE_TO_MESSAGE.find(errCode); diff --git a/frameworks/ets/ani/src/manager/ani_ans_dialog_callback.cpp b/frameworks/ets/ani/src/manager/ani_ans_dialog_callback.cpp index b288966f2..88ce9d3bd 100755 --- a/frameworks/ets/ani/src/manager/ani_ans_dialog_callback.cpp +++ b/frameworks/ets/ani/src/manager/ani_ans_dialog_callback.cpp @@ -14,6 +14,7 @@ */ #include "ani_ans_dialog_callback.h" + #include "ans_log_wrapper.h" #include "inner_errors.h" #include "notification_helper.h" diff --git a/frameworks/ets/ani/src/manager/ani_cance.cpp b/frameworks/ets/ani/src/manager/ani_cance.cpp index 600558eff..bc48b59e9 100644 --- a/frameworks/ets/ani/src/manager/ani_cance.cpp +++ b/frameworks/ets/ani/src/manager/ani_cance.cpp @@ -14,7 +14,6 @@ */ #include "ani_cance.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -27,8 +26,8 @@ void AniCancelAll(ani_env* env) { ANS_LOGD("AniCancelAll notifications call"); int returncode = Notification::NotificationHelper::CancelAllNotifications(); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniCancelAll -> error, errorCode: %{public}d", externalCode); } @@ -39,8 +38,8 @@ void AniCancelWithId(ani_env* env, ani_double id) { ANS_LOGD("AniCancelWithId call,id : %{public}lf", id); int returncode = Notification::NotificationHelper::CancelNotification(static_cast(id)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniCancelWithId -> error, errorCode: %{public}d", externalCode); } @@ -50,16 +49,16 @@ void AniCancelWithId(ani_env* env, ani_double id) void AniCancelWithIdLabel(ani_env* env, ani_double id, ani_string label) { ANS_LOGD("AniCancelWithIdLabel call"); - std::string labelStr; - if (ANI_OK != NotificationSts::GetStringByAniString(env, label, labelStr)) { + std::string tempStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, label, tempStr)) { NotificationSts::ThrowStsErroWithMsg(env, "Label parse failed!"); return; } - + std::string labelStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); ANS_LOGD("Cancel by label id:%{public}lf label:%{public}s", id, labelStr.c_str()); int returncode = Notification::NotificationHelper::CancelNotification(labelStr, static_cast(id)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniCancelWithIdLabel -> error, errorCode: %{public}d", externalCode); } @@ -78,8 +77,8 @@ void AniCancelWithBundle(ani_env* env, ani_object bundleObj, ani_double id) ANS_LOGD("Cancel by bundle:%{public}s id:%{public}lf", option.GetBundleName().c_str(), id); int returncode = Notification::NotificationHelper::CancelAsBundle(option, static_cast(id)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniCancelWithBundle -> error, errorCode: %{public}d", externalCode); } @@ -96,17 +95,18 @@ void AniCancelWithIdOptinalLabel(ani_env* env, ani_double id, ani_string label) ANS_LOGE("sts AniCancelWithIdOptinalLabel the label is undefined"); ret = Notification::NotificationHelper::CancelNotification(static_cast(id)); } else { - std::string labelStr; - if (ANI_OK != NotificationSts::GetStringByAniString(env, label, labelStr)) { + std::string tempStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, label, tempStr)) { OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); ANS_LOGE("sts AniCancelWithIdOptinalLabel ERROR_INTERNAL_ERROR"); return; } + std::string labelStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); ANS_LOGD("sts AniCancelWithIdOptinalLabel id:%{public}lf label:%{public}s", id, labelStr.c_str()); ret = Notification::NotificationHelper::CancelNotification(labelStr, id); } - int externalCode = CJSystemapi::Notification::ErrorToExternal(ret); + int externalCode = NotificationSts::GetExternalCode(ret); if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("sts AniCancelWithIdOptinalLabel error, errorCode: %{public}d", externalCode); @@ -131,8 +131,8 @@ void AniCancelAsBundle(ani_env *env, ani_double id, ani_string representativeBun convertedId, UserId, bundleStr.c_str()); int returncode = Notification::NotificationHelper::CancelAsBundle(convertedId, bundleStr, UserId); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniCancelAsBundle: CancelAsBundle retern erro. returncode: %{public}d, externalCode: %{public}d", returncode, externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -156,8 +156,8 @@ void AniCancelAsBundleWithBundleOption(ani_env *env, ani_object representativeBu option.GetBundleName().c_str(), option.GetUid(), idTest); int returncode = Notification::NotificationHelper::CancelAsBundle(option, idTest); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("CancelAsBundle retern error. returncode: %{public}d, externalCode: %{public}d", returncode, externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -170,15 +170,16 @@ void AniCancelGroup(ani_env *env, ani_string groupName) { ANS_LOGD("AniCancelGroup enter"); - std::string groupNameStr; - if (ANI_OK != NotificationSts::GetStringByAniString(env, groupName, groupNameStr)) { + std::string tempStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, groupName, tempStr)) { NotificationSts::ThrowStsErroWithMsg(env, "AniCancelGroup: groupName parse failed!"); return; } + std::string groupNameStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); ANS_LOGD("AniCancelGroup groupNameStr: %{public}s", groupNameStr.c_str()); int returncode = Notification::NotificationHelper::CancelGroup(groupNameStr); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniCancelGroup: CancelAsBundle retern erro. returncode: %{public}d, externalCode: %{public}d", returncode, externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); diff --git a/frameworks/ets/ani/src/manager/ani_display_badge.cpp b/frameworks/ets/ani/src/manager/ani_display_badge.cpp index ed01c043a..d1a4d6532 100644 --- a/frameworks/ets/ani/src/manager/ani_display_badge.cpp +++ b/frameworks/ets/ani/src/manager/ani_display_badge.cpp @@ -19,7 +19,6 @@ #include "sts_throw_erro.h" #include "sts_error_utils.h" #include "sts_common.h" -#include "inner_errors.h" #include "notification_helper.h" #include "notification_bundle_option.h" @@ -40,8 +39,8 @@ void AniDisplayBadge(ani_env *env, ani_object obj, ani_boolean enable) ANS_LOGE("sts DisplayBadge ERROR_INTERNAL_ERROR"); return; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("sts DisplayBadge error, errorCode: %{public}d", externalCode); return; @@ -68,8 +67,8 @@ ani_boolean AniIsBadgeDisplayed(ani_env *env, ani_object obj) } } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("sts IsBadgeDisplayed error, errorCode: %{public}d", externalCode); return NotificationSts::BoolToAniBoolean(false); @@ -83,7 +82,7 @@ void AniSetBadgeNumber(ani_env *env, ani_double badgeNumber) { ANS_LOGD("sts AniSetBadgeNumber call, BadgeNumber: %{public}lf", badgeNumber); int returncode = Notification::NotificationHelper::SetBadgeNumber(static_cast(badgeNumber)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("sts AniSetBadgeNumber error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -105,7 +104,7 @@ void AniSetBadgeNumberByBundle(ani_env *env, ani_object obj, ani_double badgeNum NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); return; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("sts AniSetBadgeNumberByBundle error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); diff --git a/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp index 4beb262fd..4d8ce628a 100755 --- a/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp @@ -14,7 +14,6 @@ */ #include "ani_distributed_enable.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -28,8 +27,8 @@ void AniSetDistributedEnable(ani_env* env, ani_boolean enabled) { ANS_LOGD("AniSetDistributedEnable call,enable : %{public}d", enabled); int returncode = Notification::NotificationHelper::EnableDistributed(NotificationSts::AniBooleanToBool(enabled)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniSetDistributedEnable -> error, errorCode: %{public}d", externalCode); return; @@ -42,8 +41,8 @@ ani_boolean AniIsDistributedEnabled(ani_env* env) ANS_LOGD("AniIsDistributedEnabled call"); bool enabled = false; int returncode = Notification::NotificationHelper::IsDistributedEnabled(enabled); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsDistributedEnabled -> error, errorCode: %{public}d", externalCode); return NotificationSts::BoolToAniBoolean(false); @@ -62,8 +61,8 @@ ani_boolean AniIsDistributedEnabledByBundle(ani_env* env, ani_object obj) } bool enabled = false; int returncode = Notification::NotificationHelper::IsDistributedEnableByBundle(option, enabled); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsDistributedEnabledByBundle -> error, errorCode: %{public}d", externalCode); } @@ -88,8 +87,8 @@ ani_boolean AniIsDistributedEnabledByBundleType(ani_env* env, ani_object obj, an bool enabled = false; int returncode = Notification::NotificationHelper::IsDistributedEnabledByBundle(option, deviceTypeStr, enabled); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsDistributedEnabledByBundle -> error, errorCode: %{public}d", externalCode); } @@ -112,7 +111,7 @@ void AniSetDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean e NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); return; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("sts setDistributedEnableByBundle error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -144,7 +143,7 @@ void AniSetDistributedEnableByBundleAndType(ani_env *env, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); return; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("sts setDistributedEnabledByBundle error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -165,7 +164,7 @@ void AniSetTargetDeviceStatus(ani_env* env, ani_string deviceType, ani_double st } ANS_LOGD("sts setTargetDeviceStatus id:%{public}lf deviceType:%{public}s", status, deviceTypeStr.c_str()); int32_t ret = Notification::NotificationHelper::SetTargetDeviceStatus(deviceTypeStr, status, DISTURB_DEFAULT_FLAG); - int externalCode = CJSystemapi::Notification::ErrorToExternal(ret); + int externalCode = NotificationSts::GetExternalCode(ret); if (externalCode != ERR_OK) { ANS_LOGE("sts setTargetDeviceStatus error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -190,8 +189,8 @@ ani_boolean AniIsSmartReminderEnabled(ani_env *env, ani_string deviceType) return ANI_FALSE; } int returncode = Notification::NotificationHelper::IsSmartReminderEnabled(deviceTypeStr, allowed); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("isSmartReminderEnabled -> error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -217,8 +216,8 @@ void AniSetSmartReminderEnable(ani_env *env, ani_string deviceType, ani_boolean } int returncode = Notification::NotificationHelper::SetSmartReminderEnabled(deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("setSmartReminderEnabled -> error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -250,8 +249,8 @@ void AniSetDistributedEnableBySlot(ani_env *env, ani_enum_item slot, ani_string returncode = Notification::NotificationHelper::SetDistributedEnabledBySlot(slotType, deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("setDistributedEnabledBySlot error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -281,8 +280,8 @@ ani_boolean AniIsDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_ } bool isEnable = false; int returncode = Notification::NotificationHelper::IsDistributedEnabledBySlot(slotType, deviceTypeStr, isEnable); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("isDistributedEnabledBySlot -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } diff --git a/frameworks/ets/ani/src/manager/ani_do_not_disturb_date.cpp b/frameworks/ets/ani/src/manager/ani_do_not_disturb_date.cpp index 7d09b4241..226e42790 100644 --- a/frameworks/ets/ani/src/manager/ani_do_not_disturb_date.cpp +++ b/frameworks/ets/ani/src/manager/ani_do_not_disturb_date.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ #include "ani_do_not_disturb_date.h" -#include "inner_errors.h" + #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -35,8 +35,8 @@ void AniSetDoNotDisturbDate(ani_env *env, ani_object date) } int returncode = Notification::NotificationHelper::SetDoNotDisturbDate(doNotDisturbDate); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("SetDoNotDisturbDate error. returncode: %{public}d, externalCode: %{public}d", returncode, externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -56,8 +56,8 @@ void AniSetDoNotDisturbDateWithId(ani_env *env, ani_object date, ani_double user const int32_t id = static_cast(userId); int returncode = Notification::NotificationHelper::SetDoNotDisturbDate(id, doNotDisturbDate); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("SetDoNotDisturbDate erro. returncode: %{public}d, externalCode: %{public}d", returncode, externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -73,8 +73,8 @@ ani_object AniGetDoNotDisturbDate(ani_env *env) ANS_LOGD("AniGetDoNotDisturbDate enter"); int returncode = Notification::NotificationHelper::GetDoNotDisturbDate(doNotDisturbDate); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("GetDoNotDisturbDate retern erro. returncode: %{public}d, externalCode: %{public}d", returncode, externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -100,8 +100,8 @@ ani_object AniGetDoNotDisturbDateWithId(ani_env *env, ani_double userId) const int32_t id = static_cast(userId); int returncode = Notification::NotificationHelper::GetDoNotDisturbDate(id, doNotDisturbDate); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("GetDoNotDisturbDate erro. returncode: %{public}d, externalCode: %{public}d", returncode, externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -122,8 +122,8 @@ ani_boolean AniIsSupportDoNotDisturbMode(ani_env *env) bool supportDoNotDisturbMode = false; ANS_LOGD("AniIsSupportDoNotDisturbMode enter"); int returncode = Notification::NotificationHelper::DoesSupportDoNotDisturbMode(supportDoNotDisturbMode); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("DoesSupportDoNotDisturbMode error. returncode: %{public}d, externalCode: %{public}d", returncode, externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); diff --git a/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp b/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp index 71f94dd19..6d32f3bf5 100644 --- a/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp +++ b/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp @@ -14,7 +14,6 @@ */ #include "ani_do_not_disturb_profile.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_common.h" @@ -37,8 +36,8 @@ void AniAddDoNotDisturbProfile(ani_env *env, ani_object obj) ANS_LOGE("AniAddDoNotDisturbProfile failed : ERROR_INTERNAL_ERROR"); return; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniAddDoNotDisturbProfile error, errorCode: %{public}d", externalCode); } @@ -58,8 +57,8 @@ void AniRemoveDoNotDisturbProfile(ani_env *env, ani_object obj) ANS_LOGE("AniRemoveDoNotDisturbProfile failed : ERROR_INTERNAL_ERROR"); return; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniRemoveDoNotDisturbProfile error, errorCode: %{public}d", externalCode); } @@ -82,8 +81,8 @@ ani_object AniGetDoNotDisturbProfile(ani_env *env, ani_double id) int32_t idTest = static_cast(id); ANS_LOGD("AniGetDoNotDisturbProfile: idTest: %{public}d", idTest); int returncode = Notification::NotificationHelper::GetDoNotDisturbProfile(idTest, doNotDisturbProfile); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniSetDoNotDisturbDateWithId error, errorCode: %{public}d, returncode: %{public}d", externalCode, returncode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); diff --git a/frameworks/ets/ani/src/manager/ani_get_active.cpp b/frameworks/ets/ani/src/manager/ani_get_active.cpp index 93c02e572..b22e68405 100644 --- a/frameworks/ets/ani/src/manager/ani_get_active.cpp +++ b/frameworks/ets/ani/src/manager/ani_get_active.cpp @@ -14,7 +14,6 @@ */ #include "ani_get_active.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -30,8 +29,8 @@ ani_double AniGetActiveNotificationCount(ani_env *env) int returncode = OHOS::Notification::NotificationHelper::GetActiveNotificationNums(num); ANS_LOGD("sts GetActiveNotificationCount end, num: %{public}llu", num); ani_double retNum = static_cast(num); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniSetNotificationEnableSlotSync error, errorCode: %{public}d", externalCode); return 0; @@ -44,8 +43,8 @@ ani_object AniGetAllActiveNotifications(ani_env *env) ANS_LOGD("sts AniGetAllActiveNotifications call"); std::vector> notifications; int returncode = OHOS::Notification::NotificationHelper::GetAllActiveNotifications(notifications); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniGetAllActiveNotifications error, errorCode: %{public}d", externalCode); return nullptr; @@ -70,8 +69,8 @@ ani_object AniGetActiveNotifications(ani_env *env) ANS_LOGD("sts AniGetActiveNotifications call"); std::vector> requests; int returncode = OHOS::Notification::NotificationHelper::GetActiveNotifications(requests); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniGetActiveNotifications error, errorCode: %{public}d", externalCode); return nullptr; @@ -101,7 +100,7 @@ ani_object AniGetActiveNotificationByFilter(ani_env *env, ani_object obj) } sptr notificationRequest = nullptr; int returncode = Notification::NotificationHelper::GetActiveNotificationByFilter(filter, notificationRequest); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("AniGetActiveNotificationByFilter -> error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); diff --git a/frameworks/ets/ani/src/manager/ani_local_live_view.cpp b/frameworks/ets/ani/src/manager/ani_local_live_view.cpp index d3c4203c8..5d7179c5f 100644 --- a/frameworks/ets/ani/src/manager/ani_local_live_view.cpp +++ b/frameworks/ets/ani/src/manager/ani_local_live_view.cpp @@ -14,7 +14,6 @@ */ #include "ani_local_live_view.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -44,8 +43,8 @@ void AniTriggerSystemLiveView( } int returncode = OHOS::Notification::NotificationHelper::TriggerLocalLiveView(bundleOption, static_cast(notificationId), buttonOption); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniTriggerSystemLiveView error, errorCode: %{public}d", externalCode); } @@ -60,8 +59,8 @@ void AniSubscribeSystemLiveView(ani_env *env, ani_object subscriberObj) localLiveViewSubscriber->SetStsNotificationLocalLiveViewSubscriber(env, subscriberObj); int returncode = OHOS::Notification::NotificationHelper::SubscribeLocalLiveViewNotification(*localLiveViewSubscriber, false); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniSubscribeSystemLiveView error, errorCode: %{public}d", externalCode); } diff --git a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp index ba521c2dc..aae5494da 100644 --- a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp @@ -14,7 +14,6 @@ */ #include "ani_notification_enable.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -28,7 +27,7 @@ ani_boolean AniIsNotificationEnabled(ani_env *env) ANS_LOGD("AniIsNotificationEnabled call"); bool allowed = false; int returncode = Notification::NotificationHelper::IsAllowedNotifySelf(allowed); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsNotificationEnabled -> error, errorCode: %{public}d", externalCode); @@ -42,7 +41,7 @@ ani_boolean AniIsNotificationEnabledWithId(ani_env *env, ani_double userId) ANS_LOGD("AniIsNotificationEnabledWithId call"); bool allowed = false; int returncode = Notification::NotificationHelper::IsAllowedNotify(userId, allowed); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsNotificationEnabledWithId -> error, errorCode: %{public}d", externalCode); @@ -64,7 +63,7 @@ ani_boolean AniIsNotificationEnabledWithBundleOption(ani_env *env, ani_object bu return ANI_FALSE; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsNotificationEnabledWithBundleOption -> error, errorCode: %{public}d", externalCode); @@ -85,7 +84,7 @@ void AniSetNotificationEnable(ani_env *env, ani_object bundleOption, ani_boolean std::string deviceId {""}; int returncode = Notification::NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(option, deviceId, NotificationSts::AniBooleanToBool(enable)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniSetNotificationEnable -> error, errorCode: %{public}d", externalCode); @@ -98,7 +97,7 @@ ani_object AniGetAllNotificationEnabledBundles(ani_env *env) ANS_LOGD("AniGetAllNotificationEnabledBundles call"); std::vector bundleOptions = {}; int returncode = Notification::NotificationHelper::GetAllNotificationEnabledBundles(bundleOptions); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("AniGetAllNotificationEnabledBundles -> error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -118,7 +117,7 @@ ani_boolean AniIsNotificationEnabledSync(ani_env *env) ANS_LOGD("AniIsNotificationEnabledSync call"); bool allowed = false; int returncode = Notification::NotificationHelper::IsAllowedNotifySelf(allowed); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("AniIsNotificationEnabledSync -> error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -133,7 +132,7 @@ ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double use bool enabled = false; int returncode = Notification::NotificationHelper::GetSyncNotificationEnabledWithoutApp( static_cast(userId), enabled); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("AniGetSyncNotificationEnabledWithoutApp -> error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -148,7 +147,7 @@ void AniSetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId, an ANS_LOGD("AniSetSyncNotificationEnabledWithoutApp call,enable : %{public}d", enabled); int returncode = Notification::NotificationHelper::SetSyncNotificationEnabledWithoutApp( static_cast(userId), NotificationSts::AniBooleanToBool(enabled)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("AniSetSyncNotificationEnabledWithoutApp -> error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -173,7 +172,7 @@ void AniDisableNotificationFeature(ani_env *env, ani_boolean disabled, ani_objec int returncode = ERR_OK; returncode = Notification::NotificationHelper::DisableNotificationFeature(param); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("AniDisableNotificationFeature error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); diff --git a/frameworks/ets/ani/src/manager/ani_on.cpp b/frameworks/ets/ani/src/manager/ani_on.cpp index 8d4da2c64..8bbab66b1 100755 --- a/frameworks/ets/ani/src/manager/ani_on.cpp +++ b/frameworks/ets/ani/src/manager/ani_on.cpp @@ -22,7 +22,6 @@ #include "ipc_skeleton.h" #include "tokenid_kit.h" #include "notification_helper.h" -#include "inner_errors.h" constexpr const char* TYPE_STRING = "checkNotification"; namespace OHOS { @@ -77,7 +76,7 @@ ani_int AniOn(ani_env *env, ani_string type, ani_fn_object fn, ani_object checkR stsPushCallBack_->SetJsPushCallBackObject(env, outSlotType, fn); auto result = NotificationHelper::RegisterPushCallback(stsPushCallBack_->AsObject(), checkRequest); if (result != ERR_OK) { - int32_t externalCode = ERR_OK ? ERR_OK : CJSystemapi::Notification::ErrorToExternal(result); + int32_t externalCode = ERR_OK ? ERR_OK : NotificationSts::GetExternalCode(result); ANS_LOGE("Register failed, result is %{public}d", externalCode); OHOS::NotificationSts::ThrowStsErrorWithCode(env, externalCode); return externalCode; diff --git a/frameworks/ets/ani/src/manager/ani_open_settings.cpp b/frameworks/ets/ani/src/manager/ani_open_settings.cpp index 962e28e77..0fbb71964 100644 --- a/frameworks/ets/ani/src/manager/ani_open_settings.cpp +++ b/frameworks/ets/ani/src/manager/ani_open_settings.cpp @@ -17,7 +17,6 @@ #include "ans_log_wrapper.h" #include "sts_error_utils.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ani_common_util.h" #include "sts_throw_erro.h" @@ -140,7 +139,7 @@ void StsAsyncCompleteCallbackOpenSettings(ani_env *env, std::shared_ptrerrorCode == - ERR_OK ? ERR_OK : CJSystemapi::Notification::ErrorToExternal(info->errorCode); + ERR_OK ? ERR_OK : NotificationSts::GetExternalCode(info->errorCode); } if (errorCode == ERR_OK) { diff --git a/frameworks/ets/ani/src/manager/ani_publish.cpp b/frameworks/ets/ani/src/manager/ani_publish.cpp index ba7f1f4f8..674d6b945 100644 --- a/frameworks/ets/ani/src/manager/ani_publish.cpp +++ b/frameworks/ets/ani/src/manager/ani_publish.cpp @@ -14,7 +14,6 @@ */ #include "ani_publish.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_bundle_option.h" @@ -37,7 +36,7 @@ void AniPublish(ani_env *env, ani_object obj) return; } int returncode = NotificationHelper::PublishNotification(*notificationRequest); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -55,7 +54,7 @@ void AniPublishWithId(ani_env *env, ani_object obj, ani_double userId) } notificationRequest->SetOwnerUserId(static_cast(userId)); int returncode = NotificationHelper::PublishNotification(*notificationRequest); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("AniPublishWithId error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -81,7 +80,7 @@ void AniPublishAsBundle(ani_env *env, ani_object request, ani_string representat notificationRequest->SetOwnerUserId(static_cast(userId)); notificationRequest->SetOwnerBundleName(bundleStr); int returncode = NotificationHelper::PublishNotification(*notificationRequest); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("AniPublishAsBundle: PublishNotificationerror, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -112,7 +111,7 @@ void AniPublishAsBundleWithBundleOption(ani_env *env, ani_object representativeB notificationRequest->SetIsAgentNotification(true); int returncode = NotificationHelper::PublishNotification(*notificationRequest); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("AniPublishAsBundleWithBundleOption error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); diff --git a/frameworks/ets/ani/src/manager/ani_remove_group.cpp b/frameworks/ets/ani/src/manager/ani_remove_group.cpp index b916af197..33d90ca76 100644 --- a/frameworks/ets/ani/src/manager/ani_remove_group.cpp +++ b/frameworks/ets/ani/src/manager/ani_remove_group.cpp @@ -17,7 +17,6 @@ #include "ans_log_wrapper.h" #include "sts_error_utils.h" -#include "inner_errors.h" #include "notification_helper.h" #include "sts_common.h" #include "sts_throw_erro.h" @@ -35,14 +34,15 @@ void AniRemoveGroupByBundle(ani_env *env, ani_object bundleOption, ani_string gr NotificationSts::ThrowStsErroWithMsg(env, "sts AniRemoveGroupByBundle ERROR_INTERNAL_ERROR"); return ; } - std::string groupNameStr = ""; - ani_status status = NotificationSts::GetStringByAniString(env, groupName, groupNameStr); + std::string tempStr = ""; + ani_status status = NotificationSts::GetStringByAniString(env, groupName, tempStr); if (status != ANI_OK) { NotificationSts::ThrowStsErroWithMsg(env, "sts AniRemoveGroupByBundle ERROR_INTERNAL_ERROR"); return ; } + std::string groupNameStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); int returncode = OHOS::Notification::NotificationHelper::RemoveGroupByBundle(option, groupNameStr); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + int externalCode = NotificationSts::GetExternalCode(returncode); if (externalCode != ERR_OK) { ANS_LOGE("AniRemoveGroupByBundle -> error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); diff --git a/frameworks/ets/ani/src/manager/ani_request_enable.cpp b/frameworks/ets/ani/src/manager/ani_request_enable.cpp index 910cac486..a558c2990 100755 --- a/frameworks/ets/ani/src/manager/ani_request_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_request_enable.cpp @@ -17,7 +17,6 @@ #include "ani_ans_dialog_callback.h" #include "ans_log_wrapper.h" #include "sts_error_utils.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ani_common_util.h" #include "sts_throw_erro.h" @@ -86,7 +85,7 @@ void StsAsyncCompleteCallbackRequestEnableNotification(ani_env *env, std::shared if (env == nullptr || info == nullptr) return; ani_status status; int32_t errorCode = info->errorCode == - ERR_OK ? ERR_OK : CJSystemapi::Notification::ErrorToExternal(info->errorCode); + ERR_OK ? ERR_OK : NotificationSts::GetExternalCode(info->errorCode); if (errorCode == ERR_OK) { ANS_LOGD("Resolve. errorCode %{public}d", errorCode); ani_object ret = OHOS::AppExecFwk::createInt(env, errorCode); diff --git a/frameworks/ets/ani/src/manager/ani_slot.cpp b/frameworks/ets/ani/src/manager/ani_slot.cpp index 8790b0a3b..d0d49fc53 100644 --- a/frameworks/ets/ani/src/manager/ani_slot.cpp +++ b/frameworks/ets/ani/src/manager/ani_slot.cpp @@ -18,7 +18,6 @@ #include "sts_throw_erro.h" #include "sts_error_utils.h" #include "sts_common.h" -#include "inner_errors.h" #include "notification_helper.h" #include "sts_bundle_option.h" #include "sts_slot.h" @@ -34,7 +33,7 @@ constexpr int32_t RETURN_EXCEPTION_VALUE = -1; ani_object AniGetSlotsByBundle(ani_env *env, ani_object bundleOption) { ANS_LOGD("sts GetSlotsByBundle enter"); - int returncode = CJSystemapi::Notification::SUCCESS_CODE; + int returncode = ERR_OK; std::vector> slots; BundleOption option; if (NotificationSts::UnwrapBundleOption(env, bundleOption, option)) { @@ -44,8 +43,8 @@ ani_object AniGetSlotsByBundle(ani_env *env, ani_object bundleOption) return nullptr; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("sts GetSlotsByBundle error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return nullptr; @@ -69,8 +68,8 @@ void AniAddSlots(ani_env *env, ani_object notificationSlotArrayObj) return; } int returncode = Notification::NotificationHelper::AddNotificationSlots(slots); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniAddSlots -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; @@ -81,7 +80,7 @@ void AniAddSlots(ani_env *env, ani_object notificationSlotArrayObj) void AniAddSlotByNotificationSlot(ani_env *env, ani_object notificationSlotObj) { ANS_LOGD("AniAddSlotByNotificationSlot enter"); - int returncode = CJSystemapi::Notification::SUCCESS_CODE; + int returncode = ERR_OK; Notification::NotificationSlot slot; if (NotificationSts::UnwrapNotificationSlot(env, notificationSlotObj, slot)) { returncode = Notification::NotificationHelper::AddNotificationSlot(slot); @@ -89,8 +88,8 @@ void AniAddSlotByNotificationSlot(ani_env *env, ani_object notificationSlotObj) NotificationSts::ThrowStsErroWithMsg(env, "sts AddSlot ERROR_INTERNAL_ERROR"); return; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("sts AddSlot error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; @@ -107,8 +106,8 @@ void AniAddSlotBySlotType(ani_env *env, ani_enum_item enumObj) return; } int returncode = Notification::NotificationHelper::AddSlotByType(slotType); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniAddSlotBySlotType -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -127,8 +126,8 @@ ani_object AniGetSlot(ani_env *env, ani_enum_item enumObj) } sptr slot = nullptr; int returncode = Notification::NotificationHelper::GetNotificationSlot(slotType, slot); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniGetSlot -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -152,8 +151,8 @@ ani_object AniGetSlots(ani_env *env) ANS_LOGD("AniGetSlots enter"); std::vector> slots; int returncode = Notification::NotificationHelper::GetNotificationSlots(slots); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniGetSlots -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return nullptr; @@ -178,8 +177,8 @@ void AniRemoveSlot(ani_env *env, ani_enum_item enumObj) return; } int returncode = Notification::NotificationHelper::RemoveNotificationSlot(slotType); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniRemoveSlot -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; @@ -191,8 +190,8 @@ void AniRemoveAllSlots(ani_env *env) { ANS_LOGD("AniRemoveAllSlots enter"); int returncode = Notification::NotificationHelper::RemoveAllSlots(); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniRemoveAllSlots -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; @@ -227,8 +226,8 @@ void AniSetSlotByBundle(ani_env *env, ani_object bundleOptionObj, ani_object slo slotsVct.emplace_back(slotPtr); int returncode = Notification::NotificationHelper::UpdateNotificationSlots(option, slotsVct); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("sts SetSlotByBundle error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; @@ -247,8 +246,8 @@ ani_double AniGetSlotNumByBundle(ani_env *env, ani_object bundleOption) } uint64_t num = 0; int returncode = Notification::NotificationHelper::GetNotificationSlotNumAsBundle(option, num); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("sts GetSlotNumByBundle error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return RETURN_EXCEPTION_VALUE; @@ -275,8 +274,8 @@ void AniSetNotificationEnableSlot(ani_env *env, ani_object bundleOption, ani_enu returncode = Notification::NotificationHelper::SetEnabledForBundleSlot(option, slotType, NotificationSts::AniBooleanToBool(enable), isForceControl); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniSetNotificationEnableSlot error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; @@ -300,8 +299,8 @@ void AniSetNotificationEnableSlotWithForce(ani_env *env, returncode = Notification::NotificationHelper::SetEnabledForBundleSlot(option, slotType, NotificationSts::AniBooleanToBool(enable), NotificationSts::AniBooleanToBool(isForceControl)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniSetNotificationEnableSlotSync error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -320,8 +319,8 @@ ani_boolean AniIsNotificationSlotEnabled(ani_env *env, ani_object bundleOption, bool isEnable = false; int returncode = Notification::NotificationHelper::GetEnabledForBundleSlot(option, slotType, isEnable); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("IsNotificationSlotEnabled -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -338,8 +337,8 @@ ani_int AniGetSlotFlagsByBundle(ani_env *env, ani_object obj) } uint32_t slotFlags = 0; int returncode = Notification::NotificationHelper::GetNotificationSlotFlagsAsBundle(option, slotFlags); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniGetSlotFlagsByBundle -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -356,8 +355,8 @@ void AniSetSlotFlagsByBundle(ani_env *env, ani_object obj, ani_double slotFlags) } int returncode = Notification::NotificationHelper::SetNotificationSlotFlagsAsBundle(option, static_cast(slotFlags)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniSetSlotFlagsByBundle -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } diff --git a/frameworks/ets/ani/src/manager/ani_support_template.cpp b/frameworks/ets/ani/src/manager/ani_support_template.cpp index 461787a31..b79ef22eb 100755 --- a/frameworks/ets/ani/src/manager/ani_support_template.cpp +++ b/frameworks/ets/ani/src/manager/ani_support_template.cpp @@ -14,7 +14,6 @@ */ #include "ani_support_template.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -27,17 +26,17 @@ namespace NotificationManagerSts { ani_boolean AniIsSupportTemplate(ani_env* env, ani_string templateName) { ANS_LOGD("AniIsSupportTemplate call"); - std::string templateNameStr; - if (NotificationSts::GetStringByAniString(env, templateName, templateNameStr) != ANI_OK) { + std::string tempStr; + if (NotificationSts::GetStringByAniString(env, templateName, tempStr) != ANI_OK) { NotificationSts::ThrowStsErroWithMsg(env, "templateName parse failed!"); return NotificationSts::BoolToAniBoolean(false); } - + std::string templateNameStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); ANS_LOGD("AniIsSupportTemplate by templateName:%{public}s", templateNameStr.c_str()); bool support = false; int returncode = Notification::NotificationHelper::IsSupportTemplate(templateNameStr, support); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsSupportTemplate -> error, errorCode: %{public}d", externalCode); return NotificationSts::BoolToAniBoolean(false); @@ -54,8 +53,8 @@ ani_object AniGetDeviceRemindType(ani_env *env) Notification::NotificationConstant::RemindType::DEVICE_IDLE_REMIND; int returncode = Notification::NotificationHelper::GetDeviceRemindType(remindType); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniGetDeviceRemindType error, errorCode: %{public}d", externalCode); return nullptr; diff --git a/frameworks/ets/ani/src/manager/ani_sync_config.cpp b/frameworks/ets/ani/src/manager/ani_sync_config.cpp index 5a05c28f7..edf00e43c 100644 --- a/frameworks/ets/ani/src/manager/ani_sync_config.cpp +++ b/frameworks/ets/ani/src/manager/ani_sync_config.cpp @@ -14,7 +14,6 @@ */ #include "ani_sync_config.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -49,8 +48,8 @@ ani_double AniSetAdditionalConfig(ani_env *env, ani_string key, ani_string value return RESULT_FAILED; } int returncode = Notification::NotificationHelper::SetAdditionConfig(keyStr, valueStr); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("setAdditionalConfig -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return RESULT_FAILED; diff --git a/frameworks/ets/ani/src/sts_bundle_option.cpp b/frameworks/ets/ani/src/sts_bundle_option.cpp index 2cf67a9bf..edcf16454 100644 --- a/frameworks/ets/ani/src/sts_bundle_option.cpp +++ b/frameworks/ets/ani/src/sts_bundle_option.cpp @@ -26,12 +26,13 @@ bool UnwrapBundleOption(ani_env *env, ani_object obj, Notification::Notification ANS_LOGE("UnwrapBundleOption failed, has nullptr"); return false; } - std::string bundleName; + std::string tempStr; ani_boolean isUndefined = ANI_TRUE; - if (GetPropertyString(env, obj, "bundle", isUndefined, bundleName) !=ANI_OK || isUndefined == ANI_TRUE) { + if (GetPropertyString(env, obj, "bundle", isUndefined, tempStr) !=ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("UnwrapBundleOption Get bundle failed"); return false; } + std::string bundleName = GetResizeStr(tempStr, STR_MAX_SIZE); option.SetBundleName(bundleName); ani_double result = 0.0; if (GetPropertyDouble(env, obj, "uid", isUndefined, result) == ANI_OK && isUndefined == ANI_FALSE) { diff --git a/frameworks/ets/ani/src/sts_common.cpp b/frameworks/ets/ani/src/sts_common.cpp index 31f5b6b53..54e5d0e47 100644 --- a/frameworks/ets/ani/src/sts_common.cpp +++ b/frameworks/ets/ani/src/sts_common.cpp @@ -22,6 +22,10 @@ namespace NotificationSts { constexpr const char* CLASSNAME_BOOLEAN = "Lstd/core/Boolean;"; constexpr const char* CLASSNAME_DOUBLE = "Lstd/core/Double;"; constexpr const char* CLASSNAME_INT = "Lstd/core/Int;"; +std::string GetResizeStr(std::string instr, int32_t length) +{ + return instr.length() <= length ? instr : instr.substr(0, length); +} bool IsUndefine(ani_env *env, const ani_object &obj) { diff --git a/frameworks/ets/ani/src/sts_convert_other.cpp b/frameworks/ets/ani/src/sts_convert_other.cpp index b316a4859..f85af200b 100644 --- a/frameworks/ets/ani/src/sts_convert_other.cpp +++ b/frameworks/ets/ani/src/sts_convert_other.cpp @@ -51,19 +51,20 @@ ani_status UnwrapResource(ani_env *env, ani_object obj, ResourceManager::Resourc return ANI_ERROR; } ani_status status = ANI_ERROR; - std::string bundleName = ""; + std::string tempStr = ""; ani_boolean isUndefined = ANI_TRUE; - if ((status = GetPropertyString(env, obj, "bundleName", isUndefined, bundleName)) != ANI_OK + if ((status = GetPropertyString(env, obj, "bundleName", isUndefined, tempStr)) != ANI_OK || isUndefined == ANI_TRUE) { return ANI_INVALID_ARGS; } + std::string bundleName = GetResizeStr(tempStr, STR_MAX_SIZE); resource.bundleName = bundleName; - std::string moduleName = ""; - if ((status = GetPropertyString(env, obj, "moduleName", isUndefined, moduleName)) != ANI_OK + if ((status = GetPropertyString(env, obj, "moduleName", isUndefined, tempStr)) != ANI_OK || isUndefined == ANI_TRUE) { return ANI_INVALID_ARGS; } + std::string moduleName = GetResizeStr(tempStr, STR_MAX_SIZE); resource.moduleName = moduleName; ani_double idAni = 0.0; diff --git a/frameworks/ets/ani/src/sts_notification_content.cpp b/frameworks/ets/ani/src/sts_notification_content.cpp index b3aa635f9..8e3b5764a 100644 --- a/frameworks/ets/ani/src/sts_notification_content.cpp +++ b/frameworks/ets/ani/src/sts_notification_content.cpp @@ -268,11 +268,12 @@ ani_status UnWarpNotificationIconButton(ani_env *env, ani_object obj, Notificati } ani_status status = ANI_ERROR; ani_boolean isUndefined = ANI_TRUE; - std::string name = ""; - if ((status = GetPropertyString(env, obj, "name", isUndefined, name)) != ANI_OK || isUndefined == ANI_TRUE) { + std::string tempStr = ""; + if ((status = GetPropertyString(env, obj, "name", isUndefined, tempStr)) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("UnWarpNotificationIconButton: get name failed, status = %{public}d", status); return ANI_INVALID_ARGS; } + std::string name = GetResizeStr(tempStr, STR_MAX_SIZE); iconButton.SetName(name); ani_ref iconRef = {}; if ((status = GetPropertyRef(env, obj, "iconResource", isUndefined, iconRef)) != ANI_OK @@ -291,8 +292,8 @@ ani_status UnWarpNotificationIconButton(ani_env *env, ani_object obj, Notificati } iconButton.SetIconImage(pixelMap); } - std::string text = ""; - if (GetPropertyString(env, obj, "text", isUndefined, text) == ANI_OK && isUndefined == ANI_FALSE) { + if (GetPropertyString(env, obj, "text", isUndefined, tempStr) == ANI_OK && isUndefined == ANI_FALSE) { + std::string text = GetResizeStr(tempStr, STR_MAX_SIZE); iconButton.SetName(text); } else { ANS_LOGD("UnWarpNotificationIconButton: get text failed"); @@ -362,7 +363,7 @@ void UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, // names?: Array if (GetPropertyStringArray(env, obj, "names", isUndefined, names) == ANI_OK && isUndefined == ANI_FALSE) { for (auto name: names) { - button.addSingleButtonName(name); + button.addSingleButtonName(GetResizeStr(name, STR_MAX_SIZE)); } } else { ANS_LOGD("UnWarpNotificationLocalLiveViewButton get names failed."); @@ -479,7 +480,7 @@ void UnWarpNotificationCapsule(ani_env *env, ani_object obj, NotificationCapsule ani_boolean isUndefined = ANI_TRUE; std::string title = ""; if (GetPropertyString(env, obj, "title", isUndefined, title) == ANI_OK && isUndefined == ANI_FALSE) { - capsule.SetTitle(title); + capsule.SetTitle(GetResizeStr(title, STR_MAX_SIZE)); } else { ANS_LOGE("UnWarpNotificationCapsule: get title failed"); } @@ -487,14 +488,14 @@ void UnWarpNotificationCapsule(ani_env *env, ani_object obj, NotificationCapsule isUndefined = ANI_TRUE; if (GetPropertyString(env, obj, "backgroundColor", isUndefined, backgroundColor) == ANI_OK && isUndefined == ANI_FALSE) { - capsule.SetBackgroundColor(backgroundColor); + capsule.SetBackgroundColor(GetResizeStr(backgroundColor, STR_MAX_SIZE)); } else { ANS_LOGE("UnWarpNotificationCapsule: get backgroundColor failed"); } std::string content = ""; isUndefined = ANI_TRUE; if (GetPropertyString(env, obj, "content", isUndefined, content) == ANI_OK && isUndefined == ANI_FALSE) { - capsule.SetContent(content); + capsule.SetContent(GetResizeStr(content, STR_MAX_SIZE)); } else { ANS_LOGE("UnWarpNotificationCapsule: get content failed"); } @@ -652,17 +653,17 @@ ani_status UnWarpNotificationBasicContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationBasicContent: get title failed, status = %{public}d", status); return ANI_INVALID_ARGS; } - basicContent->SetTitle(title); + basicContent->SetTitle(GetResizeStr(title, SHORT_TEXT_SIZE)); std::string text; if ((status = GetPropertyString(env, obj, "text", isUndefined, text)) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("UnWarpNotificationBasicContent: get text failed, status = %{public}d", status); return ANI_INVALID_ARGS; } - basicContent->SetText(text); + basicContent->SetText(GetResizeStr(text, COMMON_TEXT_SIZE)); std::string additionalText; if (GetPropertyString(env, obj, "additionalText", isUndefined, additionalText) == ANI_OK && isUndefined == ANI_FALSE) { - basicContent->SetAdditionalText(additionalText); + basicContent->SetAdditionalText(GetResizeStr(additionalText, COMMON_TEXT_SIZE)); } else { ANS_LOGD("UnWarpNotificationBasicContent: get additionalText failed"); } @@ -719,21 +720,21 @@ ani_status UnWarpNotificationLongTextContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationLongTextContent:get longText failed"); return ANI_INVALID_ARGS; } - longTextContent->SetLongText(longText); + longTextContent->SetLongText(GetResizeStr(longText, COMMON_TEXT_SIZE)); std::string briefText; if ((status = GetPropertyString(env, obj, "briefText", isUndefined, briefText)) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("UnWarpNotificationLongTextContent:get briefText failed"); return ANI_INVALID_ARGS; } - longTextContent->SetBriefText(briefText); + longTextContent->SetBriefText(GetResizeStr(briefText, SHORT_TEXT_SIZE)); std::string expandedTitle; if ((status = GetPropertyString(env, obj, "expandedTitle", isUndefined, expandedTitle)) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("UnWarpNotificationLongTextContent:get expandedTitle failed"); return ANI_INVALID_ARGS; } - longTextContent->SetExpandedTitle(expandedTitle); + longTextContent->SetExpandedTitle(GetResizeStr(expandedTitle, SHORT_TEXT_SIZE)); ANS_LOGD("UnWarpNotificationLongTextContent end"); return status; } @@ -758,7 +759,7 @@ ani_status UnWarpNotificationMultiLineContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationMultiLineContent: get longTitle failed"); return ANI_INVALID_ARGS; } - multiLineContent->SetExpandedTitle(longTitle); + multiLineContent->SetExpandedTitle(GetResizeStr(longTitle, SHORT_TEXT_SIZE)); std::string briefText; isUndefined = ANI_TRUE; @@ -767,7 +768,7 @@ ani_status UnWarpNotificationMultiLineContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationMultiLineContent: get briefText failed"); return ANI_INVALID_ARGS; } - multiLineContent->SetBriefText(briefText); + multiLineContent->SetBriefText(GetResizeStr(briefText, SHORT_TEXT_SIZE)); std::vector lines = {}; isUndefined = ANI_TRUE; @@ -777,7 +778,7 @@ ani_status UnWarpNotificationMultiLineContent(ani_env *env, ani_object obj, return ANI_INVALID_ARGS; } for (auto line : lines) { - multiLineContent->AddSingleLine(line); + multiLineContent->AddSingleLine(GetResizeStr(line, SHORT_TEXT_SIZE)); } ANS_LOGD("UnWarpNotificationMultiLineContent end"); return status; @@ -803,7 +804,7 @@ ani_status UnWarpNotificationPictureContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationPictureContent: get expandedTitle failed"); return ANI_INVALID_ARGS; } - pictureContent->SetExpandedTitle(expandedTitle); + pictureContent->SetExpandedTitle(GetResizeStr(expandedTitle, SHORT_TEXT_SIZE)); std::string briefText; if ((status = GetPropertyString(env, obj, "briefText", isUndefined, briefText)) != ANI_OK @@ -811,7 +812,7 @@ ani_status UnWarpNotificationPictureContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationPictureContent: get briefText failed"); return ANI_INVALID_ARGS; } - pictureContent->SetBriefText(briefText); + pictureContent->SetBriefText(GetResizeStr(briefText, SHORT_TEXT_SIZE)); ani_ref pictureRef = {}; if ((status = GetPropertyRef(env, obj, "picture", isUndefined, pictureRef)) != ANI_OK || isUndefined == ANI_TRUE || pictureRef == nullptr) { diff --git a/frameworks/ets/ani/src/sts_notification_manager.cpp b/frameworks/ets/ani/src/sts_notification_manager.cpp index eb0116381..965ba2664 100644 --- a/frameworks/ets/ani/src/sts_notification_manager.cpp +++ b/frameworks/ets/ani/src/sts_notification_manager.cpp @@ -499,7 +499,7 @@ ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonO ANS_LOGE("UnWarpNotificationButtonOption: get buttonName failed"); return ANI_INVALID_ARGS; } - buttonOption.SetButtonName(buttonName); + buttonOption.SetButtonName(GetResizeStr(buttonName, STR_MAX_SIZE)); ANS_LOGD("UnWarpNotificationButtonOption end"); return status; } diff --git a/frameworks/ets/ani/src/sts_request.cpp b/frameworks/ets/ani/src/sts_request.cpp index ed3de90e9..ed343a705 100644 --- a/frameworks/ets/ani/src/sts_request.cpp +++ b/frameworks/ets/ani/src/sts_request.cpp @@ -33,7 +33,6 @@ namespace NotificationSts { using namespace OHOS::AAFwk; using namespace OHOS::AppExecFwk; -constexpr int32_t STR_MAX_SIZE = 204; void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOptions distributedOptions) { ANS_LOGD("UnWarpDistributedOptions start"); @@ -51,19 +50,27 @@ void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOption ANS_LOGD("UnWarpDistributedOptions: isDistributed get failed"); } // supportDisplayDevices?: Array; - std::vector supportDisplayDevices = {}; + std::vector tempStrings = {}; isUndefined = ANI_TRUE; - if (GetPropertyStringArray(env, obj, "supportDisplayDevices", isUndefined, supportDisplayDevices) == ANI_OK + if (GetPropertyStringArray(env, obj, "supportDisplayDevices", isUndefined, tempStrings) == ANI_OK && isUndefined == ANI_FALSE) { + std::vector supportDisplayDevices = {}; + for (auto device: tempStrings) { + supportDisplayDevices.emplace_back(GetResizeStr(device, STR_MAX_SIZE)); + } distributedOptions.supportDisplayDevices = supportDisplayDevices; } else { ANS_LOGD("UnWarpDistributedOptions: supportDisplayDevices get failed"); } // supportOperateDevices?: Array; - std::vector supportOperateDevices = {}; + tempStrings.clear(); isUndefined = ANI_TRUE; - if (GetPropertyStringArray(env, obj, "supportOperateDevices", isUndefined, supportOperateDevices) == ANI_OK + if (GetPropertyStringArray(env, obj, "supportOperateDevices", isUndefined, tempStrings) == ANI_OK && isUndefined == ANI_FALSE) { + std::vector supportOperateDevices = {}; + for (auto device: tempStrings) { + supportOperateDevices.emplace_back(GetResizeStr(device, STR_MAX_SIZE)); + } distributedOptions.supportOperateDevices = supportOperateDevices; } else { ANS_LOGD("UnWarpDistributedOptions: supportOperateDevices get failed"); @@ -232,25 +239,16 @@ void GetNotificationRequestByString(ani_env *env, ani_object obj, std::string mString = ""; ani_boolean isUndefined = ANI_TRUE; if (ANI_OK == GetPropertyString(env, obj, "classification", isUndefined, mString) && isUndefined == ANI_FALSE) { - if (mString.length() > STR_MAX_SIZE) { - mString.resize(STR_MAX_SIZE); - } - request->SetClassification(mString); + request->SetClassification(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, obj, "appMessageId", isUndefined, mString) && isUndefined == ANI_FALSE) { request->SetAppMessageId(mString); } if (ANI_OK == GetPropertyString(env, obj, "label", isUndefined, mString) && isUndefined == ANI_FALSE) { - if (mString.length() > STR_MAX_SIZE) { - mString.resize(STR_MAX_SIZE); - } - request->SetLabel(mString); + request->SetLabel(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, obj, "groupName", isUndefined, mString) && isUndefined == ANI_FALSE) { - if (mString.length() > STR_MAX_SIZE) { - mString.resize(STR_MAX_SIZE); - } - request->SetGroupName(mString); + request->SetGroupName(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, obj, "sound", isUndefined, mString) && isUndefined == ANI_FALSE) { request->SetSound(mString); @@ -673,19 +671,19 @@ void GetNotificationUnifiedGroupInfo(ani_env *env, ani_object obj, std::string mString = ""; if (ANI_OK == GetPropertyString(env, static_cast(infoRef), "key", isUndefind, mString) && isUndefind == ANI_FALSE) { - unifiedGroupInfo->SetKey(mString); + unifiedGroupInfo->SetKey(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, static_cast(infoRef), "title", isUndefind, mString) && isUndefind == ANI_FALSE) { - unifiedGroupInfo->SetTitle(mString); + unifiedGroupInfo->SetTitle(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, static_cast(infoRef), "content", isUndefind, mString) && isUndefind == ANI_FALSE) { - unifiedGroupInfo->SetContent(mString); + unifiedGroupInfo->SetContent(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, static_cast(infoRef), "sceneName", isUndefind, mString) && isUndefind == ANI_FALSE) { - unifiedGroupInfo->SetSceneName(mString); + unifiedGroupInfo->SetSceneName(GetResizeStr(mString, STR_MAX_SIZE)); } ani_ref extraInfoRef = {}; status = GetPropertyRef(env, static_cast(infoRef), "extraInfo", isUndefind, extraInfoRef); diff --git a/frameworks/ets/ani/src/sts_slot.cpp b/frameworks/ets/ani/src/sts_slot.cpp index 844c3fc89..88af70b02 100644 --- a/frameworks/ets/ani/src/sts_slot.cpp +++ b/frameworks/ets/ani/src/sts_slot.cpp @@ -222,12 +222,12 @@ bool ParseNotificationSlotByBasicType(ani_env *env, ani_object notificationSlotO ani_boolean isUndefined = ANI_TRUE; std::string desc = ""; if (GetPropertyString(env, notificationSlotObj, "desc", isUndefined, desc) == ANI_OK && isUndefined == ANI_FALSE) { - slot.SetDescription(desc); + slot.SetDescription(GetResizeStr(desc, STR_MAX_SIZE)); } std::string sound = ""; if (GetPropertyString(env, notificationSlotObj, "sound", isUndefined, sound) == ANI_OK && isUndefined == ANI_FALSE) { - slot.SetSound(Uri(sound)); + slot.SetSound(Uri(GetResizeStr(sound, STR_MAX_SIZE))); } ani_double doubleValue = 0.0; if (GetPropertyDouble(env, notificationSlotObj, "lockscreenVisibility", isUndefined, doubleValue) == ANI_OK diff --git a/frameworks/ets/ani/src/sts_subscribe.cpp b/frameworks/ets/ani/src/sts_subscribe.cpp index 1fd46299f..5d6797b4a 100644 --- a/frameworks/ets/ani/src/sts_subscribe.cpp +++ b/frameworks/ets/ani/src/sts_subscribe.cpp @@ -15,7 +15,6 @@ #include "sts_subscribe.h" #include "ans_log_wrapper.h" -#include "inner_errors.h" #include "notification_helper.h" #include "sts_throw_erro.h" #include "sts_common.h" @@ -63,9 +62,8 @@ void StsDistributedOperationCallback::OnStsOperationCallback(ani_env *env, const return; } ani_status status = ANI_OK; - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(operationResult); - externalErrorCode = - (externalErrorCode == CJSystemapi::Notification::SUCCESS_CODE) ? operationResult : externalErrorCode; + int32_t externalErrorCode = GetExternalCode(operationResult); + externalErrorCode = (externalErrorCode == ERR_OK) ? operationResult : externalErrorCode; ANS_LOGD("operationResult %{public}d, externalCode %{public}d", operationResult, externalErrorCode); if (externalErrorCode == 0) { @@ -616,9 +614,8 @@ bool SubscriberInstanceManager::Subscribe(ani_env *env, ani_object subscriber, a status = NotificationHelper::SubscribeNotification(stsSubscriber); } if (status != ERR_OK) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(status); - externalErrorCode = - (externalErrorCode == CJSystemapi::Notification::SUCCESS_CODE) ? status : externalErrorCode; + int32_t externalErrorCode = GetExternalCode(status); + externalErrorCode = (externalErrorCode == ERR_OK) ? status : externalErrorCode; ANS_LOGD("SubscribeNotification faild. status %{public}d ErrorToExternal %{public}d", status, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); @@ -648,9 +645,8 @@ bool SubscriberInstanceManager::UnSubscribe(ani_env *env, ani_object subscriber) if (ret) { int32_t status = NotificationHelper::UnSubscribeNotification(stsSubscriber); if (status != ERR_OK) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(status); - externalErrorCode = - (externalErrorCode == CJSystemapi::Notification::SUCCESS_CODE) ? status : externalErrorCode; + int32_t externalErrorCode = GetExternalCode(status); + externalErrorCode = (externalErrorCode == ERR_OK) ? status : externalErrorCode; ANS_LOGD("UnSubscribe faild. status %{public}d ErrorToExternal %{public}d", status, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); @@ -690,9 +686,8 @@ bool SubscriberInstanceManager::SubscribeSelf(ani_env *env, ani_object subscribe ErrCode status = ERR_OK; status = NotificationHelper::SubscribeNotificationSelf(stsSubscriber); if (status != ERR_OK) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(status); - externalErrorCode = - (externalErrorCode == CJSystemapi::Notification::SUCCESS_CODE) ? status : externalErrorCode; + int32_t externalErrorCode = GetExternalCode(status); + externalErrorCode = (externalErrorCode == ERR_OK) ? status : externalErrorCode; ANS_LOGD("SubscribeNotificationSelf faild. status %{public}d ErrorToExternal %{public}d", status, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); @@ -760,7 +755,7 @@ bool UnWarpNotificationKey(ani_env *env, const ani_object obj, NotificationKey & ANS_LOGD("UnWarpNotificationKey GetPropertyString label fail"); return false; } - OutObj.label = label; + OutObj.label = GetResizeStr(label, STR_MAX_SIZE); ANS_LOGD("UnWarpNotificationKey id: %{public}d, label: %{public}s", OutObj.id, OutObj.label.c_str()); return true; } @@ -774,14 +769,12 @@ bool UnwarpOperationInfo(ani_env *env, const ani_object obj, StsNotificationOper ANS_LOGD("ConvertOperationInfoToNative GetStringOrUndefined actionName fail"); return false; } - outObj.SetActionName(actionName); + outObj.SetActionName(GetResizeStr(actionName, STR_MAX_SIZE)); if (GetPropertyString(env, obj, "userInput", isUndefined, userInput) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGD("ConvertOperationInfoToNative GetStringOrUndefined userInput fail"); return false; } - outObj.SetUserInput(actionName); - ANS_LOGD("ConvertOperationInfoToNative actionName: %{public}s, userInput: %{public}s", - outObj.GetActionName().c_str(), outObj.GetUserInput().c_str()); + outObj.SetUserInput(GetResizeStr(userInput, LONG_STR_MAX_SIZE)); return true; } diff --git a/frameworks/ets/ani/src/sts_subscribe_info.cpp b/frameworks/ets/ani/src/sts_subscribe_info.cpp index 4b5c4a891..9b1dd67a2 100644 --- a/frameworks/ets/ani/src/sts_subscribe_info.cpp +++ b/frameworks/ets/ani/src/sts_subscribe_info.cpp @@ -26,7 +26,7 @@ bool UnwarpNotificationSubscribeInfo(ani_env *env, ani_object value, Notificatio ANS_LOGE("invalid parameter value"); return false; } - std::vector res; + std::vector res = {}; ani_double userId = 0.0; ani_double filterLimit = 0.0; std::string deviceType; @@ -36,6 +36,10 @@ bool UnwarpNotificationSubscribeInfo(ani_env *env, ani_object value, Notificatio || res.empty()) { ANS_LOGE("UnWarpStringArrayOrUndefinedByProperty faild"); } + std::vector bundleNames = {}; + for (auto bundleName : res) { + bundleNames.emplace_back(GetResizeStr(bundleName, STR_MAX_SIZE)); + } if (ANI_OK != GetPropertyDouble(env, value, "userId", isUndefined, userId) || isUndefined == ANI_TRUE) { ANS_LOGE("GetDoubleOrUndefined faild"); } @@ -45,10 +49,10 @@ bool UnwarpNotificationSubscribeInfo(ani_env *env, ani_object value, Notificatio if (ANI_OK != GetPropertyDouble(env, value, "filterLimit", isUndefined, filterLimit) || isUndefined == ANI_TRUE) { ANS_LOGE("GetDoubleOrUndefined faild"); } - info.AddAppNames(res); + info.AddAppNames(bundleNames); info.AddAppUserId(static_cast(userId)); info.SetFilterType(static_cast(filterLimit)); - info.AddDeviceType(deviceType); + info.AddDeviceType(GetResizeStr(deviceType, STR_MAX_SIZE)); ANS_LOGD("userId %{public}d deviceType %{public}s filterLimit %{public}d", info.GetAppUserId(), info.GetDeviceType().c_str(), info.GetFilterType()); return true; diff --git a/frameworks/ets/ani/src/sts_user_input.cpp b/frameworks/ets/ani/src/sts_user_input.cpp index 1c56a0c66..5868a7045 100644 --- a/frameworks/ets/ani/src/sts_user_input.cpp +++ b/frameworks/ets/ani/src/sts_user_input.cpp @@ -33,7 +33,7 @@ ani_status UnwrapNotificationUserInput(ani_env *env, ani_object param, ANS_LOGE("GetPropertyString 'inputKey' faild"); return ANI_INVALID_ARGS; } - userInput = Notification::NotificationUserInput::Create(inputKey); + userInput = Notification::NotificationUserInput::Create(GetResizeStr(inputKey, STR_MAX_SIZE)); return status; } diff --git a/frameworks/ets/ani/src/subscribe/ani_remove.cpp b/frameworks/ets/ani/src/subscribe/ani_remove.cpp index 64e59665d..b73c1b744 100644 --- a/frameworks/ets/ani/src/subscribe/ani_remove.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_remove.cpp @@ -14,7 +14,6 @@ */ #include "ani_remove.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -59,7 +58,7 @@ void AniRemoveForBundle(ani_env *env, ani_object bundle, ani_object notification } int ret = NotificationHelper::RemoveNotification(option, key.id, key.label, reasonType); if (ret != ERR_OK) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); @@ -70,13 +69,14 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn { ANS_LOGD("AniRemoveForHashCode enter"); int32_t reasonType = -1; - std::string hashCodeStd; - if (ANI_OK != NotificationSts::GetStringByAniString(env, hashCode, hashCodeStd)) { + std::string tempStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, hashCode, tempStr)) { ANS_LOGE("hashCode is valid"); std::string msg = "hashCode is valid"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } + std::string hashCodeStd = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); std::string msg = "UnWarpReasonEnum failed"; @@ -92,7 +92,7 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn ANS_LOGD("hashCode: %{public}s, reasonType: %{public}d", hashCodeStd.c_str(), reasonType); int ret = NotificationHelper::RemoveNotification(hashCodeStd, reasonType); if (ret != ERR_OK) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); ANS_LOGD("StsRemoveForHashCode ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); @@ -102,14 +102,18 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reasonEnum) { ANS_LOGD("StsRemoveForHashCodes enter"); - std::vector hashCodesStd; + std::vector hashCodesTemp = {}; int32_t reasonType; - if (!NotificationSts::GetStringArrayByAniObj(env, hashCodes, hashCodesStd)) { + if (!NotificationSts::GetStringArrayByAniObj(env, hashCodes, hashCodesTemp)) { ANS_LOGE("hashCodes is valid"); std::string msg = "hashCodes is valid"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } + std::vector hashCodesStd = {}; + for (auto hashcode : hashCodesStd) { + hashCodesStd.emplace_back(NotificationSts::GetResizeStr(hashcode, NotificationSts::STR_MAX_SIZE)); + } if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); std::string msg = "UnWarpReasonEnum failed"; @@ -124,7 +128,7 @@ void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reason } int ret = NotificationHelper::RemoveNotifications(hashCodesStd, reasonType); if (ret != ERR_OK) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); ANS_LOGD("StsRemoveForHashCodes ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); @@ -136,7 +140,7 @@ void AniRemoveAll(ani_env *env) ANS_LOGD("removeAll enter"); int ret = NotificationHelper::RemoveNotifications(); if (ret != ERR_OK) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); ANS_LOGD("AniRemoveAll ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); @@ -155,7 +159,7 @@ void AniRemoveAllForBundle(ani_env *env, ani_object bundle) } int ret = NotificationHelper::RemoveAllNotifications(option); if (ret != ERR_OK) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); @@ -167,7 +171,7 @@ void AniRemoveAllForUserId(ani_env *env, ani_double userId) ANS_LOGD("AniRemoveAllForUserId enter"); int ret = NotificationHelper::RemoveNotifications(userId); if (ret != ERR_OK) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); diff --git a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp index f73b6c60b..aa4939ad7 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -16,11 +16,11 @@ #include #include -#include "inner_errors.h" #include "notification_helper.h" #include "ani_remove.h" #include "ans_log_wrapper.h" #include "sts_subscribe.h" +#include "sts_throw_erro.h" namespace OHOS { namespace NotificationSubScribeSts { @@ -75,7 +75,7 @@ ani_object AniDistributeOperation(ani_env *env, ani_string hashcode, ani_object callback->SetVm(vm); int32_t result = Notification::NotificationHelper::DistributeOperation(info, callback); ANS_LOGD("StsDistributeOperation ret %{public}d. ErrorToExternal %{public}d", - result, CJSystemapi::Notification::ErrorToExternal(result)); + result, NotificationSts::GetExternalCode(result)); if (result != ERR_OK || noWithOperationInfo) { callback->OnStsOperationCallback(env, result); } -- Gitee From b9bffe919bf1853faa543e27f3a013595f0e78e6 Mon Sep 17 00:00:00 2001 From: heguokai Date: Mon, 23 Jun 2025 09:51:48 +0800 Subject: [PATCH 2/4] modify Signed-off-by: heguokai --- frameworks/ets/ani/src/manager/ani_request_enable.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/ets/ani/src/manager/ani_request_enable.cpp b/frameworks/ets/ani/src/manager/ani_request_enable.cpp index a558c2990..da25535f0 100755 --- a/frameworks/ets/ani/src/manager/ani_request_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_request_enable.cpp @@ -52,11 +52,11 @@ bool GetEnableNotificationInfo(ani_env *env, ani_object content, std::shared_ptr void RequestEnableExecute(std::shared_ptr &info) { ANS_LOGD("enter"); + std::string deviceId {""}; sptr client = nullptr; - AnsDialogHostClient::CreateIfNullptr(client); - if (client == nullptr) { + if (!AnsDialogHostClient::CreateIfNullptr(client)) { ANS_LOGD("create client fail"); - info->errorCode = ERROR_INTERNAL_ERROR; + info->errorCode = ERR_ANS_DIALOG_IS_POPPING; return; } if (info->context != nullptr) { -- Gitee From 5c9e858cc3d09dd10529205417bc120bbf62be8e Mon Sep 17 00:00:00 2001 From: heguokai Date: Mon, 23 Jun 2025 09:59:40 +0800 Subject: [PATCH 3/4] modify Signed-off-by: heguokai --- frameworks/ets/ani/include/sts_throw_erro.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frameworks/ets/ani/include/sts_throw_erro.h b/frameworks/ets/ani/include/sts_throw_erro.h index 960b78fbf..4a99c1b6e 100644 --- a/frameworks/ets/ani/include/sts_throw_erro.h +++ b/frameworks/ets/ani/include/sts_throw_erro.h @@ -56,9 +56,7 @@ static const std::unordered_map ERROR_CODE_TO_MESSAGE { {ERROR_DISTRIBUTED_OPERATION_TIMEOUT, "Distributed operation timeout"}, }; -inline int32_t GetExternalCode(uint32_t errCode) -{ - static std::vector> errorsConvert = { +static const std::vector> ERRORS_CONVERT = { {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}, @@ -97,10 +95,13 @@ inline int32_t GetExternalCode(uint32_t errCode) {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}, - }; +}; + +inline int32_t GetExternalCode(uint32_t errCode) +{ int32_t ExternalCode = ERROR_INTERNAL_ERROR; - for (const auto &errorConvert : errorsConvert) { + for (const auto &errorConvert : ERRORS_CONVERT) { if (errCode == errorConvert.first) { ExternalCode = errorConvert.second; break; -- Gitee From 8af7bf3ef3982f548cbf39c6e8a918d7bd7be838 Mon Sep 17 00:00:00 2001 From: heguokai Date: Mon, 23 Jun 2025 11:51:21 +0800 Subject: [PATCH 4/4] codex Signed-off-by: heguokai --- frameworks/ets/ani/include/sts_throw_erro.h | 76 +++++++++---------- .../ani/src/manager/ani_request_enable.cpp | 6 +- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/frameworks/ets/ani/include/sts_throw_erro.h b/frameworks/ets/ani/include/sts_throw_erro.h index 4a99c1b6e..b24125a28 100644 --- a/frameworks/ets/ani/include/sts_throw_erro.h +++ b/frameworks/ets/ani/include/sts_throw_erro.h @@ -57,44 +57,44 @@ static const std::unordered_map ERROR_CODE_TO_MESSAGE { }; static const std::vector> ERRORS_CONVERT = { - {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_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}, + {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_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}, }; diff --git a/frameworks/ets/ani/src/manager/ani_request_enable.cpp b/frameworks/ets/ani/src/manager/ani_request_enable.cpp index da25535f0..2dab90030 100755 --- a/frameworks/ets/ani/src/manager/ani_request_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_request_enable.cpp @@ -52,13 +52,17 @@ bool GetEnableNotificationInfo(ani_env *env, ani_object content, std::shared_ptr void RequestEnableExecute(std::shared_ptr &info) { ANS_LOGD("enter"); - std::string deviceId {""}; sptr client = nullptr; if (!AnsDialogHostClient::CreateIfNullptr(client)) { ANS_LOGD("create client fail"); info->errorCode = ERR_ANS_DIALOG_IS_POPPING; return; } + if (client == nullptr) { + ANS_LOGD("client is nullptr"); + info->errorCode = ERROR_INTERNAL_ERROR; + return; + } if (info->context != nullptr) { ANS_LOGD("stage mode"); bool canPop = false; -- Gitee