diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index f630d47e49280435910f67417f94a55ece784256..c688049dcab9c44e8d778bcbd8da9d48c5b16bfd 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -27,6 +27,7 @@ config("public_ans_core_config") { "${core_path}/include", "${interfaces_path}/innerkits/ans/native/include", "${interfaces_path}/innerkits/wantAgent/include", + "//foundation/multimedia/image_standard/interfaces/innerkits/include", "//utils/native/base/include", "//third_party/jsoncpp/include", ] @@ -74,6 +75,7 @@ ohos_shared_library("ans_core") { "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//foundation/multimedia/image_standard/interfaces/innerkits:image", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", ] diff --git a/frameworks/ans/core/common/include/ans_const_define.h b/frameworks/ans/core/common/include/ans_const_define.h index 61e08768ba92c39b3bc6bfecb367f86547408c9c..353899e52df69d5b48dfff7777d8ed701d1adf7c 100644 --- a/frameworks/ans/core/common/include/ans_const_define.h +++ b/frameworks/ans/core/common/include/ans_const_define.h @@ -25,6 +25,8 @@ constexpr uint32_t MAX_ACTIVE_NUM_PERAPP = 100; constexpr uint32_t MAX_ACTIVE_NUM_PERSECOND = 10; constexpr uint32_t MAX_SLOT_NUM = 5; constexpr uint32_t MAX_SLOT_GROUP_NUM = 4; +constexpr uint32_t MAX_ICON_SIZE = 50 * 1024; +constexpr uint32_t MAX_PICTURE_SIZE = 2 * 1024 * 1024; } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/core/common/include/ans_inner_errors.h b/frameworks/ans/core/common/include/ans_inner_errors.h index 1c59b864ad8e9365b5bf731ae54026e73b34274a..3552497d156d00306a96e074c4a3541276b4b90b 100644 --- a/frameworks/ans/core/common/include/ans_inner_errors.h +++ b/frameworks/ans/core/common/include/ans_inner_errors.h @@ -58,7 +58,8 @@ enum ErrorCode : uint32_t { ERR_ANS_NOTIFICATION_NOT_EXISTS, ERR_ANS_NOTIFICATION_IS_UNREMOVABLE, ERR_ANS_OVER_MAX_ACITVE_PERSECOND, - + ERR_ANS_ICON_OVER_SIZE, + ERR_ANS_PICTURE_OVER_SIZE, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED, ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST, ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST, diff --git a/frameworks/ans/core/include/ans_notification.h b/frameworks/ans/core/include/ans_notification.h index c21ec347b4fdf1a1514a69b33679cc104fe4e9eb..100bb3894fae9ed54f2bc9d9beac170b039d268c 100644 --- a/frameworks/ans/core/include/ans_notification.h +++ b/frameworks/ans/core/include/ans_notification.h @@ -618,6 +618,13 @@ private: */ bool CanPublishMediaContent(const NotificationRequest &request) const; + /** + * Check whether the picture size exceeds the limit + * + * @return the ErrCode. + */ + ErrCode CheckImageSize(const NotificationRequest &request); + private: std::mutex mutex_; sptr ansManagerProxy_; diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index 5bf4a26c39ca4479362a2a138fe56aaa75bf845d..fd203213c202c492ecdb789650e26e762fd990a8 100644 --- a/frameworks/ans/core/src/ans_notification.cpp +++ b/frameworks/ans/core/src/ans_notification.cpp @@ -14,6 +14,8 @@ */ #include "ans_notification.h" +#include +#include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" #include "iservice_registry.h" @@ -188,6 +190,12 @@ ErrCode AnsNotification::PublishNotification(const std::string &label, const Not return ERR_ANS_INVALID_PARAM; } + ErrCode checkErr = CheckImageSize(request); + if (checkErr != ERR_OK) { + ANS_LOGE("The size of one picture exceeds the limit"); + return checkErr; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -214,6 +222,12 @@ ErrCode AnsNotification::PublishNotification(const NotificationRequest &request, return ERR_ANS_INVALID_PARAM; } + ErrCode checkErr = CheckImageSize(request); + if (checkErr != ERR_OK) { + ANS_LOGE("The size of one picture exceeds the limit"); + return checkErr; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -328,6 +342,12 @@ ErrCode AnsNotification::PublishNotificationAsBundle( return ERR_ANS_INVALID_PARAM; } + ErrCode checkErr = CheckImageSize(request); + if (checkErr != ERR_OK) { + ANS_LOGE("The size of one picture exceeds the limit"); + return checkErr; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -777,5 +797,91 @@ bool AnsNotification::CanPublishMediaContent(const NotificationRequest &request) return true; } + +ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) +{ + auto littleIcon = request.GetLittleIcon(); + if (littleIcon && (static_cast(littleIcon->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of little icon exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto bigIcon = request.GetBigIcon(); + if (bigIcon && (static_cast(bigIcon->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of big icon exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto content = request.GetContent(); + if (content) { + auto basicContent = request.GetContent()->GetNotificationContent(); + if (basicContent) { + auto contentType = request.GetNotificationType(); + switch (contentType) { + case NotificationContent::Type::CONVERSATION: { + auto conversationalContent = std::static_pointer_cast(basicContent); + + auto picture = conversationalContent->GetMessageUser().GetPixelMap(); + if (picture && (static_cast(picture->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in conversationalContent exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto messages = conversationalContent->GetAllConversationalMessages(); + for (auto &msg : messages) { + if (!msg) { + continue; + } + + auto img = msg->GetSender().GetPixelMap(); + if (img && (static_cast(img->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in conversationalMessage exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + } + } break; + case NotificationContent::Type::PICTURE: { + auto pictureContent = std::static_pointer_cast(basicContent); + + auto bigPicture = pictureContent->GetBigPicture(); + if (bigPicture && (static_cast(bigPicture->GetByteCount()) > MAX_PICTURE_SIZE)) { + ANS_LOGE("The size of big picture exceeds limit"); + return ERR_ANS_PICTURE_OVER_SIZE; + } + } break; + default: + break; + } + } + } + + auto buttons = request.GetActionButtons(); + for (auto &btn : buttons) { + if (!btn) { + continue; + } + + auto icon = btn->GetIcon(); + if (icon && (static_cast(icon->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of icon in actionButton exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + } + + auto users = request.GetMessageUsers(); + for (auto &user : users) { + if (!user) { + continue; + } + + auto icon = user->GetPixelMap(); + if (icon && (static_cast(icon->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in messageUser exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + } + + return ERR_OK; +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/native/BUILD.gn b/frameworks/ans/native/BUILD.gn index e8c5dae3354643ff8289bbf258b2d5f4daaf9271..96d8c983a9ad8c5eefbcbd953b0421409b1d00cf 100755 --- a/frameworks/ans/native/BUILD.gn +++ b/frameworks/ans/native/BUILD.gn @@ -33,6 +33,7 @@ ohos_shared_library("ans_innerkits") { include_dirs = [ "${interfaces_path}/ans/native/include", "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/multimedia/image_standard/interfaces/innerkits/include", "//utils/system/safwk/native/include", "//third_party/jsoncpp/include", ] @@ -75,6 +76,7 @@ ohos_shared_library("ans_innerkits") { "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//foundation/multimedia/image_standard/interfaces/innerkits:image", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", ] diff --git a/frameworks/ans/native/src/message_user.cpp b/frameworks/ans/native/src/message_user.cpp index 161d723871ddd8f38d0ddfbbc6621e41502ebc79..4e1632abd2381b21bd69c6524046d82c86edd326 100644 --- a/frameworks/ans/native/src/message_user.cpp +++ b/frameworks/ans/native/src/message_user.cpp @@ -14,6 +14,7 @@ */ #include "message_user.h" +#include "ans_log_wrapper.h" namespace OHOS { namespace Notification { @@ -45,12 +46,12 @@ std::string MessageUser::GetName() const return name_; } -void MessageUser::SetPixelMap(const std::shared_ptr &pixelMap) +void MessageUser::SetPixelMap(const std::shared_ptr &pixelMap) { pixelMap_ = pixelMap; } -const std::shared_ptr MessageUser::GetPixelMap() const +const std::shared_ptr MessageUser::GetPixelMap() const { return pixelMap_; } @@ -98,30 +99,50 @@ std::string MessageUser::Dump() const bool MessageUser::Marshalling(Parcel &parcel) const { if (!parcel.WriteString(key_)) { + ANS_LOGE("Failed to write key"); return false; } if (!parcel.WriteString(name_)) { + ANS_LOGE("Failed to write name"); return false; } if (!parcel.WriteBool(isMachine_)) { + ANS_LOGE("Failed to write isMachine"); return false; } if (!parcel.WriteBool(isUserImportant_)) { + ANS_LOGE("Failed to write isUserImportant"); return false; } if (uri_.ToString().empty()) { if (!parcel.WriteInt32(VALUE_NULL)) { + ANS_LOGE("Failed to write VALUE_NULL"); return false; } } else { if (!parcel.WriteInt32(VALUE_OBJECT)) { + ANS_LOGE("Failed to write VALUE_OBJECT"); return false; } if (!parcel.WriteString((uri_.ToString()))) { + ANS_LOGE("Failed to write uri"); + return false; + } + } + + bool valid = pixelMap_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether pixelMap is null"); + return false; + } + + if (valid) { + if (!parcel.WriteParcelable(pixelMap_.get())) { + ANS_LOGE("Failed to write pixelMap"); return false; } } @@ -138,6 +159,7 @@ bool MessageUser::ReadFromParcel(Parcel &parcel) int empty = VALUE_NULL; if (!parcel.ReadInt32(empty)) { + ANS_LOGE("Failed to read VALUE"); return false; } @@ -145,6 +167,15 @@ bool MessageUser::ReadFromParcel(Parcel &parcel) uri_ = Uri((parcel.ReadString())); } + bool valid = parcel.ReadBool(); + if (valid) { + pixelMap_ = std::shared_ptr(parcel.ReadParcelable()); + if (!pixelMap_) { + ANS_LOGE("Failed to read pixelMap"); + return false; + } + } + return true; } diff --git a/frameworks/ans/native/src/notification_action_button.cpp b/frameworks/ans/native/src/notification_action_button.cpp index 62cf80e18d3442cac9b10053f06aaca0ac2ad1ee..04cd48448963832303da0b6428331dcaaba18560 100644 --- a/frameworks/ans/native/src/notification_action_button.cpp +++ b/frameworks/ans/native/src/notification_action_button.cpp @@ -20,7 +20,7 @@ namespace OHOS { namespace Notification { -std::shared_ptr NotificationActionButton::Create(const std::shared_ptr &icon, +std::shared_ptr NotificationActionButton::Create(const std::shared_ptr &icon, const std::string &title, const std::shared_ptr &wantAgent, const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, @@ -79,7 +79,7 @@ std::shared_ptr NotificationActionButton::Create( actionButton->IsContextDependent()); } -NotificationActionButton::NotificationActionButton(const std::shared_ptr &icon, const std::string &title, +NotificationActionButton::NotificationActionButton(const std::shared_ptr &icon, const std::string &title, const std::shared_ptr &wantAgent, const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, @@ -95,7 +95,7 @@ NotificationActionButton::NotificationActionButton(const std::shared_ptr NotificationActionButton::GetIcon() const +const std::shared_ptr NotificationActionButton::GetIcon() const { return icon_; } @@ -217,18 +217,18 @@ bool NotificationActionButton::Marshalling(Parcel &parcel) const bool valid{false}; - // valid = icon_ ? true : false; - // if (!parcel.WriteBool(valid)) { - // ANS_LOGE("Failed to write the flag which indicate whether icon is null"); - // return false; - // } + valid = icon_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether icon is null"); + return false; + } - // if (valid) { - // if (!parcel.WriteParcelable(icon_.get())) { - // ANS_LOGE("Failed to write icon"); - // return false; - // } - // } + if (valid) { + if (!parcel.WriteParcelable(icon_.get())) { + ANS_LOGE("Failed to write icon"); + return false; + } + } valid = wantAgent_ ? true : false; if (!parcel.WriteBool(valid)) { @@ -305,14 +305,14 @@ bool NotificationActionButton::ReadFromParcel(Parcel &parcel) bool valid{false}; - // valid = parcel.ReadBool(); - // if (valid) { - // icon_ = std::shared_ptr(parcel.ReadParcelable()); - // if (!icon_) { - // ANS_LOGE("Failed to read icon"); - // return false; - // } - // } + valid = parcel.ReadBool(); + if (valid) { + icon_ = std::shared_ptr(parcel.ReadParcelable()); + if (!icon_) { + ANS_LOGE("Failed to read icon"); + return false; + } + } valid = parcel.ReadBool(); if (valid) { diff --git a/frameworks/ans/native/src/notification_picture_content.cpp b/frameworks/ans/native/src/notification_picture_content.cpp index 385e3c467ecb0268dcaab06a9903406db2937a1d..9138938cb6b1ff178b5f851ef685f2acaa9e3002 100644 --- a/frameworks/ans/native/src/notification_picture_content.cpp +++ b/frameworks/ans/native/src/notification_picture_content.cpp @@ -38,12 +38,12 @@ std::string NotificationPictureContent::GetBriefText() const return briefText_; } -void NotificationPictureContent::SetBigPicture(const std::shared_ptr &bigPicture) +void NotificationPictureContent::SetBigPicture(const std::shared_ptr &bigPicture) { bigPicture_ = bigPicture; } -const std::shared_ptr NotificationPictureContent::GetBigPicture() const +const std::shared_ptr NotificationPictureContent::GetBigPicture() const { return bigPicture_; } @@ -71,18 +71,18 @@ bool NotificationPictureContent::Marshalling(Parcel &parcel) const return false; } - // auto valid = bigPicture_ ? true : false; - // if (!parcel.WriteBool(valid)) { - // ANS_LOGE("Failed to write the flag which indicate whether bigPicture is null"); - // return false; - // } + auto valid = bigPicture_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether bigPicture is null"); + return false; + } - // if (valid) { - // if (!parcel.WriteParcelable(bigPicture_.get())) { - // ANS_LOGE("Failed to write bigPicture"); - // return false; - // } - // } + if (valid) { + if (!parcel.WriteParcelable(bigPicture_.get())) { + ANS_LOGE("Failed to write bigPicture"); + return false; + } + } return true; } @@ -115,14 +115,14 @@ bool NotificationPictureContent::ReadFromParcel(Parcel &parcel) return false; } - // auto valid = parcel.ReadBool(); - // if (valid) { - // bigPicture_ = std::shared_ptr(parcel.ReadParcelable()); - // if (!bigPicture_) { - // ANS_LOGE("Failed to read bigPicture"); - // return false; - // } - // } + auto valid = parcel.ReadBool(); + if (valid) { + bigPicture_ = std::shared_ptr(parcel.ReadParcelable()); + if (!bigPicture_) { + ANS_LOGE("Failed to read bigPicture"); + return false; + } + } return true; } diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index 809de5494c5077d8db051ea0d4dce56cdd165065..02c7e1e4cf0defffcc243703cbf49de3cadcd2c5 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -344,22 +344,22 @@ int64_t NotificationRequest::GetAutoDeletedTime() const return autoDeletedTime_; } -void NotificationRequest::SetLittleIcon(const std::shared_ptr &littleIcon) +void NotificationRequest::SetLittleIcon(const std::shared_ptr &littleIcon) { littleIcon_ = littleIcon; } -const std::shared_ptr NotificationRequest::GetLittleIcon() const +const std::shared_ptr NotificationRequest::GetLittleIcon() const { return littleIcon_; } -void NotificationRequest::SetBigIcon(const std::shared_ptr &bigIcon) +void NotificationRequest::SetBigIcon(const std::shared_ptr &bigIcon) { bigIcon_ = bigIcon; } -const std::shared_ptr NotificationRequest::GetBigIcon() const +const std::shared_ptr NotificationRequest::GetBigIcon() const { return bigIcon_; } @@ -1002,31 +1002,31 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const } } - // valid = littleIcon_ ? true : false; - // if (!parcel.WriteBool(valid)) { - // ANS_LOGE("Failed to write the flag which indicate whether littleIcon is null"); - // return false; - // } - - // if (valid) { - // if (!parcel.WriteParcelable(littleIcon_.get())) { - // ANS_LOGE("Failed to write littleIcon"); - // return false; - // } - // } - - // valid = bigIcon_ ? true : false; - // if (!parcel.WriteBool(valid)) { - // ANS_LOGE("Failed to write the flag which indicate whether bigIcon is null"); - // return false; - // } - - // if (valid) { - // if (!parcel.WriteParcelable(bigIcon_.get())) { - // ANS_LOGE("Failed to write bigIcon"); - // return false; - // } - // } + valid = littleIcon_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether littleIcon is null"); + return false; + } + + if (valid) { + if (!parcel.WriteParcelable(littleIcon_.get())) { + ANS_LOGE("Failed to write littleIcon"); + return false; + } + } + + valid = bigIcon_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether bigIcon is null"); + return false; + } + + if (valid) { + if (!parcel.WriteParcelable(bigIcon_.get())) { + ANS_LOGE("Failed to write bigIcon"); + return false; + } + } valid = notificationContent_ ? true : false; if (!parcel.WriteBool(valid)) { @@ -1215,23 +1215,23 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) } } - // valid = parcel.ReadBool(); - // if (valid) { - // littleIcon_ = std::shared_ptr(parcel.ReadParcelable()); - // if (!littleIcon_) { - // ANS_LOGE("Failed to read littleIcon"); - // return false; - // } - // } - - // valid = parcel.ReadBool(); - // if (valid) { - // bigIcon_ = std::shared_ptr(parcel.ReadParcelable()); - // if (!bigIcon_) { - // ANS_LOGE("Failed to read bigIcon"); - // return false; - // } - // } + valid = parcel.ReadBool(); + if (valid) { + littleIcon_ = std::shared_ptr(parcel.ReadParcelable()); + if (!littleIcon_) { + ANS_LOGE("Failed to read littleIcon"); + return false; + } + } + + valid = parcel.ReadBool(); + if (valid) { + bigIcon_ = std::shared_ptr(parcel.ReadParcelable()); + if (!bigIcon_) { + ANS_LOGE("Failed to read bigIcon"); + return false; + } + } valid = parcel.ReadBool(); if (valid) { diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index db73e3179276ada1f1889ec346d66a57da579c88..e50678ec1ceb5d38b7b84ec7b4f42b8d123d94ba 100755 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -102,6 +102,7 @@ ohos_moduletest("ans_fw_module_test") { "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/image_standard/interfaces/innerkits:image", "//third_party/googletest:gtest_main", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", @@ -154,6 +155,7 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata/include", "//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/src", "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/adapter/include/dfx", + "//foundation/multimedia/image_standard/interfaces/innerkits/include", "//developtools/bytrace_standard/interfaces/innerkits/native/include", ] @@ -182,6 +184,7 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/image_standard/interfaces/innerkits:image", "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index 7a35c46c2a3fa607abeb1a99218b17ec423d83f8..bfb5639cfdae3bc0a5104e311230d985d10b94e7 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -36,6 +36,8 @@ #include "system_ability_definition.h" using namespace testing::ext; +using namespace OHOS::Media; + namespace OHOS { namespace Notification { @@ -54,7 +56,7 @@ enum class SubscriberEventType { class SubscriberEvent { public: - ~SubscriberEvent() + virtual ~SubscriberEvent() {} SubscriberEventType GetType() { @@ -1064,5 +1066,119 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishVibrationNotification_00100, Function SleepForFC(); } +inline std::shared_ptr MakePixelMap(int32_t width, int32_t height) +{ + const int32_t PIXEL_BYTES = 4; + std::shared_ptr pixelMap = std::make_shared(); + ImageInfo info; + info.size.width = width; + info.size.height = height; + info.pixelFormat = PixelFormat::ARGB_8888; + info.colorSpace = ColorSpace::SRGB; + pixelMap->SetImageInfo(info); + int32_t rowDataSize = width * PIXEL_BYTES; + uint32_t bufferSize = rowDataSize * height; + void *buffer = malloc(bufferSize); + EXPECT_NE(buffer, nullptr); + pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr); + return pixelMap; +} + +/** + * + * @tc.number : ANS_FW_MT_PublishNotificationWithPixelMap_00100 + * @tc.name : + * @tc.desc : Publish a notification with pixelMap. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishNotificationWithPixelMap_00100, Function | MediumTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 400; + const int BIG_PICTURE_HEIGHT = 300; + const int ICON_SIZE = 36; + + NotificationRequest req; + req.SetSlotType(NotificationConstant::SlotType::OTHER); + req.SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req.SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetBigIcon(bigIcon); + EXPECT_EQ(NotificationHelper::PublishNotification(req), ERR_OK); +} + +/** + * + * @tc.number : ANS_FW_MT_PublishNotificationWithPixelMap_00200 + * @tc.name : + * @tc.desc : Publish a notification with oversize pixelMap. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishNotificationWithPixelMap_00200, Function | MediumTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 1024; + const int BIG_PICTURE_HEIGHT = 1024; + const int ICON_SIZE = 36; + + NotificationRequest req; + req.SetSlotType(NotificationConstant::SlotType::OTHER); + req.SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req.SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetBigIcon(bigIcon); + EXPECT_EQ(NotificationHelper::PublishNotification(req), ERR_ANS_PICTURE_OVER_SIZE); +} + +/** + * + * @tc.number : ANS_FW_MT_PublishNotificationWithPixelMap_00300 + * @tc.name : + * @tc.desc : Publish a notification with oversize pixelMap. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishNotificationWithPixelMap_00300, Function | MediumTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 400; + const int BIG_PICTURE_HEIGHT = 300; + const int ICON_SIZE = 256; + + NotificationRequest req; + req.SetSlotType(NotificationConstant::SlotType::OTHER); + req.SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req.SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetBigIcon(bigIcon); + EXPECT_EQ(NotificationHelper::PublishNotification(req), ERR_ANS_ICON_OVER_SIZE); +} + } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp index fbf6f3116f2490dc5fb5901a24aeea65c47bc785..85404dd1ba96fcdb2650f370bc1efcc8cb55085b 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -57,6 +57,10 @@ const int32_t CASE_FOURTEEN = 14; const int32_t CASE_FIFTEEN = 15; const int32_t CASE_SIXTEEN = 16; const int32_t CALLING_UID = 9999; + +const int32_t PIXEL_MAP_TEST_WIDTH = 1024; +const int32_t PIXEL_MAP_TEST_HEIGHT = 1024; + std::mutex g_subscribe_mtx; std::mutex g_consumed_mtx; std::mutex g_unsubscribe_mtx; @@ -163,8 +167,8 @@ private: } } EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType()); - for (auto it : notificationRequest.GetNotificationUserInputHistory()) { - EXPECT_EQ("style", it); + for (auto str : notificationRequest.GetNotificationUserInputHistory()) { + EXPECT_EQ("style", str); } EXPECT_EQ("bundleName", notificationRequest.GetOwnerBundleName()); EXPECT_EQ("bundleName", notificationRequest.GetCreatorBundleName()); @@ -173,18 +177,31 @@ private: if (NotificationRequestPtr != nullptr) { EXPECT_EQ("ANS_Interface_MT_Publish_00100_REQUEST", NotificationRequestPtr->GetLabel()); } + + // pixelmap + auto littleIcon = notificationRequest.GetLittleIcon(); + Media::ImageInfo outImageInfo; + littleIcon->GetImageInfo(outImageInfo); + GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100 :: littleIcon :: width : " << outImageInfo.size.width; + GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100 :: littleIcon :: height : " << outImageInfo.size.height; + + EXPECT_EQ(outImageInfo.size.width, PIXEL_MAP_TEST_WIDTH); + EXPECT_EQ(outImageInfo.size.height, PIXEL_MAP_TEST_HEIGHT); + EXPECT_EQ(outImageInfo.pixelFormat, Media::PixelFormat::ALPHA_8); + EXPECT_EQ(outImageInfo.colorSpace, Media::ColorSpace::SRGB); + EXPECT_EQ(nullptr, notificationRequest.GetBigIcon()); EXPECT_EQ(nullptr, notificationRequest.GetLittleIcon()); EXPECT_EQ(nullptr, notificationRequest.GetLittleIcon()); std::vector> messageUser = notificationRequest.GetMessageUsers(); - for (auto it : messageUser) { - if (it != nullptr) { - EXPECT_EQ("ANS_Interface_MT_Publish_00100_Message_User", it->GetName()); - EXPECT_EQ("key", it->GetKey()); - EXPECT_EQ(nullptr, it->GetPixelMap()); - EXPECT_EQ(Uri("."), it->GetUri()); - EXPECT_EQ(false, it->IsMachine()); - EXPECT_EQ(false, it->IsUserImportant()); + for (auto user : messageUser) { + if (user != nullptr) { + EXPECT_EQ("ANS_Interface_MT_Publish_00100_Message_User", user->GetName()); + EXPECT_EQ("key", user->GetKey()); + EXPECT_EQ(nullptr, user->GetPixelMap()); + EXPECT_EQ(Uri("."), user->GetUri()); + EXPECT_EQ(false, user->IsMachine()); + EXPECT_EQ(false, user->IsUserImportant()); } } } @@ -352,6 +369,11 @@ class CompletedCallbackTest : public WantAgent::CompletedCallback { void OnSendFinished( const AAFwk::Want &want, int resultCode, const std::string &resultData, const AAFwk::WantParams &resultExtras) { + (void)want; + (void)resultCode; + (void)resultData; + (void)resultExtras; + g_send_finished_mtx.unlock(); OnWantReceived = true; } @@ -480,8 +502,22 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00100, Function std::shared_ptr requestPtr = std::make_shared(); requestPtr->SetLabel("ANS_Interface_MT_Publish_00100_REQUEST"); req.SetPublicNotification(requestPtr); - req.SetBigIcon(nullptr); - req.SetLittleIcon(nullptr); + + // pixelmap + auto pixelMap = std::make_shared(); + Media::ImageInfo imageInfo; + imageInfo.size.width = PIXEL_MAP_TEST_WIDTH; + imageInfo.size.height = PIXEL_MAP_TEST_HEIGHT; + imageInfo.pixelFormat = Media::PixelFormat::ALPHA_8; + imageInfo.colorSpace = Media::ColorSpace::SRGB; + pixelMap->SetImageInfo(imageInfo); + int32_t rowDataSize = (PIXEL_MAP_TEST_WIDTH + 3) / 4 * 4; + uint32_t bufferSize = rowDataSize * PIXEL_MAP_TEST_HEIGHT; + void *buffer = malloc(bufferSize); + pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, Media::AllocatorType::HEAP_ALLOC, nullptr); + + req.SetBigIcon(pixelMap); + req.SetLittleIcon(pixelMap); std::shared_ptr messageUserPtr = std::make_shared(); messageUserPtr->SetName("ANS_Interface_MT_Publish_00100_Message_User"); messageUserPtr->SetKey("key"); diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp index 0433b29673e0c8d04636615ac1ee4321160c0996..e7ced933603477f836afef13d7cccccf66b00ee6 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp @@ -118,7 +118,6 @@ HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_NotificationSlot_00100, Fu */ HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_NotificationSlot_00200, Function | MediumTest | Level1) { - // bundleObject->MockSetIsSystemApp(false); NotificationSlot slot(NotificationConstant::SERVICE_REMINDER); slot.SetEnableLight(true); slot.SetDescription("description"); diff --git a/interfaces/innerkits/ans/native/include/message_user.h b/interfaces/innerkits/ans/native/include/message_user.h index 0ceb44f490471d3f6c3a0268206ac2d6c5330830..0e7717dda9b1ea5bee41c7a1e13de26a4569223a 100644 --- a/interfaces/innerkits/ans/native/include/message_user.h +++ b/interfaces/innerkits/ans/native/include/message_user.h @@ -16,13 +16,12 @@ #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_MESSAGE_USER_H #include - +#include "pixel_map.h" #include "parcel.h" #include "uri.h" namespace OHOS { namespace Notification { -class PixelMap; class MessageUser final : public Parcelable { public: /** @@ -67,14 +66,14 @@ public: * Sets the pixel map of this MessageUser. * @param pixelMap Indicates the pixel map to set. */ - void SetPixelMap(const std::shared_ptr &pixelMap); + void SetPixelMap(const std::shared_ptr &pixelMap); /** * Obtains the pixel map of this MessageUser. * * @return Returns the pixel map of this MessageUser. */ - const std::shared_ptr GetPixelMap() const; + const std::shared_ptr GetPixelMap() const; /** * Sets the URI of this MessageUser. @@ -153,7 +152,7 @@ private: private: std::string key_{}; std::string name_{}; - std::shared_ptr pixelMap_{nullptr}; + std::shared_ptr pixelMap_{nullptr}; Uri uri_; bool isMachine_{false}; bool isUserImportant_{false}; diff --git a/interfaces/innerkits/ans/native/include/notification_action_button.h b/interfaces/innerkits/ans/native/include/notification_action_button.h index 42f8af582eb30d87f0e372a0850d697104505617..843b87753b2ee636efd0efd0d740ec5e40ff6a38 100644 --- a/interfaces/innerkits/ans/native/include/notification_action_button.h +++ b/interfaces/innerkits/ans/native/include/notification_action_button.h @@ -23,12 +23,11 @@ #include "notification_user_input.h" #include "want_agent.h" #include "pac_map.h" +#include "pixel_map.h" #include "parcel.h" namespace OHOS { namespace Notification { -class PixelMap; - class NotificationActionButton : public Parcelable { public: /** @@ -47,7 +46,7 @@ public: * @return the shared_ptr object owns the created NotificationActionButton object otherwise return empty object if * isContextual is true but icon or wantAgent is empty. */ - static std::shared_ptr Create(const std::shared_ptr &icon, + static std::shared_ptr Create(const std::shared_ptr &icon, const std::string &title, const std::shared_ptr &wantAgent, const std::shared_ptr &extras = {}, NotificationConstant::SemanticActionButton semanticActionButton = @@ -74,7 +73,7 @@ public: * Obtains the icon of this NotificationActionButton. * @return the icon of this NotificationActionButton. */ - const std::shared_ptr GetIcon() const; + const std::shared_ptr GetIcon() const; /** * Obtains the title of this NotificationActionButton. @@ -208,7 +207,7 @@ private: * @param userInputs Indicates the NotificationUserInput object to add. * @param isContextual Indicates whether this NotificationActionButton is a contextual action. */ - NotificationActionButton(const std::shared_ptr &icon, const std::string &title, + NotificationActionButton(const std::shared_ptr &icon, const std::string &title, const std::shared_ptr &wantAgent, const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, @@ -221,7 +220,7 @@ private: bool ReadFromParcel(Parcel &parcel); private: - std::shared_ptr icon_{}; + std::shared_ptr icon_{}; std::string title_{}; std::shared_ptr wantAgent_{}; std::shared_ptr extras_{}; diff --git a/interfaces/innerkits/ans/native/include/notification_picture_content.h b/interfaces/innerkits/ans/native/include/notification_picture_content.h index 1fdd92f7e5ec9576dfc7d56b04095f5ea90dc082..c4abb2f4573e6b477dec75aa262ce151067b6a4f 100644 --- a/interfaces/innerkits/ans/native/include/notification_picture_content.h +++ b/interfaces/innerkits/ans/native/include/notification_picture_content.h @@ -19,12 +19,11 @@ #include #include #include "notification_basic_content.h" +#include "pixel_map.h" #include "parcel.h" namespace OHOS { namespace Notification { -class PixelMap; - class NotificationPictureContent : public NotificationBasicContent { public: /** @@ -71,13 +70,13 @@ public: * Sets the picture to be included in a notification. * @param bigPicture Indicates the PixelMap of the picture to be included. */ - void SetBigPicture(const std::shared_ptr &bigPicture); + void SetBigPicture(const std::shared_ptr &bigPicture); /** * Obtains the PixelMap of the picture specified by calling the setBigPicture(PixelMap) method. * @return the PixelMap of the picture included in the notification. */ - const std::shared_ptr GetBigPicture() const; + const std::shared_ptr GetBigPicture() const; /** * Returns a string representation of the object. @@ -107,7 +106,7 @@ protected: private: std::string expandedTitle_{}; std::string briefText_{}; - std::shared_ptr bigPicture_{}; + std::shared_ptr bigPicture_{}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_request.h b/interfaces/innerkits/ans/native/include/notification_request.h index 0f52f5bf68cf1d885ee877df558cd1c12b1c8792..a879f32d8032da13254fc6d49dde313d5a1fb487 100644 --- a/interfaces/innerkits/ans/native/include/notification_request.h +++ b/interfaces/innerkits/ans/native/include/notification_request.h @@ -25,12 +25,11 @@ #include "want_agent.h" #include "context.h" #include "ohos/aafwk/content/want_params.h" +#include "pixel_map.h" #include "parcel.h" namespace OHOS { namespace Notification { -class PixelMap; - class NotificationRequest : public Parcelable { public: enum class BadgeStyle { @@ -402,25 +401,25 @@ public: * Sets the little icon of the notification. * @param littleIcon Indicates the icon of the notification. */ - void SetLittleIcon(const std::shared_ptr &littleIcon); + void SetLittleIcon(const std::shared_ptr &littleIcon); /** * Obtains the icon of the notification. * @return the notification icon. */ - const std::shared_ptr GetLittleIcon() const; + const std::shared_ptr GetLittleIcon() const; /** * Sets the large icon of this notification, which is usually displayed on the right of the notification. * @param bigIcon Indicates the large icon to set. It must be a PixelMap object. */ - void SetBigIcon(const std::shared_ptr &bigIcon); + void SetBigIcon(const std::shared_ptr &bigIcon); /** * Obtains the large icon of this notification. * @return the large icon of this notification. */ - const std::shared_ptr GetBigIcon() const; + const std::shared_ptr GetBigIcon() const; /** * Sets the classification of this notification, which describes the purpose of this notification. @@ -936,8 +935,8 @@ private: std::shared_ptr removalWantAgent_{}; std::shared_ptr maxScreenWantAgent_{}; std::shared_ptr additionalParams_{}; - std::shared_ptr littleIcon_{}; - std::shared_ptr bigIcon_{}; + std::shared_ptr littleIcon_{}; + std::shared_ptr bigIcon_{}; std::shared_ptr notificationContent_{}; std::shared_ptr publicNotification_{}; diff --git a/interfaces/innerkits/ans/native/include/notification_user_input.h b/interfaces/innerkits/ans/native/include/notification_user_input.h index 41b548076c41778e4748d92fd371289f037d0fe4..f84d26830231b3b4e61694326d1f04140a589c1d 100644 --- a/interfaces/innerkits/ans/native/include/notification_user_input.h +++ b/interfaces/innerkits/ans/native/include/notification_user_input.h @@ -28,8 +28,6 @@ namespace OHOS { namespace Notification { -class PixelMap; - class NotificationUserInput : public Parcelable { public: /** diff --git a/interfaces/kits/napi/ans/BUILD.gn b/interfaces/kits/napi/ans/BUILD.gn index d7d886bebb471e003d23ebde37b64d8d6dc9148c..2d7176e35e9c49e5eacec5217b237e444765318d 100755 --- a/interfaces/kits/napi/ans/BUILD.gn +++ b/interfaces/kits/napi/ans/BUILD.gn @@ -36,6 +36,7 @@ ohos_shared_library("notification") { "//foundation/aafwk/standard/frameworks/kits/ability/native/include", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common", "//foundation/ace/napi/interfaces/kits/napi", + "//foundation/multimedia/image_standard/interfaces/kits/js/common/include/", "include", "//third_party/node/src", "//third_party/libuv/include", @@ -70,6 +71,7 @@ ohos_shared_library("notification") { "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", "//foundation/ace/napi:ace_napi", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//foundation/multimedia/image_standard/interfaces/innerkits:image", "//third_party/jsoncpp:jsoncpp", "//third_party/libuv:uv_static", "//utils/native/base:utils", diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 09531dac60e207e0122387e0fc912d0a3b02ca27..84ec62e5cedb24c68c5f17c33d30992649eeedcb 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -19,6 +19,7 @@ #include "notification_long_text_content.h" #include "notification_multiline_content.h" #include "notification_slot.h" +#include "pixel_map_napi.h" #include "publish.h" #include "want_agent.h" @@ -40,14 +41,6 @@ static napi_value GetNotificationMaxScreenWantAgent( const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationAutoDeletedTime( const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationSettingsText( -// const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationGroupValue( -// const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationGroupAlertType( -// const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationGroupOverview( -// const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationClassification( const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationColor(const napi_env &env, const napi_value &value, NotificationRequest &request); @@ -59,25 +52,17 @@ static napi_value GetNotificationIsStopwatch( const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationIsCountDown( const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationVisibleness( -// const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationProgressBar( -// const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationStatusBarText( const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationOnlyLocal( -// const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationSortingKey(const napi_env &env, const napi_value &value, NotificationRequest -// &request); static napi_value GetNotificationLabel(const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationBadgeIconStyle( const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationShortcutId( -// const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationShowDeliveryTime( const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationNotificationActionButtons( const napi_env &env, const napi_value &value, NotificationRequest &request); +static napi_value GetNotificationSmallIcon(const napi_env &env, const napi_value &value, NotificationRequest &request); +static napi_value GetNotificationLargeIcon(const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationContentType(const napi_env &env, const napi_value &result, int32_t &type); static napi_value GetNotificationBasicContent( const napi_env &env, const napi_value &result, NotificationRequest &request); @@ -207,10 +192,6 @@ napi_value Common::SetNotification( napi_create_string_utf8(env, notification->GetKey().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "hashCode", value); - // // ownerBundleName ?: string - // napi_create_string_utf8(env, notification->GetBundleName().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "ownerBundleName", value); - // isFloatingIcon ?: boolean; napi_get_boolean(env, notification->IsFloatingIcon(), &value); napi_set_named_property(env, result, "isFloatingIcon", value); @@ -277,10 +258,6 @@ napi_value Common::SetNotificationRequest( napi_get_boolean(env, request->IsUnremovable(), &value); napi_set_named_property(env, result, "isUnremovable", value); - // // createTime?: number - // napi_create_int64(env, request->GetCreateTime(), &value); - // napi_set_named_property(env, result, "createTime", value); - // deliveryTime?: number napi_create_int64(env, request->GetDeliveryTime(), &value); napi_set_named_property(env, result, "deliveryTime", value); @@ -311,27 +288,6 @@ napi_value Common::SetNotificationRequest( napi_set_named_property(env, result, "extraInfo", extraInfo); } - // // settingsText ?: string - // napi_create_string_utf8(env, request->GetSettingsText().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "settingsText", value); - - // // ownerBundleName ?: string - // napi_create_string_utf8(env, notification->GetBundleName().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "ownerBundleName", value); - - // // groupValue ?: string - // napi_create_string_utf8(env, request->GetGroupValue().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "groupValue", value); - - // // groupAlertType ?: number - // int groupAlertType = (int)request->GetGroupAlertType(); - // napi_create_int32(env, groupAlertType, &value); - // napi_set_named_property(env, result, "groupAlertType", value); - - // // groupOverview ?: boolean - // napi_get_boolean(env, request->IsGroupOverview(), &value); - // napi_set_named_property(env, result, "groupOverview", value); - // removalWantAgent ?: WantAgent std::shared_ptr removalAgent = request->GetRemovalWantAgent(); if (removalAgent) { @@ -376,55 +332,14 @@ napi_value Common::SetNotificationRequest( napi_get_boolean(env, request->IsCountdownTimer(), &value); napi_set_named_property(env, result, "isCountDown", value); - // // visibleness ?: number - // int visibleness = (int)request->GetVisibleness(); - // napi_create_int32(env, visibleness, &value); - // napi_set_named_property(env, result, "visibleness", value); - - // // progressValue ?: number - // napi_create_int32(env, request->GetProgressValue(), &value); - // napi_set_named_property(env, result, "progressValue", value); - - // // progressMaxValue ?: number - // napi_create_int32(env, request->GetProgressMax(), &value); - // napi_set_named_property(env, result, "progressMaxValue", value); - - // // isIndeterminate ?: boolean - // napi_get_boolean(env, request->IsProgressIndeterminate(), &value); - // napi_set_named_property(env, result, "isIndeterminate", value); - // statusBarText ?: string napi_create_string_utf8(env, request->GetStatusBarText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "statusBarText", value); - // isFloatingIcon ?: boolean; do notification + // isFloatingIcon ?: boolean napi_get_boolean(env, request->IsFloatingIcon(), &value); napi_set_named_property(env, result, "isFloatingIcon", value); - // // onlyLocal ?: boolean - // napi_get_boolean(env, request->IsOnlyLocal(), &value); - // napi_set_named_property(env, result, "onlyLocal", value); - - // // sortingKey ?: string - // napi_create_string_utf8(env, request->GetSortingKey().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "sortingKey", value); - - // // messageUsers ?: Array - // napi_value arr; - // int count = 0; - // napi_create_array(env, &arr); - // for (auto vec : request->GetMessageUsers()) {notification - // if (vec) { - // napi_value messageUserResult; - // napi_create_object(env, &messageUserResult); - // if (SetMessageUser(env, vec, messageUserResult)) { - // napi_set_element(env, arr, count, messageUserResult); - // count++; - // } - // } - // } - // napi_set_named_property(env, result, "messageUsers", arr); - // label ?: string napi_create_string_utf8(env, request->GetLabel().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "label", value); @@ -434,10 +349,6 @@ napi_value Common::SetNotificationRequest( napi_create_int32(env, badgeIconStyle, &value); napi_set_named_property(env, result, "badgeIconStyle", value); - // // shortcutId ?: string - // napi_create_string_utf8(env, request->GetShortcutId().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "shortcutId", value); - // showDeliveryTime ?: boolean napi_get_boolean(env, request->IsShowDeliveryTime(), &value); napi_set_named_property(env, result, "showDeliveryTime", value); @@ -458,8 +369,35 @@ napi_value Common::SetNotificationRequest( } napi_set_named_property(env, result, "actionButtons", arr); - // smallIcon ?: image.PixelMap; do - // largeIcon ?: image.PixelMap; do + // smallIcon ?: image.PixelMap + std::shared_ptr littleIcon = request->GetLittleIcon(); + if (littleIcon) { + napi_value smallIconResult = nullptr; + napi_valuetype valuetype = napi_undefined; + smallIconResult = Media::PixelMapNapi::CreatePixelMap(env, littleIcon); + NAPI_CALL(env, napi_typeof(env, smallIconResult, &valuetype)); + if (valuetype == napi_undefined) { + ANS_LOGI("smallIconResult is undefined"); + napi_set_named_property(env, result, "smallIcon", NapiGetNull(env)); + } else { + napi_set_named_property(env, result, "smallIcon", smallIconResult); + } + } + + // largeIcon ?: image.PixelMap + std::shared_ptr largeIcon = request->GetBigIcon(); + if (largeIcon) { + napi_value largeIconResult = nullptr; + napi_valuetype valuetype = napi_undefined; + largeIconResult = Media::PixelMapNapi::CreatePixelMap(env, largeIcon); + NAPI_CALL(env, napi_typeof(env, largeIconResult, &valuetype)); + if (valuetype == napi_undefined) { + ANS_LOGI("largeIconResult is undefined"); + napi_set_named_property(env, result, "largeIcon", NapiGetNull(env)); + } else { + napi_set_named_property(env, result, "largeIcon", largeIconResult); + } + } // readonly creatorBundleName?: string napi_create_string_utf8(env, request->GetCreatorBundleName().c_str(), NAPI_AUTO_LENGTH, &value); @@ -552,10 +490,6 @@ napi_value Common::SetNotificationSorting(const napi_env &env, const Notificatio napi_get_boolean(env, sorting.IsHiddenNotification(), &value); napi_set_named_property(env, result, "isHiddenNotification", value); - // isSuitInterruptionFilter?: boolean ??????? do - // napi_get_boolean(env, sorting->isOrdered, &value); - // napi_set_named_property(env, result, "isSuitInterruptionFilter", value); - // importance?: number napi_create_int32(env, sorting.GetImportance(), &value); napi_set_named_property(env, result, "importance", value); @@ -799,8 +733,6 @@ napi_value Common::SetNotificationPictureContent( napi_value value = nullptr; - // pictureId: number //c++ no do - // briefText: string napi_create_string_utf8(env, pictureContent->GetBriefText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "briefText", value); @@ -809,8 +741,6 @@ napi_value Common::SetNotificationPictureContent( napi_create_string_utf8(env, pictureContent->GetExpandedTitle().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "expandedTitle", value); - // bigPicture: image.PixelMap //do - return NapiGetboolean(env, true); } @@ -913,8 +843,6 @@ napi_value Common::SetMessageUser(const napi_env &env, const MessageUser &messag napi_create_string_utf8(env, messageUser.GetName().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "name", value); - // pixelMap: image.PixelMap //do - // uri: string napi_create_string_utf8(env, messageUser.GetUri().ToString().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "uri", value); @@ -988,17 +916,29 @@ napi_value Common::SetNotificationActionButton( // wantAgent: WantAgent std::shared_ptr agent = actionButton->GetWantAgent(); - if (!agent) { + if (agent == nullptr) { ANS_LOGI("wantAgent is null"); napi_set_named_property(env, result, "wantAgent", NapiGetNull(env)); - return NapiGetboolean(env, true); + return NapiGetboolean(env, false); } napi_value wantAgent = nullptr; wantAgent = CreateWantAgentByJS(env, agent); napi_set_named_property(env, result, "wantAgent", wantAgent); - // extras?: {[key: string]: any} //do - // icon?: image.PixelMap //do + // icon?: image.PixelMap + std::shared_ptr icon = actionButton->GetIcon(); + if (icon) { + napi_value iconResult = nullptr; + napi_valuetype valuetype = napi_undefined; + iconResult = Media::PixelMapNapi::CreatePixelMap(env, icon); + NAPI_CALL(env, napi_typeof(env, iconResult, &valuetype)); + if (valuetype == napi_undefined) { + ANS_LOGI("iconResult is undefined"); + napi_set_named_property(env, result, "icon", NapiGetNull(env)); + } else { + napi_set_named_property(env, result, "icon", iconResult); + } + } return NapiGetboolean(env, true); } @@ -1032,27 +972,6 @@ napi_value Common::GetNotificationSubscriberInfo( } } - // // deviceIds?: Array; - // NAPI_CALL(env, napi_has_named_property(env, value, "deviceIds", &hasProperty)); - // if (hasProperty) { - // napi_value nDeviceIds = nullptr; - // napi_get_named_property(env, value, "deviceIds", &nDeviceIds); - // napi_is_array(env, nDeviceIds, &isArray); - // NAPI_ASSERT(env, isArray, "Property bundleNames is expected to be an array."); - // napi_get_array_length(env, value, &length); - // NAPI_ASSERT(env, length > 0, "The array is empty."); - // for (uint32_t i = 0; i < length; ++i) { - // napi_value nDeviceId = nullptr; - // char str[STR_MAX_SIZE] = {0}; - // napi_get_element(env, nDeviceIds, i, &nDeviceId); - // NAPI_CALL(env, napi_typeof(env, nDeviceId, &valuetype)); - // NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - // NAPI_CALL(env, napi_get_value_string_utf8(env, nDeviceId, str, STR_MAX_SIZE - 1, &strLen)); - // subscriberInfo.deviceIds.emplace_back(str); - // subscriberInfo.hasSubscribeInfo = true; - // } - // } - // userId?: number; NAPI_CALL(env, napi_has_named_property(env, value, "userId", &hasProperty)); if (hasProperty) { @@ -1131,26 +1050,6 @@ napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value return nullptr; } - // // settingsText?: string - // if (GetNotificationSettingsText(env, value, request) == nullptr) { - // return nullptr; - // } - - // // groupValue?: string - // if (GetNotificationGroupValue(env, value, request) == nullptr) { - // return nullptr; - // } - - // // groupAlertType?: number - // if (GetNotificationGroupAlertType(env, value, request) == nullptr) { - // return nullptr; - // } - - // // groupOverview?: boolean - // if (GetNotificationGroupOverview(env, value, request) == nullptr) { - // return nullptr; - // } - // classification?: string if (GetNotificationClassification(env, value, request) == nullptr) { return nullptr; @@ -1181,33 +1080,11 @@ napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value return nullptr; } - // // visibleness?: number - // if (GetNotificationVisibleness(env, value, request) == nullptr) { - // return nullptr; - // } - - // // progressValue?: number - // // progressMaxValue?: number - // // isIndeterminate?: boolean - // if (GetNotificationProgressBar(env, value, request) == nullptr) { - // return nullptr; - // } - // statusBarText?: string if (GetNotificationStatusBarText(env, value, request) == nullptr) { return nullptr; } - // // onlyLocal?: boolean - // if (GetNotificationOnlyLocal(env, value, request) == nullptr) { - // return nullptr; - // } - - // // sortingKey?: string - // if (GetNotificationSortingKey(env, value, request) == nullptr) { - // return nullptr; - // } - // label?: string if (GetNotificationLabel(env, value, request) == nullptr) { return nullptr; @@ -1218,11 +1095,6 @@ napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value return nullptr; } - // // shortcutId?: string - // if (GetNotificationShortcutId(env, value, request) == nullptr) { - // return nullptr; - // } - // showDeliveryTime?: boolean if (GetNotificationShowDeliveryTime(env, value, request) == nullptr) { return nullptr; @@ -1233,6 +1105,16 @@ napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value return nullptr; } + // smallIcon?: image.PixelMap + if (GetNotificationSmallIcon(env, value, request) == nullptr) { + return nullptr; + } + + // largeIcon?: image.PixelMap + if (GetNotificationLargeIcon(env, value, request) == nullptr) { + return nullptr; + } + return Common::NapiGetNull(env); } @@ -1560,98 +1442,6 @@ napi_value GetNotificationAutoDeletedTime(const napi_env &env, const napi_value return Common::NapiGetNull(env); } -// napi_value GetNotificationSettingsText( -// const napi_env &env, const napi_value &value, NotificationRequest &request) -// { -// ANS_LOGI("enter"); - -// napi_valuetype valuetype = napi_undefined; -// napi_value result = nullptr; -// bool hasProperty = false; -// char str[STR_MAX_SIZE] = {0}; -// size_t strLen = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "settingsText", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "settingsText", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); -// NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); -// request.SetSettingsText(str); -// } - -// ANS_LOGI("===============GetNotificationSettingsText====settingsText = %{public}s end", str); -// return Common::NapiGetNull(env); -// } - -// napi_value GetNotificationGroupValue( -// const napi_env &env, const napi_value &value, NotificationRequest &request) -// { -// ANS_LOGI("enter"); - -// napi_valuetype valuetype = napi_undefined; -// napi_value result = nullptr; -// bool hasProperty = false; -// char str[STR_MAX_SIZE] = {0}; -// size_t strLen = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "groupValue", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "groupValue", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); -// NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); -// request.SetGroupValue(str); -// } - -// ANS_LOGI("===============GetNotificationGroupValue====groupValue = %{public}s end", str); -// return Common::NapiGetNull(env); -// } - -// napi_value GetNotificationGroupAlertType( -// const napi_env &env, const napi_value &value, NotificationRequest &request) -// { -// ANS_LOGI("enter"); - -// napi_valuetype valuetype = napi_undefined; -// napi_value result = nullptr; -// bool hasProperty = false; -// int32_t groupAlertType = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "groupAlertType", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "groupAlertType", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); -// napi_get_value_int32(env, result, &groupAlertType); -// request.SetGroupAlertType(static_cast(groupAlertType)); -// } - -// return Common::NapiGetNull(env); -// } - -// napi_value GetNotificationGroupOverview( -// const napi_env &env, const napi_value &value, NotificationRequest &request) -// { -// ANS_LOGI("enter"); - -// napi_valuetype valuetype = napi_undefined; -// napi_value result = nullptr; -// bool hasProperty = false; -// bool groupOverview = false; - -// NAPI_CALL(env, napi_has_named_property(env, value, "groupOverview", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "groupOverview", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); -// napi_get_value_bool(env, result, &groupOverview); -// request.SetGroupOverview(groupOverview); -// } - -// return Common::NapiGetNull(env); -// } - napi_value GetNotificationClassification(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1780,68 +1570,6 @@ napi_value GetNotificationIsCountDown(const napi_env &env, const napi_value &val return Common::NapiGetNull(env); } -// napi_value GetNotificationVisibleness( -// const napi_env &env, const napi_value &value, NotificationRequest &request) -// { -// ANS_LOGI("enter"); - -// napi_valuetype valuetype = napi_undefined; -// napi_value result = nullptr; -// bool hasProperty = false; -// int32_t visibleness = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "visibleness", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "visibleness", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); -// napi_get_value_int32(env, result, &visibleness); -// request.SetVisibleness(static_cast(visibleness)); -// } - -// return Common::NapiGetNull(env); -// } - -// napi_value GetNotificationProgressBar(const napi_env &env, const napi_value &value, NotificationRequest &request) -// { -// ANS_LOGI("enter"); - -// napi_valuetype valuetype = napi_undefined; -// napi_value result = nullptr; -// bool hasProperty = false; -// int32_t progressValue = 0; -// int32_t progressMaxValue = 0; -// bool isIndeterminate = false; - -// NAPI_CALL(env, napi_has_named_property(env, value, "progressValue", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "progressValue", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); -// napi_get_value_int32(env, result, &progressValue); -// } - -// NAPI_CALL(env, napi_has_named_property(env, value, "progressMaxValue", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "progressMaxValue", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); -// napi_get_value_int32(env, result, &progressMaxValue); -// } - -// NAPI_CALL(env, napi_has_named_property(env, value, "isIndeterminate", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "isIndeterminate", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); -// napi_get_value_bool(env, result, &isIndeterminate); -// } - -// request.SetProgressBar(progressValue, progressMaxValue, isIndeterminate); - -// return Common::NapiGetNull(env); -// } - napi_value GetNotificationStatusBarText(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1864,50 +1592,6 @@ napi_value GetNotificationStatusBarText(const napi_env &env, const napi_value &v return Common::NapiGetNull(env); } -// napi_value GetNotificationOnlyLocal(const napi_env &env, const napi_value &value, NotificationRequest -// &request) -// { -// ANS_LOGI("enter"); - -// napi_valuetype valuetype = napi_undefined; -// napi_value result = nullptr; -// bool hasProperty = false; -// bool onlyLocal = false; - -// NAPI_CALL(env, napi_has_named_property(env, value, "onlyLocal", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "onlyLocal", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. bool expected."); -// napi_get_value_bool(env, result, &onlyLocal); -// request.SetOnlyLocal(onlyLocal); -// } - -// return Common::NapiGetNull(env); -// } - -// napi_value GetNotificationSortingKey(const napi_env &env, const napi_value &value, NotificationRequest &request) -// { -// ANS_LOGI("enter"); - -// napi_valuetype valuetype = napi_undefined; -// napi_value result = nullptr; -// bool hasProperty = false; -// char str[STR_MAX_SIZE] = {0}; -// size_t strLen = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "sortingKey", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "sortingKey", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); -// NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); -// request.SetSortingKey(str); -// } - -// return Common::NapiGetNull(env); -// } - napi_value GetNotificationLabel(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1951,30 +1635,6 @@ napi_value GetNotificationBadgeIconStyle(const napi_env &env, const napi_value & return Common::NapiGetNull(env); } -// napi_value GetNotificationShortcutId( -// const napi_env &env, const napi_value &value, NotificationRequest &request) -// { -// ANS_LOGI("enter"); - -// napi_valuetype valuetype = napi_undefined; -// napi_value result = nullptr; -// bool hasProperty = false; -// char str[STR_MAX_SIZE] = {0}; -// size_t strLen = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "shortcutId", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "shortcutId", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); -// NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); -// request.SetShortcutId(str); -// } - -// ANS_LOGI("===============GetNotificationShortcutId====shortcutId = %{public}s end", str); -// return Common::NapiGetNull(env); -// } - napi_value GetNotificationShowDeliveryTime(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -2010,8 +1670,10 @@ napi_value GetNotificationNotificationActionButtons( bool hasProperty = false; napi_value titelActionButton = nullptr; napi_value wantAgentActionButton = nullptr; + napi_value iconActionButton = nullptr; std::string title; WantAgent::WantAgent *wantAgentPtr = nullptr; + std::shared_ptr iconPtr = nullptr; std::shared_ptr wantAgent; napi_has_named_property(env, value, "actionButtons", &hasProperty); @@ -2060,16 +1722,79 @@ napi_value GetNotificationNotificationActionButtons( return nullptr; } - // extras?: {[key: string]: any}; + // icon?: image.PixelMap + NAPI_CALL(env, napi_has_named_property(env, actionButton, "icon", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, actionButton, "icon", &iconActionButton); + NAPI_CALL(env, napi_typeof(env, iconActionButton, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + std::shared_ptr pixelMap = nullptr; + pixelMap = Media::PixelMapNapi::GetPixelMap(env, iconActionButton); + if (pixelMap == nullptr) { + ANS_LOGE("Invalid object pixelMap"); + return nullptr; + } + iconPtr = std::make_shared(*pixelMap); + } std::vector> vec; - auto pActionButton = NotificationActionButton::Create(nullptr, title, wantAgent); + auto pActionButton = NotificationActionButton::Create(iconPtr, title, wantAgent); request.AddActionButton(pActionButton); } return Common::NapiGetNull(env); } +napi_value GetNotificationSmallIcon(const napi_env &env, const napi_value &value, NotificationRequest &request) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value result = nullptr; + bool hasProperty = false; + + NAPI_CALL(env, napi_has_named_property(env, value, "smallIcon", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "smallIcon", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + std::shared_ptr pixelMap = nullptr; + pixelMap = Media::PixelMapNapi::GetPixelMap(env, result); + if (pixelMap == nullptr) { + ANS_LOGE("Invalid object pixelMap"); + return nullptr; + } + request.SetLittleIcon(std::make_shared(*pixelMap)); + } + + return Common::NapiGetNull(env); +} + +napi_value GetNotificationLargeIcon(const napi_env &env, const napi_value &value, NotificationRequest &request) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value result = nullptr; + bool hasProperty = false; + + NAPI_CALL(env, napi_has_named_property(env, value, "largeIcon", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "largeIcon", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + std::shared_ptr pixelMap = nullptr; + pixelMap = Media::PixelMapNapi::GetPixelMap(env, result); + if (pixelMap == nullptr) { + ANS_LOGE("Invalid object pixelMap"); + return nullptr; + } + request.SetBigIcon(std::make_shared(*pixelMap)); + } + + return Common::NapiGetNull(env); +} + napi_value GetNotificationContentType(const napi_env &env, const napi_value &result, int32_t &type) { ANS_LOGI("enter"); @@ -2363,8 +2088,6 @@ napi_value GetNotificationPictureContent(const napi_env &env, const napi_value & return nullptr; } - // bigPicture: image.PixelMap do - request.SetContent(std::make_shared(pictureContent)); return Common::NapiGetNull(env); @@ -2393,8 +2116,6 @@ napi_value GetMessageUser(const napi_env &env, const napi_value &result, Message return nullptr; } - // pixelMap: image.PixelMap do - // uri: string NAPI_CALL(env, napi_has_named_property(env, result, "uri", &hasProperty)); if (hasProperty) { @@ -3071,18 +2792,9 @@ bool Common::ContentTypeJSToC(const enum ContentType &inType, enum NotificationC case ContentType::NOTIFICATION_CONTENT_LONG_TEXT: outType = NotificationContent::Type::LONG_TEXT; break; - // case ContentType::NOTIFICATION_CONTENT_PICTURE: - // outType = NotificationContent::Type::PICTURE; - // break; - // case ContentType::NOTIFICATION_CONTENT_CONVERSATION: - // outType = NotificationContent::Type::CONVERSATION; - // break; case ContentType::NOTIFICATION_CONTENT_MULTILINE: outType = NotificationContent::Type::MULTILINE; break; - // case ContentType::NOTIFICATION_CONTENT_MEDIA: - // outType = NotificationContent::Type::MEDIA; - // break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); return false; @@ -3099,18 +2811,9 @@ bool Common::ContentTypeCToJS(const enum NotificationContent::Type &inType, enum case NotificationContent::Type::LONG_TEXT: outType = ContentType::NOTIFICATION_CONTENT_LONG_TEXT; break; - // case NotificationContent::Type::PICTURE: - // outType = ContentType::NOTIFICATION_CONTENT_PICTURE; - // break; - // case NotificationContent::Type::CONVERSATION: - // outType = ContentType::NOTIFICATION_CONTENT_CONVERSATION; - // break; case NotificationContent::Type::MULTILINE: outType = ContentType::NOTIFICATION_CONTENT_MULTILINE; break; - // case NotificationContent::Type::MEDIA: - // outType = ContentType::NOTIFICATION_CONTENT_MEDIA; - // break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); return false; diff --git a/interfaces/kits/napi/ans/src/display_badge.cpp b/interfaces/kits/napi/ans/src/display_badge.cpp index 52d895636173efe32c84da0985feba28695d4b29..129355a8fccb3091b7b8b08f7e7ce26332a20898 100644 --- a/interfaces/kits/napi/ans/src/display_badge.cpp +++ b/interfaces/kits/napi/ans/src/display_badge.cpp @@ -75,9 +75,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[2]:callback if (argc >= ENABLE_BADGE_DISPLAYED_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[ENABLE_BADGE_DISPLAYED_MAX_PARA - 1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[2], 1, ¶ms.callback); + napi_create_reference(env, argv[ENABLE_BADGE_DISPLAYED_MAX_PARA - 1], 1, ¶ms.callback); } return Common::NapiGetNull(env); diff --git a/interfaces/kits/napi/ans/src/enable_notification.cpp b/interfaces/kits/napi/ans/src/enable_notification.cpp index 014c6c3e680ee529740c8de450a738bea7d7bcca..5e2b6535a715a6bf00960a18838ff5e3af032868 100644 --- a/interfaces/kits/napi/ans/src/enable_notification.cpp +++ b/interfaces/kits/napi/ans/src/enable_notification.cpp @@ -75,9 +75,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[2]:callback if (argc >= ENABLE_NOTIFICATION_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[ENABLE_NOTIFICATION_MAX_PARA -1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[2], 1, ¶ms.callback); + napi_create_reference(env, argv[ENABLE_NOTIFICATION_MAX_PARA -1], 1, ¶ms.callback); } return Common::NapiGetNull(env); diff --git a/interfaces/kits/napi/ans/src/remove.cpp b/interfaces/kits/napi/ans/src/remove.cpp index a2c4f62ba92f3465912e37ff4c700c74be5ea08f..edac8de8a411bc2eb97a2146ba020dbf6d8881fb 100644 --- a/interfaces/kits/napi/ans/src/remove.cpp +++ b/interfaces/kits/napi/ans/src/remove.cpp @@ -97,9 +97,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[2]:callback if (argc >= REMOVE_BY_BUNDLE_AND_KEY_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[REMOVE_BY_BUNDLE_AND_KEY_MAX_PARA -1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[2], 1, ¶ms.callback); + napi_create_reference(env, argv[REMOVE_BY_BUNDLE_AND_KEY_MAX_PARA -1], 1, ¶ms.callback); } } diff --git a/interfaces/kits/napi/ans/src/slot.cpp b/interfaces/kits/napi/ans/src/slot.cpp index 19350c71683a8ddd6f0a1997c0d5382bbae73a68..e9d3cbc81d79cd52492372a2466031c28b1c6ebf 100644 --- a/interfaces/kits/napi/ans/src/slot.cpp +++ b/interfaces/kits/napi/ans/src/slot.cpp @@ -249,9 +249,9 @@ napi_value ParseParametersSetSlotAsBundle( // argv[2]:callback if (argc >= SET_SLOT_AS_BUNDLE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[SET_SLOT_AS_BUNDLE_MAX_PARA -1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[2], 1, ¶ms.callback); + napi_create_reference(env, argv[SET_SLOT_AS_BUNDLE_MAX_PARA -1], 1, ¶ms.callback); } return Common::NapiGetNull(env); diff --git a/interfaces/kits/napi/ans/src/subscribe.cpp b/interfaces/kits/napi/ans/src/subscribe.cpp index f4787d927a8fd6811c3cd9b172c8a6c883f4e1b4..6abc770ea1b1ce8fd580268dc36da2286e724cc4 100644 --- a/interfaces/kits/napi/ans/src/subscribe.cpp +++ b/interfaces/kits/napi/ans/src/subscribe.cpp @@ -897,9 +897,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[2]:callback if (argc >= SUBSRIBE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[SUBSRIBE_MAX_PARA - 1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[2], 1, &callback); + napi_create_reference(env, argv[SUBSRIBE_MAX_PARA - 1], 1, &callback); } return Common::NapiGetNull(env); diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index a062596c39e5a827eb83b04780c0fe7fd57e8c65..ff9eb615a207082dc96981c1f248f4daf27111de 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -67,6 +67,7 @@ ohos_shared_library("libans") { "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/services/abilitymgr:abilityms", "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner", + "//foundation/multimedia/image_standard/interfaces/innerkits:image", "//utils/native/base:utils", ] diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 810e075344a16148ab1e3b9b672d4de7e67b82b0..be3508a61a36ec4227d1f1736fba7f8bd85fd7c9 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -122,6 +122,35 @@ inline ErrCode AssignValidNotificationSlot(const std::shared_ptr &request) +{ + ErrCode result = ERR_OK; + + auto content = request->GetContent(); + if (content != nullptr && content->GetContentType() == NotificationContent::Type::PICTURE) { + std::shared_ptr pictureContent = + std::static_pointer_cast(content->GetNotificationContent()); + if (pictureContent != nullptr) { + auto picture = pictureContent->GetBigPicture(); + if (picture != nullptr && (uint32_t)picture->GetByteCount() > MAX_PICTURE_SIZE) { + result = ERR_ANS_PICTURE_OVER_SIZE; + } + } + } + + auto littleIcon = request->GetLittleIcon(); + if (littleIcon != nullptr && (uint32_t)littleIcon->GetByteCount() > MAX_ICON_SIZE) { + result = ERR_ANS_ICON_OVER_SIZE; + } + + auto bigIcon = request->GetBigIcon(); + if (bigIcon != nullptr && (uint32_t)bigIcon->GetByteCount() > MAX_ICON_SIZE) { + result = ERR_ANS_ICON_OVER_SIZE; + } + + return result; +} + inline ErrCode PrepereNotificationRequest(const sptr &request) { std::string bundle = GetClientBundleName(); @@ -137,7 +166,9 @@ inline ErrCode PrepereNotificationRequest(const sptr &reque request->SetCreatorUid(uid); request->SetCreatorPid(pid); - return ERR_OK; + ErrCode result = CheckPictureSize(request); + + return result; } sptr AdvancedNotificationService::GetInstance() diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 8da3be02ecd880a23a342e6fda4560ae0cac2988..642dbb200d2822c55a13dfeb059c35eccb9079e0 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -81,6 +81,7 @@ ohos_unittest("ans_unit_test") { "${frameworks_path}/ans/native:ans_innerkits", "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//foundation/multimedia/image_standard/interfaces/innerkits:image", "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 90d0cbc84faec23e3db0d39eafbff568b730bae5..9ce83674362458d0510688771f0193abf2b97ef2 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -30,6 +30,7 @@ #include "notification_subscriber.h" using namespace testing::ext; +using namespace OHOS::Media; namespace OHOS { namespace Notification { @@ -116,6 +117,7 @@ void AdvancedNotificationServiceTest::TestAddSlotGroup() groups.push_back(group); advancedNotificationService_->AddSlotGroups(groups); } + /** * @tc.number : AMS_ANS_Publish_00100 * @tc.name : ANSPublish00100 @@ -412,7 +414,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01200, /** * @tc.number : AMS_ANS_Publish_01300 * @tc.name : ANSPublish01300 - * @tc.desc : When a bundle is not allowed to publish a notification, the notification publishing interface returns + * @tc.desc : When a bundle is not allowed to publish a notification, the notification publishing interface + returns * ERR_ANS_NOT_ALLOWED */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01300, Function | SmallTest | Level1) @@ -1274,5 +1277,119 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09900, (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +inline std::shared_ptr MakePixelMap(int32_t width, int32_t height) +{ + const int32_t PIXEL_BYTES = 4; + std::shared_ptr pixelMap = std::make_shared(); + ImageInfo info; + info.size.width = width; + info.size.height = height; + info.pixelFormat = PixelFormat::ARGB_8888; + info.colorSpace = ColorSpace::SRGB; + pixelMap->SetImageInfo(info); + int32_t rowDataSize = width * PIXEL_BYTES; + uint32_t bufferSize = rowDataSize * height; + void *buffer = malloc(bufferSize); + EXPECT_NE(buffer, nullptr); + pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr); + return pixelMap; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10000 + * @tc.name : AMS_ANS_Publish_With_PixelMap + * @tc.desc : Publish a notification with pixelMap. + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10000, Function | SmallTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 400; + const int BIG_PICTURE_HEIGHT = 300; + const int ICON_SIZE = 36; + + sptr req = new NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetBigIcon(bigIcon); + EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10100 + * @tc.name : AMS_ANS_Publish_With_PixelMap_Oversize_00100 + * @tc.desc : Publish a notification with oversize pixelMap. + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10100, Function | SmallTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 1024; + const int BIG_PICTURE_HEIGHT = 1024; + const int ICON_SIZE = 36; + + sptr req = new NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetBigIcon(bigIcon); + EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_ANS_PICTURE_OVER_SIZE); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10200 + * @tc.name : AMS_ANS_Publish_With_PixelMap_Oversize_00200 + * @tc.desc : Publish a notification with oversize pixelMap. + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10200, Function | SmallTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 400; + const int BIG_PICTURE_HEIGHT = 300; + const int ICON_SIZE = 256; + + sptr req = new NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetBigIcon(bigIcon); + EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_ANS_ICON_OVER_SIZE); +} + } // namespace Notification } // namespace OHOS diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 740e3b89562c3937fbdef65251285e59b1f3ae42..558bedfac49f0a8f78095d3cd783ef9a0a8e3433 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -80,6 +80,7 @@ ohos_moduletest("ans_module_test") { "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/image_standard/interfaces/innerkits:image", "//third_party/googletest:gtest_main", "//utils/native/base:utils", ]