diff --git a/frameworks/ets/ani/include/sts_notification_content.h b/frameworks/ets/ani/include/sts_notification_content.h index 34f73e559c17ea6c1945b7db82ff5acaa081b610..63e0b548bc5cfced546b2012d8e03e39bd6f5092 100644 --- a/frameworks/ets/ani/include/sts_notification_content.h +++ b/frameworks/ets/ani/include/sts_notification_content.h @@ -72,7 +72,7 @@ ani_status GetIconButtonArray(ani_env *env, ani_object param, const char *name, std::vector &res, const uint32_t maxLen); ani_object GetAniIconButtonArray(ani_env *env, const std::vector buttons); -void UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, +bool UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, NotificationLocalLiveViewButton &button); bool WarpNotificationLocalLiveViewButton(ani_env *env, const NotificationLocalLiveViewButton &button, ani_object &buttonObject); diff --git a/frameworks/ets/ani/include/sts_request.h b/frameworks/ets/ani/include/sts_request.h index 5a1416d3b7e497ec62837f2148eda58a4c8ee65c..36c3fe618f71c3c978607a05050fb5563bce1502 100644 --- a/frameworks/ets/ani/include/sts_request.h +++ b/frameworks/ets/ani/include/sts_request.h @@ -35,7 +35,7 @@ void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOption bool WarpNotificationUnifiedGroupInfo(ani_env* env, const std::shared_ptr &groupInfo, ani_object &groupInfoObject); -ani_status UnWarpNotificationRequest( +int32_t UnWarpNotificationRequest( ani_env *env, ani_object obj, std::shared_ptr ¬ificationRequest); bool WarpNotificationRequest( ani_env *env, const NotificationRequest *notificationRequest, ani_class &cls, ani_object &outAniObj); diff --git a/frameworks/ets/ani/src/manager/ani_publish.cpp b/frameworks/ets/ani/src/manager/ani_publish.cpp index 4913ca684e976c501f03f115ed84aa3ea536fe8f..e65653f944345135dccaa4db733d445b063f0e84 100644 --- a/frameworks/ets/ani/src/manager/ani_publish.cpp +++ b/frameworks/ets/ani/src/manager/ani_publish.cpp @@ -30,9 +30,11 @@ void AniPublish(ani_env *env, ani_object obj) { ANS_LOGD("AniPublish call"); std::shared_ptr notificationRequest = std::make_shared(); - if (NotificationSts::UnWarpNotificationRequest(env, obj, notificationRequest) != ANI_OK) { + int32_t ret = NotificationSts::UnWarpNotificationRequest(env, obj, notificationRequest); + if (ret != ERR_OK) { ANS_LOGE("AniPublish UnWarpNotificationRequest failed"); - NotificationSts::ThrowStsErroWithMsg(env, "AniPublish ERROR_INTERNAL_ERROR"); + int externalCode = NotificationSts::GetExternalCode(ret); + OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; } int returncode = NotificationHelper::PublishNotification(*notificationRequest); @@ -48,8 +50,10 @@ void AniPublishWithId(ani_env *env, ani_object obj, ani_int userId) ANS_LOGD("AniPublishWithId start"); //NotificationRequest request; std::shared_ptr notificationRequest = std::make_shared(); - if (NotificationSts::UnWarpNotificationRequest(env, obj, notificationRequest) != ANI_OK) { - NotificationSts::ThrowStsErroWithMsg(env, "AniPublishWithId ERROR_INTERNAL_ERROR"); + int32_t ret = NotificationSts::UnWarpNotificationRequest(env, obj, notificationRequest); + if (ret != ERR_OK) { + int externalCode = NotificationSts::GetExternalCode(ret); + OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; } notificationRequest->SetOwnerUserId(userId); @@ -72,9 +76,11 @@ void AniPublishAsBundle(ani_env *env, ani_object request, ani_string representat } std::shared_ptr notificationRequest = std::make_shared(); - if (NotificationSts::UnWarpNotificationRequest(env, request, notificationRequest) != ANI_OK) { + int32_t ret = NotificationSts::UnWarpNotificationRequest(env, request, notificationRequest); + if (ret != ERR_OK) { ANS_LOGE("AniPublishAsBundle failed"); - NotificationSts::ThrowStsErroWithMsg(env, "AniPublishAsBundle ERROR_INTERNAL_ERROR"); + int externalCode = NotificationSts::GetExternalCode(ret); + OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; } notificationRequest->SetOwnerUserId(userId); @@ -94,8 +100,10 @@ void AniPublishAsBundleWithBundleOption(ani_env *env, ani_object representativeB { ANS_LOGE("AniPublishAsBundleWithBundleOption enter"); std::shared_ptr notificationRequest = std::make_shared(); - if (NotificationSts::UnWarpNotificationRequest(env, request, notificationRequest) != ANI_OK) { - NotificationSts::ThrowStsErroWithMsg(env, "AniPublishAsBundleWithBundleOption ERROR_INTERNAL_ERROR"); + int32_t ret = NotificationSts::UnWarpNotificationRequest(env, request, notificationRequest); + if (ret != ERR_OK) { + int externalCode = NotificationSts::GetExternalCode(ret); + OHOS::NotificationSts::ThrowError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; } diff --git a/frameworks/ets/ani/src/sts_notification_content.cpp b/frameworks/ets/ani/src/sts_notification_content.cpp index 73524f10f5219b4c1f6135be3f19a673c76ebaef..cdbbebc40e966cd01c472c9fc125fa433fc869a0 100644 --- a/frameworks/ets/ani/src/sts_notification_content.cpp +++ b/frameworks/ets/ani/src/sts_notification_content.cpp @@ -356,13 +356,13 @@ ani_status GetIconButtonArray(ani_env *env, ani_object param, const char *name, return status; } -void UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, +bool UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, NotificationLocalLiveViewButton &button) { ANS_LOGD("UnWarpNotificationLocalLiveViewButton call"); if (env == nullptr || obj == nullptr) { ANS_LOGE("UnWarpNotificationLocalLiveViewButton failed, has nullptr"); - return; + return false; } std::vector names = {}; // names?: Array @@ -377,7 +377,11 @@ void UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, std::vector> icons = {}; if (ANI_OK == GetPixelMapArray(env, obj, "icons", icons, BUTTON_RESOURCE_SIZE)) { for (auto icon : icons) { - button.addSingleButtonIcon(icon); + if (icon != nullptr && static_cast(icon->GetByteCount()) <= MAX_ICON_SIZE) { + button.addSingleButtonIcon(icon); + } else { + return false; + } } } else { ANS_LOGD("UnWarpNotificationLocalLiveViewButton get icons failed."); @@ -393,6 +397,7 @@ void UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, ANS_LOGD("UnWarpNotificationLocalLiveViewButton get iconsResource failed."); } ANS_LOGD("UnWarpNotificationLocalLiveViewButton end"); + return true; } bool WarpNotificationLocalLiveViewButton( @@ -1059,7 +1064,9 @@ bool GetLocalLiveViewContentByOne(ani_env *env, ani_object obj, if (GetPropertyRef(env, obj, "button", isUndefined, buttonRef) == ANI_OK && isUndefined == ANI_FALSE && buttonRef != nullptr) { NotificationLocalLiveViewButton button; - UnWarpNotificationLocalLiveViewButton(env, static_cast(buttonRef), button); + if (!UnWarpNotificationLocalLiveViewButton(env, static_cast(buttonRef), button)) { + return false; + } localLiveViewContent->SetButton(button); localLiveViewContent->addFlag(NotificationLocalLiveViewContent::LiveViewContentInner::BUTTON); } else { diff --git a/frameworks/ets/ani/src/sts_request.cpp b/frameworks/ets/ani/src/sts_request.cpp index 11e1ffe3ddb34121576bae12528fda6560933414..854dfac85077a8c9e8f3ba1b243f38bbecc3017a 100644 --- a/frameworks/ets/ani/src/sts_request.cpp +++ b/frameworks/ets/ani/src/sts_request.cpp @@ -27,6 +27,7 @@ #include "ani_common_want.h" #include "sts_bundle_option.h" #include "sts_subscribe.h" +#include "ans_inner_errors.h" namespace OHOS { namespace NotificationSts { @@ -295,144 +296,149 @@ void GetNotificationRequestByNumber(ani_env *env, ani_object obj, ANS_LOGD("GetNotificationRequestByNumber end"); } -bool GetNotificationNormalContent(ani_env *env, ani_object obj, std::shared_ptr &request) +int32_t GetNotificationNormalContent(ani_env *env, ani_object obj, std::shared_ptr &request) { ANS_LOGD("GetNotificationNormalContent start"); if (env == nullptr || obj == nullptr || request == nullptr) { ANS_LOGE("GetNotificationNormalContent failed, has nullptr"); - return false; + return ERROR_INTERNAL_ERROR; } ani_boolean isUndefined = ANI_TRUE; ani_ref contentRef = {}; if (ANI_OK != GetPropertyRef(env, obj, "normal", isUndefined, contentRef) || isUndefined == ANI_TRUE || contentRef == nullptr) { ANS_LOGE("GetNotificationNormalContent get ref failed"); - return false; + return ERROR_INTERNAL_ERROR; } std::shared_ptr normalContent = std::make_shared(); UnWarpNotificationNormalContent(env, static_cast(contentRef), normalContent); request->SetContent(std::make_shared(normalContent)); ANS_LOGD("GetNotificationNormalContent end"); - return true; + return ERR_OK; } -bool GetNotificationLongTextContent(ani_env *env, ani_object obj, std::shared_ptr &request) +int32_t GetNotificationLongTextContent(ani_env *env, ani_object obj, std::shared_ptr &request) { ANS_LOGD("GetNotificationLongTextContent start"); if (env == nullptr || obj == nullptr || request == nullptr) { ANS_LOGE("GetNotificationLongTextContent failed, has nullptr"); - return false; + return ERROR_INTERNAL_ERROR; } ani_boolean isUndefined = ANI_TRUE; ani_ref contentRef = {}; if (ANI_OK != GetPropertyRef(env, obj, "longText", isUndefined, contentRef) || isUndefined == ANI_TRUE || contentRef == nullptr) { ANS_LOGE("GetNotificationLongTextContent get ref failed"); - return false; + return ERROR_INTERNAL_ERROR; } std::shared_ptr longTextContent = std::make_shared(); UnWarpNotificationLongTextContent(env, static_cast(contentRef), longTextContent); request->SetContent(std::make_shared(longTextContent)); ANS_LOGD("GetNotificationLongTextContent end"); - return true; + return ERR_OK; } -bool GetNotificationPictureContent(ani_env *env, ani_object obj, std::shared_ptr &request) +int32_t GetNotificationPictureContent(ani_env *env, ani_object obj, std::shared_ptr &request) { ANS_LOGD("GetNotificationPictureContent start"); if (env == nullptr || obj == nullptr || request == nullptr) { ANS_LOGE("GetNotificationPictureContent failed, has nullptr"); - return false; + return ERROR_INTERNAL_ERROR; } ani_boolean isUndefined = ANI_TRUE; ani_ref contentRef = {}; if (ANI_OK != GetPropertyRef(env, obj, "picture", isUndefined, contentRef) || isUndefined == ANI_TRUE || contentRef == nullptr) { ANS_LOGE("GetNotificationPictureContent get ref failed"); - return false; + return ERROR_INTERNAL_ERROR; } std::shared_ptr pictureContent = std::make_shared(); UnWarpNotificationPictureContent(env, static_cast(contentRef), pictureContent); request->SetContent(std::make_shared(pictureContent)); ANS_LOGD("GetNotificationPictureContent end"); - return true; + return ERR_OK; } -bool GetNotificationMultiLineContent(ani_env *env, ani_object obj, std::shared_ptr &request) +int32_t GetNotificationMultiLineContent(ani_env *env, ani_object obj, std::shared_ptr &request) { ANS_LOGD("GetNotificationMultiLineContent start"); if (env == nullptr || obj == nullptr || request == nullptr) { ANS_LOGE("GetNotificationMultiLineContent failed, has nullptr"); - return false; + return ERROR_INTERNAL_ERROR; } ani_boolean isUndefined = ANI_TRUE; ani_ref contentRef = {}; if (ANI_OK != GetPropertyRef(env, obj, "multiLine", isUndefined, contentRef) || isUndefined == ANI_TRUE || contentRef == nullptr) { ANS_LOGE("GetNotificationMultiLineContent get ref failed"); - return false; + return ERROR_INTERNAL_ERROR; } std::shared_ptr multiLineContent = std::make_shared(); UnWarpNotificationMultiLineContent(env, static_cast(contentRef), multiLineContent); request->SetContent(std::make_shared(multiLineContent)); ANS_LOGD("GetNotificationMultiLineContent end"); - return true; + return ERR_OK; } -bool GetNotificationLocalLiveViewContent(ani_env *env, ani_object obj, std::shared_ptr &request) +int32_t GetNotificationLocalLiveViewContent(ani_env *env, ani_object obj, std::shared_ptr &request) { ANS_LOGD("GetNotificationLocalLiveViewContent start"); if (env == nullptr || obj == nullptr || request == nullptr) { ANS_LOGE("GetNotificationLocalLiveViewContent failed, has nullptr"); - return false; + return ERROR_INTERNAL_ERROR; } ani_boolean isUndefined = ANI_TRUE; ani_ref contentRef = {}; if (ANI_OK != GetPropertyRef(env, obj, "systemLiveView", isUndefined, contentRef) || isUndefined == ANI_TRUE || contentRef == nullptr) { ANS_LOGE("GetNotificationLocalLiveViewContent get ref failed"); - return false; + return ERROR_INTERNAL_ERROR; } std::shared_ptr localLiveView = std::make_shared(); - UnWarpNotificationLocalLiveViewContent(env, static_cast(contentRef), localLiveView); + ani_status status = ANI_OK; + status = UnWarpNotificationLocalLiveViewContent(env, static_cast(contentRef), localLiveView); + if (status != ANI_OK) { + ANS_LOGE("UnWarpNotificationLocalLiveViewContent failed, status %{public}d", status); + return ERROR_PARAM_INVALID; + } request->SetContent(std::make_shared(localLiveView)); ANS_LOGD("GetNotificationLocalLiveViewContent end"); - return true; + return ERR_OK; } -bool GetNotificationLiveViewContent(ani_env *env, ani_object obj, std::shared_ptr &request) +int32_t GetNotificationLiveViewContent(ani_env *env, ani_object obj, std::shared_ptr &request) { ANS_LOGD("GetNotificationLiveViewContent start"); if (env == nullptr || obj == nullptr || request == nullptr) { ANS_LOGE("GetNotificationLiveViewContent failed, has nullptr"); - return false; + return ERROR_INTERNAL_ERROR; } ani_boolean isUndefined = ANI_TRUE; ani_ref contentRef = {}; if (ANI_OK != GetPropertyRef(env, obj, "liveView", isUndefined, contentRef) || isUndefined == ANI_TRUE || contentRef == nullptr) { ANS_LOGE("GetNotificationLiveViewContent get ref failed"); - return false; + return ERROR_INTERNAL_ERROR; } std::shared_ptr liveViewContent = std::make_shared(); UnWarpNotificationLiveViewContent(env, static_cast(contentRef), liveViewContent); request->SetContent(std::make_shared(liveViewContent)); ANS_LOGD("GetNotificationLiveViewContent end"); - return true; + return ERR_OK; } -bool GetNotificationContent(ani_env *env, ani_object obj, ContentType outType, +int32_t GetNotificationContent(ani_env *env, ani_object obj, ContentType outType, std::shared_ptr &request) { ANS_LOGD("GetNotificationContentWithType start"); if (env == nullptr || obj == nullptr || request == nullptr) { ANS_LOGE("GetNotificationContent failed, has nullptr"); - return false; + return ERROR_INTERNAL_ERROR; } ANS_LOGD("GetNotificationContent ContentType = %{public}d", static_cast(outType)); switch (outType) { @@ -454,16 +460,16 @@ bool GetNotificationContent(ani_env *env, ani_object obj, ContentType outType, ANS_LOGD("ContentType not find. type %{public}d", static_cast(outType)); break; } - return true; + return ERR_OK; } -ani_status GetNotificationContent(ani_env *env, ani_object obj, +int32_t GetNotificationContent(ani_env *env, ani_object obj, std::shared_ptr &request) { ANS_LOGD("GetNotificationContent start"); if (env == nullptr || obj == nullptr || request == nullptr) { ANS_LOGE("GetNotificationContent failed, has nullptr"); - return ANI_ERROR; + return ERROR_INTERNAL_ERROR; } ani_status status = ANI_OK; ani_boolean isUndefined = ANI_TRUE; @@ -471,26 +477,27 @@ ani_status GetNotificationContent(ani_env *env, ani_object obj, if (ANI_OK != (status = GetPropertyRef(env, obj, "content", isUndefined, notificationContentRef)) || isUndefined == ANI_TRUE) { ANS_LOGE("GetNotificationContent:get contentRef failed. status %{public}d", status); - return status; + return ERROR_INTERNAL_ERROR; } ani_ref contentTypeRef; if (ANI_OK != (status = GetPropertyRef(env, static_cast(notificationContentRef), "notificationContentType", isUndefined, contentTypeRef)) || isUndefined == ANI_TRUE || contentTypeRef == nullptr) { ANS_LOGE("GetNotificationContent:get notificationContentType failed. status %{public}d", status); - return status; + return ERROR_INTERNAL_ERROR; } ContentType type; if (!ContentTypeEtsToC(env, static_cast(contentTypeRef), type)) { ANS_LOGE("GetNotificationContent:ContentTypeEtsToC failed"); - return ANI_INVALID_ARGS; + return ERROR_INTERNAL_ERROR; } - if (!GetNotificationContent(env, static_cast(notificationContentRef), type, request)) { + int32_t ret = GetNotificationContent(env, static_cast(notificationContentRef), type, request); + if (ret != ERR_OK) { ANS_LOGE("GetNotificationContent:GetNotificationContent failed"); - return ANI_INVALID_ARGS; + return ret; } ANS_LOGD("GetNotificationContent end"); - return ANI_OK; + return ERR_OK; } void GetNotificationSlotType(ani_env *env, ani_object obj, std::shared_ptr &request) @@ -725,12 +732,12 @@ void GetNotificationBundleOption(ani_env *env, ani_object obj, } } -ani_status GetNotificationRequestByCustom(ani_env *env, ani_object obj, +int32_t GetNotificationRequestByCustom(ani_env *env, ani_object obj, std::shared_ptr ¬ificationRequest) { - ani_status status = GetNotificationContent(env, obj, notificationRequest); - if (status != ANI_OK) { - return ANI_INVALID_ARGS; + int32_t status = GetNotificationContent(env, obj, notificationRequest); + if (status != ERR_OK) { + return status; } GetNotificationSlotType(env, obj, notificationRequest); GetNotificationWantAgent(env, obj, notificationRequest); @@ -748,15 +755,15 @@ ani_status GetNotificationRequestByCustom(ani_env *env, ani_object obj, return status; } -ani_status UnWarpNotificationRequest(ani_env *env, ani_object obj, +int32_t UnWarpNotificationRequest(ani_env *env, ani_object obj, std::shared_ptr ¬ificationRequest) { ANS_LOGD("UnWarpNotificationRequest start"); if (env == nullptr || obj == nullptr) { ANS_LOGE("UnWarpNotificationRequest has nullptr"); - return ANI_ERROR; + return ERROR_INTERNAL_ERROR; } - ani_status status = ANI_ERROR; + int32_t status = ERR_OK; GetNotificationRequestByNumber(env, obj, notificationRequest); GetNotificationRequestByString(env, obj, notificationRequest); GetNotificationRequestByBoolean(env, obj, notificationRequest);