diff --git a/frameworks/ets/ani/include/sts_common.h b/frameworks/ets/ani/include/sts_common.h index 8bfe1dac6b764c903707eecd6a959dcac813a7ce..35f9d908fda7a293c91956d901a128f6e1d35e69 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 642ed3b429369ce88195eab551f1f03a6e42ac10..b24125a28294e00883fd0fb6db8f0c2be5acb82b 100644 --- a/frameworks/ets/ani/include/sts_throw_erro.h +++ b/frameworks/ets/ani/include/sts_throw_erro.h @@ -56,6 +56,61 @@ static const std::unordered_map ERROR_CODE_TO_MESSAGE { {ERROR_DISTRIBUTED_OPERATION_TIMEOUT, "Distributed operation timeout"}, }; +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}, +}; + + +inline int32_t GetExternalCode(uint32_t errCode) +{ + int32_t ExternalCode = ERROR_INTERNAL_ERROR; + for (const auto &errorConvert : ERRORS_CONVERT) { + 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 b288966f2b1e6d246b08f8f58f9fd5cecf87accf..88ce9d3bd290d46421190db29cb8acd9b7748efe 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 600558eff0052d46de28f884795021bc72bc3f8b..bc48b59e9000bc86eec919e5be469496df8fa25a 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 ed01c043a4b222fc50caf9a261a80602b443a487..d1a4d6532467523afd025d0a781576b82d849bb0 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 4beb262fdb52a70724074698553c58605e17a8d1..4d8ce628ae7c2c87254ad44db1e9c0d566e4fb67 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 7d09b4241994f9483982910f0c727640172de5e9..226e42790b886dfda5c50fef378e35337b258f57 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 71f94dd19d0b5ff4389d983e3687d5fa71b177a4..6d32f3bf5cbf62360220549e2cc09bace059d6d0 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 93c02e57210c57e14c623bc6b71a00719444e6a3..b22e684055e1c67ec738e9f3b934a84078fa123f 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 d3c4203c80ad7bc0013b2d147039627e8d24cc14..5d7179c5f6a2fff432bd06ab72215bcc5ffd66d0 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 ba521c2dc6bbd809d11a3c9f535f9c6e9513c2e4..aae5494da4fd58939bba0fade5bee772e6e0322d 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 8d4da2c647407f2a08a84dfccce730c0254e44fd..8bbab66b12e4e456c406441a4b04149e8c10aa92 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 962e28e777d05847e7d45c3f18981a5cf92df7d4..0fbb71964d47eeef5ce9cb51ce22f126d2d90552 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 ba7f1f4f8889111e2e523c072dcc0a5ee0c3222a..674d6b945551edd4d828e30efa128ed596eb2903 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 b916af19792811694c73495821becb706b13e46b..33d90ca765ef11f424bda7533493add5f56765ce 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 910cac486064a992279034197f35b2b263ac4eb1..2dab900305bb64cf7cab4fbde891d4fdb060c36f 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" @@ -54,9 +53,13 @@ void RequestEnableExecute(std::shared_ptr &info) { ANS_LOGD("enter"); sptr client = nullptr; - AnsDialogHostClient::CreateIfNullptr(client); - if (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; } @@ -86,7 +89,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 8790b0a3b2e5b837c91ddfae05963ce4bfceefea..d0d49fc533b04de66bacf17daf16536a09e92ef3 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 461787a311d9499426b499443acdceef19fd10f1..b79ef22eb7b6d2de6b1c42b1b9796dd50ebba75e 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 5a05c28f7a8507c08cd5fd2af4ad70e0fb1108a8..edf00e43c30ab56a5923732aac1b09f5660cc756 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 2cf67a9bfdc0d15f84516fed7a0abe1baab43ed9..edcf1645495710ae8de1fadee5032a3bfba7660f 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 31f5b6b53d4e6574e2fdd594774d542179648f96..54e5d0e470eb4a6843257efb2dd53d8902ba4165 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 b316a48594fa7bf8090eed59351f212da8b2b151..f85af200b84a6ffc29b7f2a864ba8f943e344028 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 b3aa635f9f0594c9b5abd4d43187bba6c0389a64..8e3b5764aa0424f39e0939ba380fde357f646a20 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 eb011638169efb21a1ab19def7c9c11a1879cf00..965ba2664c72a995e54b2e1387bcd7d9c323732e 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 ed3de90e93ef280828b63b2f1f0a5e857a91ef28..ed343a70577483391da6f524c4f08835dc21c234 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 844c3fc897cfb54454b656aef09ab893c8a509c7..88af70b02bbc72c1645d8a28f39728aa6b152bba 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 1fd46299f415fa9d47cbbe4504b9ae65a93c4b15..5d6797b4a22e45b6807c336c76b6ccbbfc08fc76 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 4b5c4a891b9274af120fa3b13f583db05de47ebb..9b1dd67a2bf394892a16df2d4362ac22b616e7df 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 1c56a0c669aadef44f1ae3488b6b6c9726e4ef38..5868a70459f7ac7fe9d6d524b30a8557559c165a 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 64e59665d76400e1b2e8a95d16d5f4fa6834a162..b73c1b74466929a950a6a2fe84bbe8ae674f4900 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 f73b6c60b49d95f64496b68dcfd8a872b2c52245..aa4939ad745e41b6babd00b9dbcd0dd250515e59 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); }