From 9ff1158d3ece28697a20c9537005e3f4fc38e544 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Wed, 24 Nov 2021 11:58:47 +0000 Subject: [PATCH 1/3] Add pixelmapInit Signed-off-by: zhaoyuan17 --- .../ans/core/include/ans_notification.h | 16 +- frameworks/ans/core/src/ans_manager_stub.cpp | 2 - frameworks/ans/core/src/ans_notification.cpp | 127 ++++++----- .../test/moduletest/ans_fw_module_test.cpp | 206 +++++++++--------- interfaces/kits/napi/ans/src/init.cpp | 3 + 5 files changed, 199 insertions(+), 155 deletions(-) diff --git a/frameworks/ans/core/include/ans_notification.h b/frameworks/ans/core/include/ans_notification.h index 066b03bb2..4c2661323 100644 --- a/frameworks/ans/core/include/ans_notification.h +++ b/frameworks/ans/core/include/ans_notification.h @@ -643,6 +643,21 @@ private: */ bool CanPublishMediaContent(const NotificationRequest &request) const; + /** + * Check whether the picture size exceeds the limit in PixelMap + * + * @return Returns true if the limit size is exceeded; returns false otherwise. + */ + bool CheckImageOverSizeForPixelMap( + const std::shared_ptr &pixelMap, uint32_t maxSize); + + /** + * Check whether the picture size exceeds the limit in NotificationRequest's content + * + * @return the ErrCode. + */ + ErrCode CheckImageSizeForContent(const NotificationRequest &request); + /** * Check whether the picture size exceeds the limit * @@ -655,7 +670,6 @@ private: sptr ansManagerProxy_; sptr recipient_; }; - } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/core/src/ans_manager_stub.cpp b/frameworks/ans/core/src/ans_manager_stub.cpp index 8928488bb..2e8da5eac 100644 --- a/frameworks/ans/core/src/ans_manager_stub.cpp +++ b/frameworks/ans/core/src/ans_manager_stub.cpp @@ -1190,7 +1190,6 @@ ErrCode AnsManagerStub::HandleCancelGroup(MessageParcel &data, MessageParcel &re ANS_LOGW("[HandleCancelGroup] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; } - return ERR_OK; } @@ -1214,7 +1213,6 @@ ErrCode AnsManagerStub::HandleRemoveGroupByBundle(MessageParcel &data, MessagePa ANS_LOGW("[HandleRemoveGroupByBundle] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; } - return ERR_OK; } diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index ec677c790..fb2a0e253 100644 --- a/frameworks/ans/core/src/ans_notification.cpp +++ b/frameworks/ans/core/src/ans_notification.cpp @@ -907,61 +907,92 @@ bool AnsNotification::CanPublishMediaContent(const NotificationRequest &request) return true; } +bool AnsNotification::CheckImageOverSizeForPixelMap(const std::shared_ptr &pixelMap, uint32_t maxSize) +{ + if (!pixelMap) { + return false; + } + + uint32_t size = static_cast(pixelMap->GetByteCount()); + if (size > maxSize) { + return true; + } + return false; +} + +ErrCode AnsNotification::CheckImageSizeForContent(const NotificationRequest &request) +{ + auto content = request.GetContent(); + if (!content) { + ANS_LOGW("Invalid content in NotificationRequest"); + return ERR_OK; + } + + auto basicContent = request.GetContent()->GetNotificationContent(); + if (!basicContent) { + ANS_LOGW("Invalid content in NotificationRequest"); + return ERR_OK; + } + + auto contentType = request.GetNotificationType(); + switch (contentType) { + case NotificationContent::Type::CONVERSATION: { + auto conversationalContent = std::static_pointer_cast(basicContent); + + auto picture = conversationalContent->GetMessageUser().GetPixelMap(); + if (CheckImageOverSizeForPixelMap(picture, MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in ConversationalContent's message user 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 (CheckImageOverSizeForPixelMap(img, MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in ConversationalContent's message 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 (CheckImageOverSizeForPixelMap(bigPicture, MAX_PICTURE_SIZE)) { + ANS_LOGE("The size of big picture in PictureContent exceeds limit"); + return ERR_ANS_PICTURE_OVER_SIZE; + } + break; + } + default: + break; + } + + return ERR_OK; +} + ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) { auto littleIcon = request.GetLittleIcon(); - if (littleIcon && (static_cast(littleIcon->GetByteCount()) > MAX_ICON_SIZE)) { + if (CheckImageOverSizeForPixelMap(littleIcon, 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)) { + if (CheckImageOverSizeForPixelMap(bigIcon, 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; - } - } + ErrCode err = CheckImageSizeForContent(request); + if (err != ERR_OK) { + return err; } auto buttons = request.GetActionButtons(); @@ -969,10 +1000,9 @@ ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) 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"); + if (CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { + ANS_LOGE("The size of icon in ActionButton exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } } @@ -982,10 +1012,9 @@ ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) 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"); + if (CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in MessageUser exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } } diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index c89d45290..b9db0989a 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -352,7 +352,7 @@ public: ~EventParser() {} - void parse(std::list> events) + void Parse(std::list> events) { for (auto event : events) { if (event->GetType() == SubscriberEventType::ON_SUBSCRIBERESULT) { @@ -384,87 +384,87 @@ public: } } - void setWaitOnConsumed(bool bl) + void SetWaitOnConsumed(bool bl) { waitOnConsumed_ = bl; } - void setWaitOnCanceled(bool bl) + void SetWaitOnCanceled(bool bl) { waitOnCanceled_ = bl; } - void setWaitOnCanceledWithSortingMapAndDeleteReason(bool bl) + void SetWaitOnCanceledWithSortingMapAndDeleteReason(bool bl) { waitOnCanceledWithSortingMapAndDeleteReason_ = bl; } - void setWaitOnUnSubscriber() + void SetWaitOnUnSubscriber() { waitOnUnSubscriber_ = NotificationConstant::SubscribeResult::RESOURCES_FAIL; } - bool getWaitOnSubscriber() + bool GetWaitOnSubscriber() const { return waitOnSubscriber_; } - bool getWaitOnUnSubscriber() + bool GetWaitOnUnSubscriber() const { return waitOnUnSubscriber_; } - bool getwaitOnConsumed() + bool GetWaitOnConsumed() const { return waitOnConsumed_; } - std::vector> getOnConsumedReq() + std::vector> GetOnConsumedReq() const { return onConsumedReq_; } - std::vector> getOnConsumedWithSortingMapReq() + std::vector> GetOnConsumedWithSortingMapReq() const { return onConsumedWithSortingMapReq_; } - std::vector> getOnConsumedWithSortingMapSor() + std::vector> GetOnConsumedWithSortingMapSor() const { return onConsumedWithSortingMapSor_; } - bool getWaitOnConsumedWithSortingMap() + bool GetWaitOnConsumedWithSortingMap() const { return waitOnConsumedWithSortingMap_; } - bool getWaitOnCanceled() + bool GetWaitOnCanceled() const { return waitOnCanceled_; } - bool getWaitOnCanceledWithSortingMapAndDeleteReason() + bool GetWaitOnCanceledWithSortingMapAndDeleteReason() const { return waitOnCanceledWithSortingMapAndDeleteReason_; } - std::vector> getOnCanceledReq() + std::vector> GetOnCanceledReq() const { return onCanceledReq_; } - std::vector> getOnCanceledWithSortingMapReq() + std::vector> GetOnCanceledWithSortingMapReq() const { return onCanceledWithSortingMapReq_; } - std::vector> getOnCanceledWithSortingMapSor() + std::vector> GetOnCanceledWithSortingMapSor() const { return onCanceledWithSortingMapSor_; } - std::vector getOnCanceledWithSortingMapDelRea() + std::vector GetOnCanceledWithSortingMapDelRea() { return onCanceledWithSortingMapDelRea_; } @@ -545,7 +545,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_FlowControl_00100, Function | MediumTest | L SleepForFC(); std::list> events = subscriber.GetEvents(); EventParser eventParser; - eventParser.parse(events); + eventParser.Parse(events); for (uint32_t i = 0; i <= MAX_ACTIVE_NUM_PERSECOND; i++) { std::string notificationLabel = std::to_string(i); std::string notificationIdStr = std::to_string(i); @@ -555,21 +555,21 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_FlowControl_00100, Function | MediumTest | L stream << UID << KEY_SPLITER << notificationLabel << KEY_SPLITER << notificationIdInt; std::string notificationKey = stream.str(); NotificationSorting sorting; - EXPECT_EQ(eventParser.getOnConsumedReq()[i]->GetLabel().c_str(), notificationLabel); - EXPECT_EQ(eventParser.getOnConsumedReq()[i]->GetId(), notificationIdInt); - EXPECT_EQ(eventParser.getOnConsumedReq()[i]->GetKey(), notificationKey); - EXPECT_EQ(eventParser.getOnConsumedWithSortingMapReq()[i]->GetLabel().c_str(), notificationLabel); - EXPECT_EQ(eventParser.getOnConsumedWithSortingMapReq()[i]->GetId(), notificationIdInt); - EXPECT_EQ(eventParser.getOnConsumedWithSortingMapReq()[i]->GetKey(), notificationKey); + EXPECT_EQ(eventParser.GetOnConsumedReq()[i]->GetLabel().c_str(), notificationLabel); + EXPECT_EQ(eventParser.GetOnConsumedReq()[i]->GetId(), notificationIdInt); + EXPECT_EQ(eventParser.GetOnConsumedReq()[i]->GetKey(), notificationKey); + EXPECT_EQ(eventParser.GetOnConsumedWithSortingMapReq()[i]->GetLabel().c_str(), notificationLabel); + EXPECT_EQ(eventParser.GetOnConsumedWithSortingMapReq()[i]->GetId(), notificationIdInt); + EXPECT_EQ(eventParser.GetOnConsumedWithSortingMapReq()[i]->GetKey(), notificationKey); EXPECT_TRUE( - eventParser.getOnConsumedWithSortingMapSor()[i]->GetNotificationSorting(notificationKey, sorting)); + eventParser.GetOnConsumedWithSortingMapSor()[i]->GetNotificationSorting(notificationKey, sorting)); EXPECT_EQ(sorting.GetKey().c_str(), notificationKey); } } - EXPECT_EQ((uint32_t)eventParser.getOnConsumedReq().size(), MAX_ACTIVE_NUM_PERSECOND); - EXPECT_EQ((uint32_t)eventParser.getOnConsumedWithSortingMapReq().size(), MAX_ACTIVE_NUM_PERSECOND); - EXPECT_TRUE(eventParser.getWaitOnSubscriber()); - EXPECT_TRUE(eventParser.getWaitOnUnSubscriber()); + EXPECT_EQ((uint32_t)eventParser.GetOnConsumedReq().size(), MAX_ACTIVE_NUM_PERSECOND); + EXPECT_EQ((uint32_t)eventParser.GetOnConsumedWithSortingMapReq().size(), MAX_ACTIVE_NUM_PERSECOND); + EXPECT_TRUE(eventParser.GetWaitOnSubscriber()); + EXPECT_TRUE(eventParser.GetWaitOnUnSubscriber()); subscriber.ClearEvents(); SleepForFC(); } @@ -601,21 +601,21 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitonsByKey_00100, Function | M SleepForFC(); std::list> events = subscriber.GetEvents(); EventParser eventParser; - eventParser.parse(events); - EXPECT_TRUE(eventParser.getwaitOnConsumed()); - EXPECT_TRUE(eventParser.getWaitOnConsumedWithSortingMap()); - EXPECT_TRUE(eventParser.getWaitOnCanceled()); - EXPECT_EQ(eventParser.getOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); - EXPECT_EQ(eventParser.getOnConsumedReq()[0]->GetId(), 0); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + EXPECT_TRUE(eventParser.GetWaitOnConsumedWithSortingMap()); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 0); std::stringstream stream; stream << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0; std::string notificationKey = stream.str(); NotificationSorting sorting; - EXPECT_EQ(eventParser.getOnCanceledReq()[0]->GetKey(), notificationKey); - EXPECT_EQ(eventParser.getOnCanceledWithSortingMapReq()[0]->GetKey(), notificationKey); - EXPECT_TRUE(eventParser.getOnConsumedWithSortingMapSor()[0]->GetNotificationSorting(notificationKey, sorting)); + EXPECT_EQ(eventParser.GetOnCanceledReq()[0]->GetKey(), notificationKey); + EXPECT_EQ(eventParser.GetOnCanceledWithSortingMapReq()[0]->GetKey(), notificationKey); + EXPECT_TRUE(eventParser.GetOnConsumedWithSortingMapSor()[0]->GetNotificationSorting(notificationKey, sorting)); EXPECT_EQ(sorting.GetKey().c_str(), notificationKey); - EXPECT_EQ(eventParser.getOnCanceledWithSortingMapDelRea()[0], CANCEL_REASON_DELETE); + EXPECT_EQ(eventParser.GetOnCanceledWithSortingMapDelRea()[0], CANCEL_REASON_DELETE); subscriber.ClearEvents(); SleepForFC(); } @@ -646,19 +646,19 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitonsByKey_00200, Function | M SleepForFC(); std::list> events = subscriber.GetEvents(); EventParser eventParser; - eventParser.parse(events); - EXPECT_TRUE(eventParser.getWaitOnCanceled()); - eventParser.setWaitOnCanceled(false); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + eventParser.SetWaitOnCanceled(false); EXPECT_EQ(NotificationHelper::RemoveNotification(key), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); events = subscriber.GetEvents(); - eventParser.parse(events); - EXPECT_TRUE(eventParser.getWaitOnCanceled()); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); SleepForFC(); EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber, info), ERR_OK); SleepForFC(); events = subscriber.GetEvents(); - eventParser.parse(events); - EXPECT_TRUE(eventParser.getWaitOnConsumedWithSortingMap()); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumedWithSortingMap()); subscriber.ClearEvents(); SleepForFC(); } @@ -685,9 +685,9 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitons_00100, Function | Medium SleepForFC(); EventParser eventParser; std::list> events = subscriber.GetEvents(); - eventParser.parse(events); - EXPECT_TRUE(eventParser.getwaitOnConsumed()); - eventParser.setWaitOnConsumed(false); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + eventParser.SetWaitOnConsumed(false); NotificationRequest req1(1); req1.SetLabel(NOTIFICATION_LABEL_0); @@ -695,8 +695,8 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitons_00100, Function | Medium events = subscriber.GetEvents(); EXPECT_EQ(NotificationHelper::PublishNotification(req1), ERR_OK); SleepForFC(); - eventParser.parse(events); - EXPECT_TRUE(eventParser.getwaitOnConsumed()); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); SleepForFC(); EXPECT_EQ(NotificationHelper::RemoveNotifications(), ERR_OK); std::vector> notifications; @@ -706,9 +706,9 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitons_00100, Function | Medium SleepForFC(); EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber, info), ERR_OK); events = subscriber.GetEvents(); - eventParser.parse(events); - EXPECT_TRUE(eventParser.getWaitOnCanceled()); - EXPECT_TRUE(eventParser.getWaitOnCanceledWithSortingMapAndDeleteReason()); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + EXPECT_TRUE(eventParser.GetWaitOnCanceledWithSortingMapAndDeleteReason()); subscriber.ClearEvents(); SleepForFC(); } @@ -730,11 +730,11 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitons_00200, Function | Medium SleepForFC(); EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber, info), ERR_OK); std::list> events = subscriber.GetEvents(); - eventParser.parse(events); - EXPECT_FALSE(eventParser.getwaitOnConsumed()); - EXPECT_FALSE(eventParser.getWaitOnConsumedWithSortingMap()); - EXPECT_FALSE(eventParser.getWaitOnCanceled()); - EXPECT_FALSE(eventParser.getWaitOnCanceledWithSortingMapAndDeleteReason()); + eventParser.Parse(events); + EXPECT_FALSE(eventParser.GetWaitOnConsumed()); + EXPECT_FALSE(eventParser.GetWaitOnConsumedWithSortingMap()); + EXPECT_FALSE(eventParser.GetWaitOnCanceled()); + EXPECT_FALSE(eventParser.GetWaitOnCanceledWithSortingMapAndDeleteReason()); subscriber.ClearEvents(); SleepForFC(); } @@ -874,21 +874,21 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_CancelNotificationById_00100, Function | Med SleepForFC(); std::list> events = subscriber.GetEvents(); - eventParser.parse(events); - EXPECT_TRUE(eventParser.getwaitOnConsumed()); - EXPECT_TRUE(eventParser.getWaitOnConsumedWithSortingMap()); - EXPECT_TRUE(eventParser.getWaitOnCanceled()); - EXPECT_EQ(eventParser.getOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); - EXPECT_EQ(eventParser.getOnConsumedReq()[0]->GetId(), 1); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + EXPECT_TRUE(eventParser.GetWaitOnConsumedWithSortingMap()); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 1); std::stringstream stream; stream << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 1; std::string notificationKey = stream.str(); NotificationSorting sorting; - EXPECT_EQ(eventParser.getOnCanceledReq()[0]->GetKey(), notificationKey); - EXPECT_EQ(eventParser.getOnCanceledWithSortingMapReq()[0]->GetKey(), notificationKey); - EXPECT_TRUE(eventParser.getOnConsumedWithSortingMapSor()[0]->GetNotificationSorting(notificationKey, sorting)); + EXPECT_EQ(eventParser.GetOnCanceledReq()[0]->GetKey(), notificationKey); + EXPECT_EQ(eventParser.GetOnCanceledWithSortingMapReq()[0]->GetKey(), notificationKey); + EXPECT_TRUE(eventParser.GetOnConsumedWithSortingMapSor()[0]->GetNotificationSorting(notificationKey, sorting)); EXPECT_EQ(sorting.GetKey().c_str(), notificationKey); - EXPECT_EQ(eventParser.getOnCanceledWithSortingMapDelRea()[0], APP_CANCEL_REASON_DELETE); + EXPECT_EQ(eventParser.GetOnCanceledWithSortingMapDelRea()[0], APP_CANCEL_REASON_DELETE); subscriber.ClearEvents(); SleepForFC(); } @@ -919,19 +919,19 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_CancelNotificationById_00200, Function | Med int32_t id = 0; SleepForFC(); - eventParser.setWaitOnCanceled(false); - eventParser.setWaitOnCanceledWithSortingMapAndDeleteReason(false); + eventParser.SetWaitOnCanceled(false); + eventParser.SetWaitOnCanceledWithSortingMapAndDeleteReason(false); EXPECT_EQ(NotificationHelper::CancelNotification(NOTIFICATION_LABEL_0, id), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); SleepForFC(); EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber, info), ERR_OK); SleepForFC(); std::list> events = subscriber.GetEvents(); - eventParser.parse(events); - EXPECT_TRUE(eventParser.getwaitOnConsumed()); - EXPECT_TRUE(eventParser.getWaitOnConsumedWithSortingMap()); - EXPECT_FALSE(eventParser.getWaitOnCanceled()); - EXPECT_FALSE(eventParser.getWaitOnCanceledWithSortingMapAndDeleteReason()); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + EXPECT_TRUE(eventParser.GetWaitOnConsumedWithSortingMap()); + EXPECT_FALSE(eventParser.GetWaitOnCanceled()); + EXPECT_FALSE(eventParser.GetWaitOnCanceledWithSortingMapAndDeleteReason()); subscriber.ClearEvents(); SleepForFC(); } @@ -969,33 +969,33 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_CancelAllNotifications_00100, Function | Med std::list> events = subscriber.GetEvents(); EventParser eventParser; - eventParser.parse(events); - EXPECT_TRUE(eventParser.getwaitOnConsumed()); - EXPECT_TRUE(eventParser.getWaitOnConsumedWithSortingMap()); - EXPECT_TRUE(eventParser.getWaitOnCanceled()); - EXPECT_EQ(eventParser.getOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); - EXPECT_EQ(eventParser.getOnConsumedReq()[0]->GetId(), 0); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + EXPECT_TRUE(eventParser.GetWaitOnConsumedWithSortingMap()); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 0); std::stringstream stream0; stream0 << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0; std::string notificationKey0 = stream0.str(); NotificationSorting sorting0; - EXPECT_EQ(eventParser.getOnCanceledReq()[0]->GetKey(), notificationKey0); - EXPECT_EQ(eventParser.getOnCanceledWithSortingMapReq()[0]->GetKey(), notificationKey0); - EXPECT_TRUE(eventParser.getOnConsumedWithSortingMapSor()[0]->GetNotificationSorting(notificationKey0, sorting0)); + EXPECT_EQ(eventParser.GetOnCanceledReq()[0]->GetKey(), notificationKey0); + EXPECT_EQ(eventParser.GetOnCanceledWithSortingMapReq()[0]->GetKey(), notificationKey0); + EXPECT_TRUE(eventParser.GetOnConsumedWithSortingMapSor()[0]->GetNotificationSorting(notificationKey0, sorting0)); EXPECT_EQ(sorting0.GetKey().c_str(), notificationKey0); - EXPECT_EQ(eventParser.getOnCanceledWithSortingMapDelRea()[0], APP_CANCEL_ALL_REASON_DELETE); + EXPECT_EQ(eventParser.GetOnCanceledWithSortingMapDelRea()[0], APP_CANCEL_ALL_REASON_DELETE); - EXPECT_EQ(eventParser.getOnConsumedReq()[1]->GetLabel().c_str(), NOTIFICATION_LABEL_1); - EXPECT_EQ(eventParser.getOnConsumedReq()[1]->GetId(), 1); + EXPECT_EQ(eventParser.GetOnConsumedReq()[1]->GetLabel().c_str(), NOTIFICATION_LABEL_1); + EXPECT_EQ(eventParser.GetOnConsumedReq()[1]->GetId(), 1); std::stringstream stream1; stream1 << UID << KEY_SPLITER << NOTIFICATION_LABEL_1 << KEY_SPLITER << 1; std::string notificationKey1 = stream1.str(); NotificationSorting sorting1; - EXPECT_EQ(eventParser.getOnCanceledReq()[1]->GetKey(), notificationKey1); - EXPECT_EQ(eventParser.getOnCanceledWithSortingMapReq()[1]->GetKey(), notificationKey1); - EXPECT_TRUE(eventParser.getOnConsumedWithSortingMapSor()[1]->GetNotificationSorting(notificationKey1, sorting1)); + EXPECT_EQ(eventParser.GetOnCanceledReq()[1]->GetKey(), notificationKey1); + EXPECT_EQ(eventParser.GetOnCanceledWithSortingMapReq()[1]->GetKey(), notificationKey1); + EXPECT_TRUE(eventParser.GetOnConsumedWithSortingMapSor()[1]->GetNotificationSorting(notificationKey1, sorting1)); EXPECT_EQ(sorting1.GetKey().c_str(), notificationKey1); - EXPECT_EQ(eventParser.getOnCanceledWithSortingMapDelRea()[1], APP_CANCEL_ALL_REASON_DELETE); + EXPECT_EQ(eventParser.GetOnCanceledWithSortingMapDelRea()[1], APP_CANCEL_ALL_REASON_DELETE); subscriber.ClearEvents(); SleepForFC(); @@ -1036,11 +1036,11 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishSoundNotification_00100, Function | M std::list> events = subscriber.GetEvents(); EventParser eventParser; - eventParser.parse(events); - EXPECT_TRUE(eventParser.getwaitOnConsumed()); - EXPECT_TRUE(eventParser.getWaitOnConsumedWithSortingMap()); - EXPECT_TRUE(eventParser.getWaitOnCanceled()); - EXPECT_TRUE(eventParser.getWaitOnCanceledWithSortingMapAndDeleteReason()); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + EXPECT_TRUE(eventParser.GetWaitOnConsumedWithSortingMap()); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + EXPECT_TRUE(eventParser.GetWaitOnCanceledWithSortingMapAndDeleteReason()); subscriber.ClearEvents(); SleepForFC(); } @@ -1079,11 +1079,11 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishVibrationNotification_00100, Function SleepForFC(); std::list> events = subscriber.GetEvents(); EventParser eventParser; - eventParser.parse(events); - EXPECT_TRUE(eventParser.getwaitOnConsumed()); - EXPECT_TRUE(eventParser.getWaitOnConsumedWithSortingMap()); - EXPECT_TRUE(eventParser.getWaitOnCanceled()); - EXPECT_TRUE(eventParser.getWaitOnCanceledWithSortingMapAndDeleteReason()); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + EXPECT_TRUE(eventParser.GetWaitOnConsumedWithSortingMap()); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + EXPECT_TRUE(eventParser.GetWaitOnCanceledWithSortingMapAndDeleteReason()); subscriber.ClearEvents(); SleepForFC(); } diff --git a/interfaces/kits/napi/ans/src/init.cpp b/interfaces/kits/napi/ans/src/init.cpp index e72eddaec..358865aa3 100644 --- a/interfaces/kits/napi/ans/src/init.cpp +++ b/interfaces/kits/napi/ans/src/init.cpp @@ -20,6 +20,7 @@ #include "disturb_mode.h" #include "enable_notification.h" #include "get_active.h" +#include "pixel_map_napi.h" #include "publish.h" #include "remove.h" #include "slot.h" @@ -82,6 +83,8 @@ static napi_value Init(napi_env env, napi_value exports) */ NotificationInit(env, exports); ConstantInit(env, exports); + OHOS::Media::PixelMapNapi::Init(env, exports); + return exports; } -- Gitee From 3cb7789de525890d409129ff28b06f208e8bd4fc Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Wed, 24 Nov 2021 16:25:02 +0000 Subject: [PATCH 2/3] Add permission check Signed-off-by: zhaoyuan17 --- .../common/include/ans_permission_define.h | 28 -- frameworks/ans/test/moduletest/BUILD.gn | 8 - .../test/moduletest/mock/permission_kit.cpp | 90 ---- services/ans/BUILD.gn | 1 - .../ans/src/advanced_notification_service.cpp | 67 ++- services/ans/test/unittest/BUILD.gn | 2 - .../ans/test/unittest/mock/permission_kit.cpp | 90 ---- services/test/moduletest/BUILD.gn | 2 - .../test/moduletest/mock/permission_kit.cpp | 90 ---- .../include/notificationfuzzconfigparser.h | 6 +- .../include/notificationfuzztestmanager.h | 49 +- .../include/notificationgetparam.h | 186 +------ .../src/notificationfuzztestmanager.cpp | 73 ++- .../src/notificationgetparam.cpp | 461 ++---------------- 14 files changed, 149 insertions(+), 1004 deletions(-) delete mode 100644 frameworks/ans/core/common/include/ans_permission_define.h delete mode 100644 frameworks/ans/test/moduletest/mock/permission_kit.cpp delete mode 100644 services/ans/test/unittest/mock/permission_kit.cpp delete mode 100644 services/test/moduletest/mock/permission_kit.cpp diff --git a/frameworks/ans/core/common/include/ans_permission_define.h b/frameworks/ans/core/common/include/ans_permission_define.h deleted file mode 100644 index 058c75d2c..000000000 --- a/frameworks/ans/core/common/include/ans_permission_define.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_PERMISSION_DEFINE_H -#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_PERMISSION_DEFINE_H - -#include - -namespace OHOS { -namespace Notification { -// Permission -const std::string ANS_PERMISSION_CONTROLLER = "ohos.permission.NOTIFICATION_CONTROLLER"; -} // namespace Notification -} // namespace OHOS - -#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_PERMISSION_DEFINE_H diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index 85cc90dc9..f2edf4096 100755 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -82,7 +82,6 @@ ohos_moduletest("ans_fw_module_test") { "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", - "mock/permission_kit.cpp", ] configs = [ "//utils/native/base:utils_config" ] @@ -113,7 +112,6 @@ ohos_moduletest("ans_fw_module_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] @@ -165,7 +163,6 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", - "mock/permission_kit.cpp", ] configs = [ "//utils/native/base:utils_config" ] @@ -196,7 +193,6 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] @@ -247,7 +243,6 @@ ohos_moduletest("ans_innerkits_module_slot_test") { "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", - "mock/permission_kit.cpp", ] configs = [ "//utils/native/base:utils_config" ] @@ -276,7 +271,6 @@ ohos_moduletest("ans_innerkits_module_slot_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] @@ -327,7 +321,6 @@ ohos_moduletest("ans_innerkits_module_setting_test") { "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", - "mock/permission_kit.cpp", ] configs = [ "//utils/native/base:utils_config" ] @@ -356,7 +349,6 @@ ohos_moduletest("ans_innerkits_module_setting_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/frameworks/ans/test/moduletest/mock/permission_kit.cpp b/frameworks/ans/test/moduletest/mock/permission_kit.cpp deleted file mode 100644 index 36855b9de..000000000 --- a/frameworks/ans/test/moduletest/mock/permission_kit.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "permission/permission_kit.h" - -namespace OHOS { -namespace Security { -namespace Permission { -using namespace std; - -int PermissionKit::VerifyPermission(const string &bundleName, const string &permissionName, int userId) -{ - return TypePermissionState::PERMISSION_GRANTED; -} - -bool PermissionKit::CanRequestPermission(const string &bundleName, const string &permissionName, int userId) -{ - return 0; -} - -int PermissionKit::GrantUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) -{ - return 0; -} - -int PermissionKit::GrantSystemGrantedPermission(const string &bundleName, const string &permissionName) -{ - return 0; -} - -int PermissionKit::RevokeUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) -{ - return 0; -} - -int PermissionKit::RevokeSystemGrantedPermission(const string &bundleName, const string &permissionName) -{ - return 0; -} - -int PermissionKit::AddUserGrantedReqPermissions( - const string &bundleName, const std::vector &permList, int userId) -{ - return 0; -} - -int PermissionKit::AddSystemGrantedReqPermissions(const string &bundleName, const std::vector &permList) -{ - return 0; -} - -int PermissionKit::RemoveUserGrantedReqPermissions(const string &bundleName, int userId) -{ - return 0; -} - -int PermissionKit::RemoveSystemGrantedReqPermissions(const string &bundleName) -{ - return 0; -} - -int PermissionKit::AddDefPermissions(const std::vector &permList) -{ - return 0; -} - -int PermissionKit::RemoveDefPermissions(const string &bundleName) -{ - return 0; -} - -int PermissionKit::GetDefPermission(const string &permissionName, PermissionDef &permissionDefResult) -{ - return 0; -} -} // namespace Permission -} // namespace Security -} // namespace OHOS \ No newline at end of file diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 249f437bb..1f8e18f94 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -56,7 +56,6 @@ ohos_shared_library("libans") { "${core_path}:ans_core", "${frameworks_path}/ans/native:ans_innerkits", "${frameworks_path}/wantagent:wantagent_innerkits", - "//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard", "//foundation/aafwk/standard/services/abilitymgr:abilityms", "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner", "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index cde4d34cd..538f26bfa 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -22,7 +22,6 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" -#include "ans_permission_define.h" #include "bundle_manager_helper.h" #include "ipc_skeleton.h" #include "notification_constant.h" @@ -31,7 +30,6 @@ #include "notification_slot.h" #include "notification_slot_filter.h" #include "notification_subscriber_manager.h" -#include "permission/permission_kit.h" #include "permission_filter.h" namespace OHOS { @@ -828,6 +826,10 @@ ErrCode AdvancedNotificationService::GetSlotsByBundle( return ERR_ANS_NON_SYSTEM_APP; } + if (!CheckPermission(GetClientBundleName())) { + return ERR_ANS_PERMISSION_DENIED; + } + sptr bundle = GenerateValidBundleOption(bundleOption); if (bundle == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -853,6 +855,10 @@ ErrCode AdvancedNotificationService::UpdateSlots( return ERR_ANS_NON_SYSTEM_APP; } + if (!CheckPermission(GetClientBundleName())) { + return ERR_ANS_PERMISSION_DENIED; + } + sptr bundle = GenerateValidBundleOption(bundleOption); if (bundle == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -1012,6 +1018,10 @@ ErrCode AdvancedNotificationService::Subscribe( return ERR_ANS_NON_SYSTEM_APP; } + if (!CheckPermission(GetClientBundleName())) { + return ERR_ANS_PERMISSION_DENIED; + } + return NotificationSubscriberManager::GetInstance()->AddSubscriber(subscriber, info); } @@ -1024,6 +1034,10 @@ ErrCode AdvancedNotificationService::Unsubscribe( return ERR_ANS_INVALID_PARAM; } + if (!CheckPermission(GetClientBundleName())) { + return ERR_ANS_PERMISSION_DENIED; + } + if (!IsSystemApp()) { ANS_LOGE("Client is not a system app"); return ERR_ANS_NON_SYSTEM_APP; @@ -1079,6 +1093,10 @@ ErrCode AdvancedNotificationService::GetAllActiveNotifications(std::vectorPostSyncTask(std::bind([&]() { notifications.clear(); @@ -1154,6 +1172,10 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForSpecialBundle( return ERR_ANS_NON_SYSTEM_APP; } + if (!CheckPermission(GetClientBundleName())) { + return ERR_ANS_PERMISSION_DENIED; + } + sptr bundle = GenerateValidBundleOption(bundleOption); if (bundle == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -1513,6 +1535,10 @@ ErrCode AdvancedNotificationService::RemoveNotification( return ERR_ANS_NON_SYSTEM_APP; } + if (!CheckPermission(GetClientBundleName())) { + return ERR_ANS_PERMISSION_DENIED; + } + sptr bundle = GenerateValidBundleOption(bundleOption); if (bundle == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -1557,6 +1583,10 @@ ErrCode AdvancedNotificationService::RemoveAllNotifications(const sptr bundle = GenerateValidBundleOption(bundleOption); if (bundle == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -1792,12 +1822,21 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDate(const sptrGetBeginDate()); int64_t endDate = ResetSeconds(date->GetEndDate()); - if (date->GetDoNotDisturbType() == NotificationConstant::DoNotDisturbType::NONE) { - beginDate = 0; - endDate = 0; - } - if (date->GetDoNotDisturbType() == NotificationConstant::DoNotDisturbType::ONCE) { - AdjustDateForDndTypeOnce(beginDate, endDate); + switch (date->GetDoNotDisturbType()) { + case NotificationConstant::DoNotDisturbType::NONE: + beginDate = 0; + endDate = 0; + break; + case NotificationConstant::DoNotDisturbType::ONCE: + AdjustDateForDndTypeOnce(beginDate, endDate); + break; + case NotificationConstant::DoNotDisturbType::CLEARLY: + if (beginDate >= endDate) { + return ERR_ANS_INVALID_PARAM; + } + break; + default: + break; } const sptr newConfig = new NotificationDoNotDisturbDate( @@ -1857,18 +1896,12 @@ ErrCode AdvancedNotificationService::DoesSupportDoNotDisturbMode(bool &doesSuppo bool AdvancedNotificationService::CheckPermission(const std::string &bundleName) { ANS_LOGD("%{public}s", __FUNCTION__); - bool isGranted = false; if (bundleName.empty()) { ANS_LOGE("Bundle name is empty."); - return isGranted; - } - int result = Security::Permission::PermissionKit::VerifyPermission(bundleName, ANS_PERMISSION_CONTROLLER, 0); - if (Security::Permission::TypePermissionState::PERMISSION_GRANTED == result) { - isGranted = true; - } else { - ANS_LOGE("Permission granted failed."); + return false; } - return isGranted; + // Add permission check in future + return true; } } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index d131b5f6f..b404f8907 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -58,7 +58,6 @@ ohos_unittest("ans_unit_test") { "mock/mock_event_handler.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", - "mock/permission_kit.cpp", "notification_preferences_database_test.cpp", "notification_preferences_test.cpp", "notification_slot_filter_test.cpp", @@ -86,7 +85,6 @@ ohos_unittest("ans_unit_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/services/ans/test/unittest/mock/permission_kit.cpp b/services/ans/test/unittest/mock/permission_kit.cpp deleted file mode 100644 index 36855b9de..000000000 --- a/services/ans/test/unittest/mock/permission_kit.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "permission/permission_kit.h" - -namespace OHOS { -namespace Security { -namespace Permission { -using namespace std; - -int PermissionKit::VerifyPermission(const string &bundleName, const string &permissionName, int userId) -{ - return TypePermissionState::PERMISSION_GRANTED; -} - -bool PermissionKit::CanRequestPermission(const string &bundleName, const string &permissionName, int userId) -{ - return 0; -} - -int PermissionKit::GrantUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) -{ - return 0; -} - -int PermissionKit::GrantSystemGrantedPermission(const string &bundleName, const string &permissionName) -{ - return 0; -} - -int PermissionKit::RevokeUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) -{ - return 0; -} - -int PermissionKit::RevokeSystemGrantedPermission(const string &bundleName, const string &permissionName) -{ - return 0; -} - -int PermissionKit::AddUserGrantedReqPermissions( - const string &bundleName, const std::vector &permList, int userId) -{ - return 0; -} - -int PermissionKit::AddSystemGrantedReqPermissions(const string &bundleName, const std::vector &permList) -{ - return 0; -} - -int PermissionKit::RemoveUserGrantedReqPermissions(const string &bundleName, int userId) -{ - return 0; -} - -int PermissionKit::RemoveSystemGrantedReqPermissions(const string &bundleName) -{ - return 0; -} - -int PermissionKit::AddDefPermissions(const std::vector &permList) -{ - return 0; -} - -int PermissionKit::RemoveDefPermissions(const string &bundleName) -{ - return 0; -} - -int PermissionKit::GetDefPermission(const string &permissionName, PermissionDef &permissionDefResult) -{ - return 0; -} -} // namespace Permission -} // namespace Security -} // namespace OHOS \ No newline at end of file diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 02ebb5b1e..0440b8b95 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -57,7 +57,6 @@ ohos_moduletest("ans_module_test") { "mock/mock_event_handler.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", - "mock/permission_kit.cpp", ] configs = [ "//utils/native/base:utils_config" ] @@ -86,7 +85,6 @@ ohos_moduletest("ans_module_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/services/test/moduletest/mock/permission_kit.cpp b/services/test/moduletest/mock/permission_kit.cpp deleted file mode 100644 index 36855b9de..000000000 --- a/services/test/moduletest/mock/permission_kit.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "permission/permission_kit.h" - -namespace OHOS { -namespace Security { -namespace Permission { -using namespace std; - -int PermissionKit::VerifyPermission(const string &bundleName, const string &permissionName, int userId) -{ - return TypePermissionState::PERMISSION_GRANTED; -} - -bool PermissionKit::CanRequestPermission(const string &bundleName, const string &permissionName, int userId) -{ - return 0; -} - -int PermissionKit::GrantUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) -{ - return 0; -} - -int PermissionKit::GrantSystemGrantedPermission(const string &bundleName, const string &permissionName) -{ - return 0; -} - -int PermissionKit::RevokeUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) -{ - return 0; -} - -int PermissionKit::RevokeSystemGrantedPermission(const string &bundleName, const string &permissionName) -{ - return 0; -} - -int PermissionKit::AddUserGrantedReqPermissions( - const string &bundleName, const std::vector &permList, int userId) -{ - return 0; -} - -int PermissionKit::AddSystemGrantedReqPermissions(const string &bundleName, const std::vector &permList) -{ - return 0; -} - -int PermissionKit::RemoveUserGrantedReqPermissions(const string &bundleName, int userId) -{ - return 0; -} - -int PermissionKit::RemoveSystemGrantedReqPermissions(const string &bundleName) -{ - return 0; -} - -int PermissionKit::AddDefPermissions(const std::vector &permList) -{ - return 0; -} - -int PermissionKit::RemoveDefPermissions(const string &bundleName) -{ - return 0; -} - -int PermissionKit::GetDefPermission(const string &permissionName, PermissionDef &permissionDefResult) -{ - return 0; -} -} // namespace Permission -} // namespace Security -} // namespace OHOS \ No newline at end of file diff --git a/test/resource/notificationfuzztest/include/notificationfuzzconfigparser.h b/test/resource/notificationfuzztest/include/notificationfuzzconfigparser.h index d6d96c219..d0a492b1d 100644 --- a/test/resource/notificationfuzztest/include/notificationfuzzconfigparser.h +++ b/test/resource/notificationfuzztest/include/notificationfuzzconfigparser.h @@ -15,8 +15,8 @@ #ifndef NOTIFICATION_FUZZ_CONFIG_PARSER_H #define NOTIFICATION_FUZZ_CONFIG_PARSER_H -#include #include +#include #include #include @@ -31,9 +31,9 @@ struct FuzzTestData { std::vector methodVec {}; }; -class FuzzConfigParser { +class NotificationFuzzConfigParser { public: - void ParseFromFile4FuzzTest(const std::string &path, FuzzTestData &ftd) + void ParseFromFile4FuzzTest(const std::string &path, FuzzTestData &ftd) const { std::cout << __func__ << std::endl; if (path.empty()) { diff --git a/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h b/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h index c17922ac6..cce89899f 100644 --- a/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h +++ b/test/resource/notificationfuzztest/include/notificationfuzztestmanager.h @@ -28,11 +28,11 @@ public: {} static Ptr GetInstance() { - if (instance_ == nullptr) { - auto pObj = new NotificationFuzzTestManager(); - instance_ = std::shared_ptr(pObj); + if (instance == nullptr) { + NotificationFuzzTestManager* pObj = new NotificationFuzzTestManager(); + instance = std::shared_ptr(pObj); } - return instance_; + return instance; } void StartFuzzTest(); @@ -41,47 +41,16 @@ private: void SetJsonFunction(std::string functionName); void SetCycle(uint16_t cycle); NotificationFuzzTestManager(); - NotificationFuzzTestManager(NotificationFuzzTestManager &) = delete; + NotificationFuzzTestManager(const NotificationFuzzTestManager &) = delete; NotificationFuzzTestManager &operator=(const NotificationFuzzTestManager &) = delete; - static Ptr instance_; - uint16_t cycle_; + static Ptr instance; + uint16_t cycle_ = 0; std::unordered_map remainderMap_ {}; std::unordered_map> callFunctionMap_ {}; const int COLOR_R = 100; const int COLOR_G = 100; const int COLOR_B = 100; - - void RegisterAsyncCommonEventResult(); - void RegisterCommonEventData(); - void RegisterCommonEventManager(); - void RegisterCommonEventPublishInfo(); - void RegisterCommonEventSubscribeInfo(); - void RegisterCommonEventSubscriber(); - void RegisterCommonEventSupport(); - void RegisterMatchingSkills(); - void RegisterDumper(); - void RegisterEventHandler(); - void RegisterEventQueue(); - void RegisterEventRunner(); - void RegisterFileDescriptorListener(); - void RegisterInnerEvent(); - void RegisterEventRunnerNativeImplement(); - void RegisterAbilityManager(); - void RegisterWantParams(); - void RegisterWant(); - void RegisterElementName(); - void RegisterBundleMgrProxy(); - - void RegisterOHOSApplication(); - void RegisterAbility(); - void RegisterDataAbilityHelper(); - void RegisterDataUriUtils(); - void RegisterLifeCycle(); - - void RegisterAbilityContext(); - void RegisterProcessInfo(); - void RegisterNotificationHelper(); void RegisterNotificationSorting(); void RegisterNotificationSortingMap(); @@ -93,8 +62,8 @@ private: void RegisterIAbilityContinuation(); void RegisterRevocable(); void RegisterTaskDispatcher(); - void RegisterAbility_(); - void RegisterAbilityContext_(); + void RegisterAbility(); + void RegisterAbilityContext(); void RegisterContext(); void RegisterAbilityLifecycleCallbacks(); void RegisterIAbilityManager(); diff --git a/test/resource/notificationfuzztest/include/notificationgetparam.h b/test/resource/notificationfuzztest/include/notificationgetparam.h index 2216a49f6..b18017d60 100644 --- a/test/resource/notificationfuzztest/include/notificationgetparam.h +++ b/test/resource/notificationfuzztest/include/notificationgetparam.h @@ -14,54 +14,40 @@ */ #ifndef NOTIFICATION_GET_PARAM_H #define NOTIFICATION_GET_PARAM_H +#include #include +#include +#include + #include "ability.h" #include "ability_handler.h" #include "ability_manager.h" #include "ability_manager_interface.h" -#include "async_common_event_result.h" -#include "bundle_info.h" -#include "common_event_manager.h" -#include "common_event_data.h" -#include "common_event_publish_info.h" -#include "common_event_subscribe_info.h" -#include "common_event_subscriber.h" -#include "common_event_support.h" +#include "ability_manager_service.h" +#include "base_task_dispatcher.h" #include "data_uri_utils.h" #include "element_name.h" -#include "event_handler.h" #include "event_runner.h" -#include "inner_event.h" -#include "key_event.h" -#include "logger.h" -#include "matching_skills.h" -#include "module_info.h" -#include "native_implement_eventhandler.h" -#include "pac_map.h" -#include "parcel.h" -#include "patterns_matcher.h" +#include "launcher_ability_info.h" +#include "launcher_service.h" +#include "spec_task_dispatcher.h" +#include "task_dispatcher.h" +#include "task_dispatcher_context.h" #include "uri.h" #include "want.h" -#include "bundle_mgr_proxy.h" -#include "notification_sorting_map.h" -#include "notification_helper.h" -#include "want_agent_helper.h" -#include "notification.h" + #ifdef PRINT_LOG #undef PRINT_LOG #endif -#include "launcher_service.h" -#include "launcher_ability_info.h" -#include "task_dispatcher.h" -#include "base_task_dispatcher.h" -#include "spec_task_dispatcher.h" -#include "task_dispatcher_context.h" -#include "ability_manager_service.h" + +#include "notification.h" +#include "notification_helper.h" +#include "notification_sorting_map.h" +#include "want_agent_helper.h" using Want = OHOS::AAFwk::Want; namespace OHOS { namespace Notification { -class TestDumper; bool GetBoolParam(); uint8_t GetU8Param(); unsigned int GetUIntParam(); @@ -97,79 +83,16 @@ std::vector GetS8VectorParam(); std::vector GetS16VectorParam(); std::vector GetS32VectorParam(); std::vector GetS64VectorParam(); - -std::shared_ptr GetParamParcel(); std::shared_ptr GetParamWant(); -std::vector> GetParamWantVector(); -OHOS::AAFwk::Operation GetParamOperation(); -std::shared_ptr GetParamAsyncCommonEventResult(); -std::shared_ptr GetParamCommonEventData(); -std::shared_ptr GetParamCommonEventManager(); -std::shared_ptr GetParamCommonEventPublishInfo(); -std::shared_ptr GetParamCommonEventSubscribeInfo(); -std::shared_ptr GetParamCommonEventSubscriber(); -std::shared_ptr GetParamCommonEventSupport(); -std::shared_ptr GetParamMatchingSkills(); sptr GetParamSptrRemote(); std::shared_ptr GetParamEventRunner(); -std::shared_ptr GetParamEventHandler(); -std::shared_ptr GetParamEventQueue(); -std::shared_ptr GetParamEventRunnerNativeImplement(); -std::shared_ptr GetParamFileDescriptorListener(); -std::shared_ptr GetParamLogger(); -OHOS::AppExecFwk::EventQueue::Priority GetParamPriority(); -TestDumper GetParamDumper(); -OHOS::AppExecFwk::InnerEvent::Pointer GetParamInnerEvent(); -OHOS::AppExecFwk::InnerEvent::Callback GetParamCallback(); -OHOS::AppExecFwk::InnerEvent::TimePoint GetParamTimePoint(); -OHOS::EventFwk::CommonEventSubscribeInfo::ThreadMode GetParamThreadMode(); - -std::shared_ptr GetParamAbilityContext(); -std::shared_ptr GetParamIAbilityEvent(); -sptr GetParamAbilityThread(); -std::shared_ptr GetParamAbilityHandler(); -std::shared_ptr GetParamAbilityStartSetting(); std::shared_ptr GetParamAbility(); -std::shared_ptr GetParamOHOSApplication(); -std::shared_ptr GetParamKeyEvent(); -OHOS::Uri GetParamUri(); - -NativeRdb::ValuesBucket GetParamValuesBucket(); -OHOS::AppExecFwk::Configuration GetParamConfiguration(); -NativeRdb::DataAbilityPredicates GetParamDataAbilityPredicates(); -OHOS::AppExecFwk::PacMap GetParamPacMap(); -std::shared_ptr GetParamComponentContainer(); -sptr GetParamIAbilityConnection(); - -std::shared_ptr GetParamProcessInfo(); -std::shared_ptr GetParamDataUriUtils(); -std::shared_ptr GetParamDataAbilityHelper(); -std::shared_ptr GetParamLifeCycle(); -OHOS::AppExecFwk::LifeCycle::Event GetParamLifeCycleEvent(); -std::shared_ptr GetParamElementName(); std::shared_ptr GetParamWantParams(); -std::shared_ptr GetParamAbilityManager(); -OHOS::AAFwk::PatternsMatcher GetParamPatternsMatcher(); -OHOS::AAFwk::MatchType GetParamMatchType(); std::shared_ptr GetParamContext(); - -std::shared_ptr GetParamBundleMgrProxy(); OHOS::AppExecFwk::ApplicationFlag GetParamApplicationFlag(); OHOS::AppExecFwk::ApplicationInfo GetParamApplicationInfo(); -std::vector GetParamApplicationInfoVector(); -OHOS::AppExecFwk::BundleFlag GetParamBundleFlag(); -OHOS::AppExecFwk::BundleInfo GetParamBundleInfo(); OHOS::AppExecFwk::AbilityInfo GetParamAbilityInfo(); -std::vector GetParamBundleInfoVector(); -OHOS::AppExecFwk::HapModuleInfo GetParamHapModuleInfo(); -OHOS::AppExecFwk::PermissionDef GetParamPermissionDef(); -std::vector GetParamPermissionDefVector(); -OHOS::AppExecFwk::IBundleMgr::Message GetParamIBundleMgrMessage(); -OHOS::MessageParcel GetParamMessageParcel(); -OHOS::AppExecFwk::DumpFlag GetParamDumpFlag(); -sptr GetParamICleanCacheCallback(); sptr GetParamIBundleStatusCallback(); - std::shared_ptr GetParamNotificationSorting(); std::vector GetParamNotificationSortingVector(); std::shared_ptr GetParamNotificationSortingMap(); @@ -281,74 +204,7 @@ public: } }; -class TestCommonEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber { -public: - TestCommonEventSubscriber() - {} - ~TestCommonEventSubscriber() - {} - virtual void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) - { - printf("Fuzz Test Reveive Event\n"); - } -}; - -class TestDumper : public OHOS::AppExecFwk::Dumper { -public: - void Dump(const std::string &message) - { - return; - } - std::string GetTag() - { - return GetStringParam(); - } -}; - -class TestFileDescriptorListener : public OHOS::AppExecFwk::FileDescriptorListener { -public: - TestFileDescriptorListener() - {} - ~TestFileDescriptorListener() - {} -}; -class TestIAbilityConnection : public OHOS::AAFwk::IAbilityConnection { -public: - void OnAbilityConnectDone( - const OHOS::AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override - {} - void OnAbilityDisconnectDone(const OHOS::AppExecFwk::ElementName &element, int resultCode) override - {} - virtual ~TestIAbilityConnection() - {} -}; - -class TestAbilityEvent : public OHOS::AppExecFwk::IAbilityEvent { -public: - virtual void OnBackPressed() - { - printf("Fuzz Test Back Pressed."); - } -}; - -class TestLogger : public OHOS::AppExecFwk::Logger { -public: - void Log(const std::string &line) - {} - virtual ~TestLogger() - {} -}; - -class TestICleanCacheCallback : public OHOS::AppExecFwk::ICleanCacheCallback { -public: - TestICleanCacheCallback() - {} - void OnCleanCacheFinished(bool succeeded) override - {} - virtual ~TestICleanCacheCallback() - {} -}; class TestIBundleStatusCallback : public OHOS::AppExecFwk::IBundleStatusCallback { public: @@ -370,12 +226,12 @@ public: void OnConnected() override { std::cout << "TestAnsSubscriber OnConnected" << std::endl; - mutex_.unlock(); + mutex.unlock(); } void OnDisconnected() override { std::cout << "TestAnsSubscriber OnDisconnected" << std::endl; - mutex_.unlock(); + mutex.unlock(); } void OnDied() override {} @@ -394,8 +250,8 @@ public: const std::shared_ptr &sortingMap) override {} -private: - static std::mutex mutex_; +public: + static std::mutex mutex; }; class TestCompletedCallback : public OHOS::Notification::WantAgent::CompletedCallback { diff --git a/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp b/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp index edb736b92..b2c7ef219 100644 --- a/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp +++ b/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp @@ -12,21 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define private public -#define protected public #include "datetime_ex.h" #include "../include/notificationfuzzconfigparser.h" #include "../include/notificationfuzztestmanager.h" #include "../include/notificationgetparam.h" -#undef private -#undef protected using namespace OHOS::AppExecFwk; using namespace OHOS::EventFwk; namespace OHOS { namespace Notification { -std::shared_ptr NotificationFuzzTestManager::instance_ = nullptr; +std::shared_ptr NotificationFuzzTestManager::instance = nullptr; // RegisterNotificationHelper void NotificationFuzzTestManager::RegisterNotificationHelper() { @@ -163,37 +159,37 @@ void NotificationFuzzTestManager::RegisterNotificationHelper() }); callFunctionMap_.emplace("NotificationHelperSubscribeNotificationNotificationSubscriber", []() { - TestAnsSubscriber::mutex_.lock(); + TestAnsSubscriber::mutex.lock(); std::shared_ptr subscriber = GetParamNotificationSubscriber(); struct tm start = {0}; OHOS::GetSystemCurrentTime(&start); OHOS::Notification::NotificationHelper::SubscribeNotification(*subscriber); struct tm end = {0}; int64_t timeout = 0; - while (!TestAnsSubscriber::mutex_.try_lock()) { + while (!TestAnsSubscriber::mutex.try_lock()) { OHOS::GetSystemCurrentTime(&end); timeout = OHOS::GetSecondsBetween(start, end); if (timeout >= 5L) { break; } } - TestAnsSubscriber::mutex_.unlock(); - TestAnsSubscriber::mutex_.lock(); + TestAnsSubscriber::mutex.unlock(); + TestAnsSubscriber::mutex.lock(); OHOS::GetSystemCurrentTime(&start); OHOS::Notification::NotificationHelper::UnSubscribeNotification(*subscriber); - while (!TestAnsSubscriber::mutex_.try_lock()) { + while (!TestAnsSubscriber::mutex.try_lock()) { OHOS::GetSystemCurrentTime(&end); timeout = OHOS::GetSecondsBetween(start, end); if (timeout >= 5L) { break; } } - TestAnsSubscriber::mutex_.unlock(); + TestAnsSubscriber::mutex.unlock(); }); callFunctionMap_.emplace( "NotificationHelperSubscribeNotificationNotificationSubscriberNotificationSubscribeInfo", []() { - TestAnsSubscriber::mutex_.lock(); + TestAnsSubscriber::mutex.lock(); std::shared_ptr subscriber = GetParamNotificationSubscriber(); std::shared_ptr subscribeInfo = GetParamNotificationSubscribeInfo(); @@ -202,59 +198,59 @@ void NotificationFuzzTestManager::RegisterNotificationHelper() OHOS::Notification::NotificationHelper::SubscribeNotification(*subscriber, *subscribeInfo); struct tm end = {0}; int64_t timeout = 0; - while (!TestAnsSubscriber::mutex_.try_lock()) { + while (!TestAnsSubscriber::mutex.try_lock()) { OHOS::GetSystemCurrentTime(&end); timeout = OHOS::GetSecondsBetween(start, end); if (timeout >= 5L) { break; } } - TestAnsSubscriber::mutex_.unlock(); - TestAnsSubscriber::mutex_.lock(); + TestAnsSubscriber::mutex.unlock(); + TestAnsSubscriber::mutex.lock(); OHOS::GetSystemCurrentTime(&start); OHOS::Notification::NotificationHelper::UnSubscribeNotification(*subscriber, *subscribeInfo); - while (!TestAnsSubscriber::mutex_.try_lock()) { + while (!TestAnsSubscriber::mutex.try_lock()) { OHOS::GetSystemCurrentTime(&end); timeout = OHOS::GetSecondsBetween(start, end); if (timeout >= 5L) { break; } } - TestAnsSubscriber::mutex_.unlock(); + TestAnsSubscriber::mutex.unlock(); }); callFunctionMap_.emplace("NotificationHelperUnSubscribeNotificationNotificationSubscriber", []() { - TestAnsSubscriber::mutex_.lock(); + TestAnsSubscriber::mutex.lock(); std::shared_ptr subscriber = GetParamNotificationSubscriber(); struct tm start = {0}; OHOS::GetSystemCurrentTime(&start); OHOS::Notification::NotificationHelper::SubscribeNotification(*subscriber); struct tm end = {0}; int64_t timeout = 0; - while (!TestAnsSubscriber::mutex_.try_lock()) { + while (!TestAnsSubscriber::mutex.try_lock()) { OHOS::GetSystemCurrentTime(&end); timeout = OHOS::GetSecondsBetween(start, end); if (timeout >= 5L) { break; } } - TestAnsSubscriber::mutex_.unlock(); - TestAnsSubscriber::mutex_.lock(); + TestAnsSubscriber::mutex.unlock(); + TestAnsSubscriber::mutex.lock(); OHOS::GetSystemCurrentTime(&start); OHOS::Notification::NotificationHelper::UnSubscribeNotification(*subscriber); - while (!TestAnsSubscriber::mutex_.try_lock()) { + while (!TestAnsSubscriber::mutex.try_lock()) { OHOS::GetSystemCurrentTime(&end); timeout = OHOS::GetSecondsBetween(start, end); if (timeout >= 5L) { break; } } - TestAnsSubscriber::mutex_.unlock(); + TestAnsSubscriber::mutex.unlock(); }); callFunctionMap_.emplace( "NotificationHelperUnSubscribeNotificationNotificationSubscriberNotificationSubscribeInfo", []() { - TestAnsSubscriber::mutex_.lock(); + TestAnsSubscriber::mutex.lock(); std::shared_ptr subscriber = GetParamNotificationSubscriber(); std::shared_ptr subscribeInfo = GetParamNotificationSubscribeInfo(); @@ -263,25 +259,25 @@ void NotificationFuzzTestManager::RegisterNotificationHelper() OHOS::Notification::NotificationHelper::SubscribeNotification(*subscriber, *subscribeInfo); struct tm end = {0}; int64_t timeout = 0; - while (!TestAnsSubscriber::mutex_.try_lock()) { + while (!TestAnsSubscriber::mutex.try_lock()) { OHOS::GetSystemCurrentTime(&end); timeout = OHOS::GetSecondsBetween(start, end); if (timeout >= 5L) { break; } } - TestAnsSubscriber::mutex_.unlock(); - TestAnsSubscriber::mutex_.lock(); + TestAnsSubscriber::mutex.unlock(); + TestAnsSubscriber::mutex.lock(); OHOS::GetSystemCurrentTime(&start); OHOS::Notification::NotificationHelper::UnSubscribeNotification(*subscriber, *subscribeInfo); - while (!TestAnsSubscriber::mutex_.try_lock()) { + while (!TestAnsSubscriber::mutex.try_lock()) { OHOS::GetSystemCurrentTime(&end); timeout = OHOS::GetSecondsBetween(start, end); if (timeout >= 5L) { break; } } - TestAnsSubscriber::mutex_.unlock(); + TestAnsSubscriber::mutex.unlock(); }); callFunctionMap_.emplace("NotificationHelperRemoveNotificationstring", @@ -666,8 +662,8 @@ void NotificationFuzzTestManager::RegisterIAbilityContinuation() }); } -// RegisterAbility_ -void NotificationFuzzTestManager::RegisterAbility_() +// RegisterAbility +void NotificationFuzzTestManager::RegisterAbility() { callFunctionMap_.emplace("AbilityOnRequestPermissionsFromUserResult", []() { std::shared_ptr temp = GetParamAbility(); @@ -684,8 +680,8 @@ void NotificationFuzzTestManager::RegisterAbility_() }); } -// RegisterAbilityContext_ -void NotificationFuzzTestManager::RegisterAbilityContext_() +// RegisterAbilityContext +void NotificationFuzzTestManager::RegisterAbilityContext() { callFunctionMap_.emplace("AbilityStartAbility", []() { std::shared_ptr temp = GetParamAbility(); @@ -841,8 +837,8 @@ NotificationFuzzTestManager::NotificationFuzzTestManager() RegisterWantAgentHelper(); RegisterLauncherService(); RegisterIAbilityContinuation(); - RegisterAbility_(); - RegisterAbilityContext_(); + RegisterAbility(); + RegisterAbilityContext(); RegisterContext(); RegisterAbilityLifecycleCallbacks(); RegisterIAbilityManager(); @@ -866,15 +862,10 @@ int GetRandomInt(int minNum, int maxNum) return GetU16Param() % (maxNum - minNum + 1) + minNum; } -void action(int a) -{ - std::cout << "Interrupt signal (" << a << ") received.\n"; -} - void NotificationFuzzTestManager::StartFuzzTest() { std::cout << __func__ << std::endl; - OHOS::FuzzConfigParser jsonParser; + OHOS::NotificationFuzzConfigParser jsonParser; OHOS::FuzzTestData tempData; std::cout << "parseFromFile start" << std::endl; diff --git a/test/resource/notificationfuzztest/src/notificationgetparam.cpp b/test/resource/notificationfuzztest/src/notificationgetparam.cpp index 0ff93b73d..29b8d46e0 100644 --- a/test/resource/notificationfuzztest/src/notificationgetparam.cpp +++ b/test/resource/notificationfuzztest/src/notificationgetparam.cpp @@ -28,6 +28,7 @@ using namespace OHOS::AppExecFwk; using namespace OHOS::EventFwk; using Uri = OHOS::Uri; +namespace { static const int INDEX_ZERO = 0; static const int INDEX_ONE = 1; static const int INDEX_TWO = 2; @@ -39,13 +40,14 @@ static const int INDEX_SEVEN = 7; static const int INDEX_EIGHT = 8; static const int INDEX_NINE = 9; static const int INDEX_TEN = 10; -static const int MESSAGE_INDEX = 36; static const int CHAR_MINCOUNT = -128; static const int CHAR_MAXCOUNT = 127; +static const int MAX_LENGTH = 255; +} // namespace namespace OHOS { namespace Notification { -std::mutex TestAnsSubscriber::mutex_ = std::mutex(); +std::mutex TestAnsSubscriber::mutex = std::mutex(); bool GetBoolParam() { bool param; @@ -238,7 +240,7 @@ string GetStringParam() { string param = ""; char ch = GetCharParam(); - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { ch = GetCharParam(); param += ch; @@ -250,7 +252,7 @@ template vector GetUnsignVectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { T t = GetUnsignParam(); param.push_back(t); @@ -268,7 +270,7 @@ T GetClassParam() std::vector GetBoolVectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int t = GetBoolParam(); param.push_back(t); @@ -279,7 +281,7 @@ std::vector GetBoolVectorParam() std::vector GetShortVectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { short t = GetShortParam(); param.push_back(t); @@ -290,7 +292,7 @@ std::vector GetShortVectorParam() std::vector GetLongVectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { long t = GetLongParam(); param.push_back(t); @@ -301,7 +303,7 @@ std::vector GetLongVectorParam() vector GetIntVectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int t = GetIntParam(); param.push_back(t); @@ -312,7 +314,7 @@ vector GetIntVectorParam() std::vector GetFloatVectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { float t = GetIntParam(); param.push_back(t); @@ -323,7 +325,7 @@ std::vector GetFloatVectorParam() std::vector GetDoubleVectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { double t = GetIntParam(); param.push_back(t); @@ -334,7 +336,7 @@ std::vector GetDoubleVectorParam() vector GetCharVectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { char t = GetCharParam(); param.push_back(t); @@ -345,7 +347,7 @@ vector GetCharVectorParam() vector GetChar32VectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { char32_t t = GetChar32Param(); param.push_back(t); @@ -356,7 +358,7 @@ vector GetChar32VectorParam() vector GetStringVectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { string t = GetStringParam(); param.push_back(t); @@ -367,7 +369,7 @@ vector GetStringVectorParam() vector GetS8VectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int8_t temp = GetS8Param(); param.push_back(temp); @@ -378,7 +380,7 @@ vector GetS8VectorParam() vector GetS16VectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int16_t temp = GetS16Param(); param.push_back(temp); @@ -389,7 +391,7 @@ vector GetS16VectorParam() vector GetS32VectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int32_t temp = GetS32Param(); param.push_back(temp); @@ -400,7 +402,7 @@ vector GetS32VectorParam() vector GetS64VectorParam() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { int64_t temp = GetS64Param(); param.push_back(temp); @@ -420,7 +422,7 @@ std::shared_ptr GetParamWant() std::vector> GetParamWantVector() { vector> param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { std::shared_ptr t = GetParamWant(); param.push_back(t); @@ -433,47 +435,6 @@ OHOS::AAFwk::Operation GetParamOperation() return OHOS::AAFwk::Operation(); } -std::shared_ptr GetParamAsyncCommonEventResult() -{ - return make_shared( - GetIntParam(), GetStringParam(), GetBoolParam(), GetBoolParam(), GetParamSptrRemote()); -} - -std::shared_ptr GetParamCommonEventData() -{ - return make_shared(); -} - -std::shared_ptr GetParamCommonEventManager() -{ - return make_shared(); -} - -std::shared_ptr GetParamCommonEventPublishInfo() -{ - return make_shared(); -} - -std::shared_ptr GetParamCommonEventSubscribeInfo() -{ - return make_shared(); -} - -std::shared_ptr GetParamCommonEventSubscriber() -{ - return make_shared(); -} - -std::shared_ptr GetParamCommonEventSupport() -{ - return make_shared(); -} - -std::shared_ptr GetParamMatchingSkills() -{ - return make_shared(); -} - sptr GetParamSptrRemote() { return sptr(); @@ -483,289 +444,21 @@ std::shared_ptr GetParamEventRunner() { return EventRunner::Create(GetCharArryParam()); } - -std::shared_ptr GetParamEventHandler() -{ - return make_shared(GetParamEventRunner()); -} - -std::shared_ptr GetParamEventQueue() -{ - return make_shared(); -} - -std::shared_ptr GetParamEventRunnerNativeImplement() -{ - return make_shared(GetBoolParam()); -} - -std::shared_ptr GetParamFileDescriptorListener() -{ - return make_shared(); -} - -TestDumper GetParamDumper() -{ - return GetClassParam(); -} - -InnerEvent::Pointer GetParamInnerEvent() -{ - return InnerEvent::Get(GetU32Param(), GetS64Param()); -} - -CommonEventSubscribeInfo::ThreadMode GetParamThreadMode() -{ - switch (GetIntParam() % INDEX_FOUR) { - case INDEX_ZERO: - return CommonEventSubscribeInfo::ThreadMode::HANDLER; - break; - case INDEX_ONE: - return CommonEventSubscribeInfo::ThreadMode::POST; - break; - case INDEX_TWO: - return CommonEventSubscribeInfo::ThreadMode::ASYNC; - break; - case INDEX_THREE: - return CommonEventSubscribeInfo::ThreadMode::BACKGROUND; - break; - default: - return CommonEventSubscribeInfo::ThreadMode::HANDLER; - break; - } -} - -EventQueue::Priority GetParamPriority() -{ - switch (GetIntParam() % INDEX_FOUR) { - case INDEX_ZERO: - return EventQueue::Priority::IMMEDIATE; - break; - case INDEX_ONE: - return EventQueue::Priority::HIGH; - break; - case INDEX_TWO: - return EventQueue::Priority::LOW; - break; - case INDEX_THREE: - return EventQueue::Priority::IDLE; - break; - default: - return EventQueue::Priority::LOW; - break; - } -} - -std::shared_ptr GetParamLogger() -{ - return make_shared(); -} - -InnerEvent::Callback GetParamCallback() -{ - auto callback = []() { printf("Fuzz Test Inner Event Callback."); }; - return callback; -} - -OHOS::AppExecFwk::InnerEvent::TimePoint GetParamTimePoint() -{ - std::chrono::steady_clock::time_point param = std::chrono::steady_clock::now(); - return param; -} - -std::shared_ptr GetParamAbilityStartSetting() -{ - return AbilityStartSetting::GetEmptySetting(); -} - -sptr GetParamIAbilityConnection() -{ - return sptr(); -} - -std::shared_ptr GetParamAbilityContext() -{ - return make_shared(); -} -std::shared_ptr GetParamIAbilityEvent() -{ - return make_shared(); -} - -sptr GetParamAbilityThread() -{ - return sptr(); -} - -std::shared_ptr GetParamAbilityHandler() -{ - return make_shared(GetParamEventRunner(), GetParamAbilityThread()); -} - std::shared_ptr GetParamAbility() { return make_shared(); } -std::shared_ptr GetParamComponentContainer() -{ - return make_shared(); -} - -std::shared_ptr GetParamOHOSApplication() -{ - return make_shared(); -} - -std::shared_ptr GetParamKeyEvent() -{ - return make_shared(); -} - -OHOS::Uri GetParamUri() -{ - return OHOS::Uri(GetStringParam()); -} - -NativeRdb::ValuesBucket GetParamValuesBucket() -{ - if (GetBoolParam()) { - NativeRdb::ValuesBucket val; - val.PutNull(GetStringParam()); - return val; - } else { - return NativeRdb::ValuesBucket(); - } -} - -OHOS::AppExecFwk::Configuration GetParamConfiguration() -{ - if (GetBoolParam()) { - return OHOS::AppExecFwk::Configuration(GetStringParam()); - } else { - return OHOS::AppExecFwk::Configuration(); - } -} - -NativeRdb::DataAbilityPredicates GetParamDataAbilityPredicates() -{ - if (GetBoolParam()) { - return NativeRdb::DataAbilityPredicates(GetStringParam()); - } else { - return NativeRdb::DataAbilityPredicates(); - } -} - -OHOS::AppExecFwk::PacMap GetParamPacMap() -{ - return OHOS::AppExecFwk::PacMap(); -} - -std::shared_ptr GetParamProcessInfo() -{ - pid_t id = GetIntParam(); - if (GetBoolParam()) { - return make_shared(GetStringParam(), id); - } else { - return make_shared(); - } -} - -std::shared_ptr GetParamDataUriUtils() -{ - return make_shared(); -} - std::shared_ptr GetParamContext() { return make_shared(); } -std::shared_ptr GetParamLifeCycle() -{ - return make_shared(); -} - -OHOS::AppExecFwk::LifeCycle::Event GetParamLifeCycleEvent() -{ - switch (GetIntParam() % INDEX_SEVEN) { - case INDEX_ZERO: - return OHOS::AppExecFwk::LifeCycle::Event::ON_ACTIVE; - break; - case INDEX_ONE: - return OHOS::AppExecFwk::LifeCycle::Event::ON_BACKGROUND; - break; - case INDEX_TWO: - return OHOS::AppExecFwk::LifeCycle::Event::ON_FOREGROUND; - break; - case INDEX_THREE: - return OHOS::AppExecFwk::LifeCycle::Event::ON_INACTIVE; - break; - case INDEX_FOUR: - return OHOS::AppExecFwk::LifeCycle::Event::ON_START; - break; - case INDEX_FIVE: - return OHOS::AppExecFwk::LifeCycle::Event::ON_STOP; - break; - case INDEX_SIX: - return OHOS::AppExecFwk::LifeCycle::Event::UNDEFINED; - break; - default: - return OHOS::AppExecFwk::LifeCycle::Event::ON_ACTIVE; - break; - } -} - -std::shared_ptr GetParamElementName() -{ - if (GetBoolParam()) { - return make_shared(GetStringParam(), GetStringParam(), GetStringParam()); - } else { - return make_shared(); - } -} - std::shared_ptr GetParamWantParams() { return make_shared(); } -std::shared_ptr GetParamAbilityManager() -{ - return make_shared(); -} - -OHOS::AAFwk::PatternsMatcher GetParamPatternsMatcher() -{ - return OHOS::AAFwk::PatternsMatcher(); -} - -OHOS::AAFwk::MatchType GetParamMatchType() -{ - switch (GetIntParam() % INDEX_FOUR) { - case INDEX_ZERO: - return OHOS::AAFwk::MatchType::DEFAULT; - break; - case INDEX_ONE: - return OHOS::AAFwk::MatchType::PREFIX; - break; - case INDEX_TWO: - return OHOS::AAFwk::MatchType::PATTERN; - break; - case INDEX_THREE: - return OHOS::AAFwk::MatchType::GLOBAL; - break; - default: - return OHOS::AAFwk::MatchType::DEFAULT; - break; - } -} - -std::shared_ptr GetParamBundleMgrProxy() -{ - return make_shared(GetParamSptrRemote()); -} - OHOS::AppExecFwk::ApplicationFlag GetParamApplicationFlag() { if (GetBoolParam()) { @@ -779,101 +472,16 @@ OHOS::AppExecFwk::ApplicationInfo GetParamApplicationInfo() { return OHOS::AppExecFwk::ApplicationInfo(); } - -std::vector GetParamApplicationInfoVector() -{ - vector param; - size_t len = GenRandom(0, 255); - while (len--) { - OHOS::AppExecFwk::ApplicationInfo t = GetParamApplicationInfo(); - param.push_back(t); - } - return param; -} - -OHOS::AppExecFwk::BundleFlag GetParamBundleFlag() -{ - if (GetBoolParam()) { - return OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT; - } else { - return OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES; - } -} - -OHOS::AppExecFwk::BundleInfo GetParamBundleInfo() -{ - return OHOS::AppExecFwk::BundleInfo(); -} - OHOS::AppExecFwk::AbilityInfo GetParamAbilityInfo() { return OHOS::AppExecFwk::AbilityInfo(); } -OHOS::AppExecFwk::HapModuleInfo GetParamHapModuleInfo() -{ - return OHOS::AppExecFwk::HapModuleInfo(); -} - -OHOS::AppExecFwk::PermissionDef GetParamPermissionDef() -{ - return OHOS::AppExecFwk::PermissionDef(); -} - -std::vector GetParamPermissionDefVector() -{ - vector param; - size_t len = GenRandom(0, 255); - while (len--) { - OHOS::AppExecFwk::PermissionDef t = GetParamPermissionDef(); - param.push_back(t); - } - return param; -} - -OHOS::AppExecFwk::IBundleMgr::Message GetParamIBundleMgrMessage() -{ - return (OHOS::AppExecFwk::IBundleMgr::Message)(GetIntParam() % MESSAGE_INDEX); -} - -OHOS::MessageParcel GetParamMessageParcel() -{ - return OHOS::MessageParcel(); -} - -OHOS::AppExecFwk::DumpFlag GetParamDumpFlag() -{ - switch (GetIntParam() % INDEX_THREE) { - case INDEX_ZERO: - return OHOS::AppExecFwk::DumpFlag::DUMP_BUNDLE_LIST; - break; - case INDEX_ONE: - return OHOS::AppExecFwk::DumpFlag::DUMP_ALL_BUNDLE_INFO; - break; - case INDEX_TWO: - return OHOS::AppExecFwk::DumpFlag::DUMP_BUNDLE_INFO; - break; - default: - return OHOS::AppExecFwk::DumpFlag::DUMP_BUNDLE_LIST; - break; - } -} - -sptr GetParamICleanCacheCallback() -{ - return sptr(); -} - sptr GetParamIBundleStatusCallback() { return sptr(); } -std::shared_ptr GetParamDataAbilityHelper() -{ - return OHOS::AppExecFwk::DataAbilityHelper::Creator(std::make_shared()); -} - std::shared_ptr GetParamNotificationSorting() { return std::make_shared(); @@ -882,7 +490,7 @@ std::shared_ptr GetParamNotificationSorting() std::vector GetParamNotificationSortingVector() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { NotificationSorting t; param.push_back(t); @@ -907,8 +515,7 @@ std::shared_ptr GetParamNotificationSlot() sptr GetParamNotificationSlotSptr() { - sptr param = - new OHOS::Notification::NotificationSlot(GetParamSlotType()); + sptr param = new OHOS::Notification::NotificationSlot(GetParamSlotType()); return param; } @@ -938,7 +545,7 @@ OHOS::Notification::NotificationConstant::SlotType GetParamSlotType() std::vector> GetParamNotificationSlotSptrVector() { vector> param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { sptr t = GetParamNotificationSlotSptr(); param.push_back(t); @@ -949,7 +556,7 @@ std::vector> GetParamNotificationSlot std::vector GetParamNotificationSlotVector() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { NotificationSlot t = *GetParamNotificationSlot(); param.push_back(t); @@ -960,7 +567,7 @@ std::vector GetParamNotificationSlotVector std::vector GetParamNotificationSlotGroupVector() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::Notification::NotificationSlotGroup t = *GetParamNotificationSlotGroup(); param.push_back(t); @@ -976,7 +583,7 @@ sptr GetParamNotificationSlotGroup() std::vector> GetParamNotificationSlotGroupSptrVector() { vector> param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { sptr t = GetParamNotificationSlotGroup(); param.push_back(t); @@ -1036,7 +643,7 @@ sptr GetParamNotificationRequestSptr() std::vector> GetParamNotificationRequestVector() { vector> param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { sptr t = GetParamNotificationRequestSptr(); param.push_back(t); @@ -1180,7 +787,7 @@ OHOS::Notification::WantAgent::WantAgentConstant::Flags GetParamFlags() std::vector GetParamFlagsVector() { vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::Notification::WantAgent::WantAgentConstant::Flags t = GetParamFlags(); param.push_back(t); @@ -1204,7 +811,7 @@ sptr GetParamNotificationSptr() std::vector> GetParamNotificationSptrVector() { std::vector> param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { sptr t = GetParamNotificationSptr(); param.push_back(t); @@ -1254,7 +861,7 @@ std::shared_ptr GetParamLauncherService() std::vector GetParamLauncherAbilityInfoVector() { std::vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AppExecFwk::LauncherAbilityInfo t; param.push_back(t); @@ -1268,7 +875,7 @@ std::shared_ptr GetParamLauncherAbilityIn std::vector GetParamLauncherShortcutInfoVector() { std::vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AppExecFwk::LauncherShortcutInfo t; param.push_back(t); @@ -1278,7 +885,7 @@ std::vector GetParamLauncherShortcutInfo std::vector GetParamFormInfoVector() { std::vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AppExecFwk::FormInfo t; param.push_back(t); @@ -1288,7 +895,7 @@ std::vector GetParamFormInfoVector() std::vector GetParamShortcutInfoVector() { std::vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AppExecFwk::ShortcutInfo t; param.push_back(t); @@ -1298,7 +905,7 @@ std::vector GetParamShortcutInfoVector() std::vector GetParamModuleUsageRecordVector() { std::vector param; - size_t len = GenRandom(0, 255); + size_t len = GenRandom(0, MAX_LENGTH); while (len--) { OHOS::AppExecFwk::ModuleUsageRecord t; param.push_back(t); -- Gitee From d946528131f4f23169d6484e884d64a5316b1065 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Wed, 24 Nov 2021 16:35:01 +0000 Subject: [PATCH 3/3] Fix codex Signed-off-by: zhaoyuan17 --- .../notificationfuzztest/include/notificationgetparam.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/resource/notificationfuzztest/include/notificationgetparam.h b/test/resource/notificationfuzztest/include/notificationgetparam.h index b18017d60..80aa444cd 100644 --- a/test/resource/notificationfuzztest/include/notificationgetparam.h +++ b/test/resource/notificationfuzztest/include/notificationgetparam.h @@ -16,7 +16,7 @@ #define NOTIFICATION_GET_PARAM_H #include #include -#include +#include #include #include "ability.h" @@ -204,8 +204,6 @@ public: } }; - - class TestIBundleStatusCallback : public OHOS::AppExecFwk::IBundleStatusCallback { public: TestIBundleStatusCallback() -- Gitee